@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/checkout.js
CHANGED
|
@@ -11,6 +11,264 @@ import { SwapRouter, PaymentsExtended } from '@uniswap/router-sdk';
|
|
|
11
11
|
import FormData$2 from 'form-data';
|
|
12
12
|
import { Seaport as Seaport$1 } from '@opensea/seaport-js';
|
|
13
13
|
|
|
14
|
+
const isNode$1 = () => typeof window === 'undefined';
|
|
15
|
+
const isBrowser$1 = () => !isNode$1();
|
|
16
|
+
|
|
17
|
+
var Detail$1;
|
|
18
|
+
(function (Detail) {
|
|
19
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
20
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
21
|
+
Detail["ENVIRONMENT"] = "env";
|
|
22
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
23
|
+
Detail["IDENTITY"] = "uid";
|
|
24
|
+
Detail["DOMAIN"] = "domain";
|
|
25
|
+
})(Detail$1 || (Detail$1 = {}));
|
|
26
|
+
var Store$1;
|
|
27
|
+
(function (Store) {
|
|
28
|
+
Store["EVENTS"] = "events";
|
|
29
|
+
Store["RUNTIME"] = "runtime";
|
|
30
|
+
})(Store$1 || (Store$1 = {}));
|
|
31
|
+
const POLLING_FREQUENCY$1 = 5000;
|
|
32
|
+
|
|
33
|
+
const IMTBL_API$1 = 'https://api.x.immutable.com';
|
|
34
|
+
async function post$1(path, data) {
|
|
35
|
+
const client = globalAxios.create({
|
|
36
|
+
baseURL: IMTBL_API$1,
|
|
37
|
+
});
|
|
38
|
+
const payload = JSON.stringify(data);
|
|
39
|
+
const body = {
|
|
40
|
+
payload: btoa(payload),
|
|
41
|
+
};
|
|
42
|
+
const response = await client.post(path, body);
|
|
43
|
+
return response.data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Abstraction on localstorage
|
|
48
|
+
*/
|
|
49
|
+
const localStoragePrefix$1 = '__IMX-';
|
|
50
|
+
const hasLocalstorage$1 = () => isBrowser$1() && window.localStorage;
|
|
51
|
+
const parseItem$1 = (payload) => {
|
|
52
|
+
// Try to parse, if can't be parsed assume string
|
|
53
|
+
// and return string
|
|
54
|
+
if (payload === null)
|
|
55
|
+
return undefined;
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(payload);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Assumes it's a string.
|
|
61
|
+
return payload;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const serialiseItem$1 = (payload) => {
|
|
65
|
+
if (typeof payload === 'string') {
|
|
66
|
+
return payload;
|
|
67
|
+
}
|
|
68
|
+
return JSON.stringify(payload);
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* GenKey will take into account the namespace
|
|
72
|
+
* as well as if being run in the Link, it will tap into the link
|
|
73
|
+
* @param {string} key
|
|
74
|
+
* @returns key
|
|
75
|
+
*/
|
|
76
|
+
const genKey$1 = (key) => `${localStoragePrefix$1}${key}`;
|
|
77
|
+
function getItem$1(key) {
|
|
78
|
+
if (hasLocalstorage$1()) {
|
|
79
|
+
return parseItem$1(window.localStorage.getItem(genKey$1(key)));
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const setItem$1 = (key, payload) => {
|
|
84
|
+
if (hasLocalstorage$1()) {
|
|
85
|
+
window.localStorage.setItem(genKey$1(key), serialiseItem$1(payload));
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// In memory storage for events and other data
|
|
92
|
+
let EVENT_STORE$1;
|
|
93
|
+
let RUNTIME_DETAILS$1;
|
|
94
|
+
// Initialise store and runtime
|
|
95
|
+
const initialise$1$1 = () => {
|
|
96
|
+
EVENT_STORE$1 = getItem$1(Store$1.EVENTS) || [];
|
|
97
|
+
RUNTIME_DETAILS$1 = getItem$1(Store$1.RUNTIME) || {};
|
|
98
|
+
};
|
|
99
|
+
initialise$1$1();
|
|
100
|
+
// Runtime Details
|
|
101
|
+
const storeDetail$1 = (key, value) => {
|
|
102
|
+
RUNTIME_DETAILS$1 = {
|
|
103
|
+
...RUNTIME_DETAILS$1,
|
|
104
|
+
[key]: value,
|
|
105
|
+
};
|
|
106
|
+
setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
|
|
107
|
+
};
|
|
108
|
+
const getDetail$1 = (key) => {
|
|
109
|
+
// Handle the scenario where detail is a falsy value
|
|
110
|
+
if (RUNTIME_DETAILS$1[key] === undefined) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return RUNTIME_DETAILS$1[key];
|
|
114
|
+
};
|
|
115
|
+
const getAllDetails$1 = () => RUNTIME_DETAILS$1;
|
|
116
|
+
// Events
|
|
117
|
+
const getEvents$1 = () => EVENT_STORE$1;
|
|
118
|
+
const addEvent = (event) => {
|
|
119
|
+
EVENT_STORE$1.push(event);
|
|
120
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
121
|
+
};
|
|
122
|
+
const removeSentEvents$1 = (numberOfEvents) => {
|
|
123
|
+
EVENT_STORE$1 = EVENT_STORE$1.slice(numberOfEvents);
|
|
124
|
+
setItem$1(Store$1.EVENTS, EVENT_STORE$1);
|
|
125
|
+
};
|
|
126
|
+
const flattenProperties$1 = (properties) => {
|
|
127
|
+
const propertyMap = [];
|
|
128
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
129
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
130
|
+
propertyMap.push([key, value.toString()]);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return propertyMap;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let initialised$1 = false;
|
|
137
|
+
const isInitialised$1 = () => initialised$1;
|
|
138
|
+
const getReferrer$1 = () => {
|
|
139
|
+
if (isNode$1()) {
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
if (window.location.ancestorOrigins
|
|
143
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
144
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
145
|
+
}
|
|
146
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
147
|
+
};
|
|
148
|
+
const runtimeHost$1 = () => {
|
|
149
|
+
if (isNode$1()) {
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
if (window.opener || window.parent !== window) {
|
|
153
|
+
return getReferrer$1();
|
|
154
|
+
}
|
|
155
|
+
return new URL(window.location.href).hostname;
|
|
156
|
+
};
|
|
157
|
+
const getRuntimeDetails$1 = () => {
|
|
158
|
+
if (isNode$1()) {
|
|
159
|
+
return { browser: 'nodejs' };
|
|
160
|
+
}
|
|
161
|
+
const domain = runtimeHost$1();
|
|
162
|
+
if (domain) {
|
|
163
|
+
storeDetail$1(Detail$1.DOMAIN, domain);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
browser: window.navigator.userAgent,
|
|
167
|
+
domain,
|
|
168
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
169
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
const initialise$2 = async () => {
|
|
173
|
+
const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
|
|
174
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
175
|
+
const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
|
|
176
|
+
const body = {
|
|
177
|
+
version: 1,
|
|
178
|
+
data: {
|
|
179
|
+
runtimeDetails,
|
|
180
|
+
runtimeId: existingRuntimeId,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
const response = await post$1('/v1/sdk/initialise', body);
|
|
184
|
+
// Get runtimeId and store it
|
|
185
|
+
const { runtimeId } = response;
|
|
186
|
+
storeDetail$1(Detail$1.RUNTIME_ID, runtimeId);
|
|
187
|
+
initialised$1 = true;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
function errorBoundary$1(fn) {
|
|
191
|
+
const wrappedFunction = ((...args) => {
|
|
192
|
+
try {
|
|
193
|
+
// Execute the original function
|
|
194
|
+
const result = fn(...args);
|
|
195
|
+
if (result instanceof Promise) {
|
|
196
|
+
// Silent fail for now, in future
|
|
197
|
+
// we can send errors to a logging service
|
|
198
|
+
return result.catch(() => undefined);
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// As above, fail silently for now
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return wrappedFunction;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function isTestEnvironment$1() {
|
|
211
|
+
if (typeof process === 'undefined') {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Store the event in the event store
|
|
218
|
+
const trackFn = (moduleName, eventName, properties) => {
|
|
219
|
+
const event = {
|
|
220
|
+
event: `${moduleName}.${eventName}`,
|
|
221
|
+
time: new Date().toISOString(),
|
|
222
|
+
...(properties && { properties: flattenProperties$1(properties) }),
|
|
223
|
+
};
|
|
224
|
+
addEvent(event);
|
|
225
|
+
};
|
|
226
|
+
const track = errorBoundary$1(trackFn);
|
|
227
|
+
// Sending events to the server
|
|
228
|
+
const flushFn$1 = async () => {
|
|
229
|
+
// Don't flush if not initialised
|
|
230
|
+
if (isInitialised$1() === false) {
|
|
231
|
+
await initialise$2();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const events = getEvents$1();
|
|
235
|
+
if (events.length === 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Track events length here, incase
|
|
239
|
+
const numEvents = events.length;
|
|
240
|
+
// Get details and send it with the track request
|
|
241
|
+
const details = getAllDetails$1();
|
|
242
|
+
const metricsPayload = {
|
|
243
|
+
version: 1,
|
|
244
|
+
data: {
|
|
245
|
+
events,
|
|
246
|
+
details,
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
const response = await post$1('/v1/sdk/metrics', metricsPayload);
|
|
250
|
+
if (response instanceof Error) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
// Clear events if successfully posted
|
|
254
|
+
removeSentEvents$1(numEvents);
|
|
255
|
+
};
|
|
256
|
+
const flush$1 = errorBoundary$1(flushFn$1);
|
|
257
|
+
// Flush events every 5 seconds
|
|
258
|
+
const flushPoll$1 = async () => {
|
|
259
|
+
await flush$1();
|
|
260
|
+
setTimeout(flushPoll$1, POLLING_FREQUENCY$1);
|
|
261
|
+
};
|
|
262
|
+
// This will get initialised when module is imported.
|
|
263
|
+
if (!isTestEnvironment$1()) {
|
|
264
|
+
errorBoundary$1(flushPoll$1)();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const setEnvironmentFn = (env) => {
|
|
268
|
+
storeDetail$1(Detail$1.ENVIRONMENT, env);
|
|
269
|
+
};
|
|
270
|
+
const setEnvironment = errorBoundary$1(setEnvironmentFn);
|
|
271
|
+
|
|
14
272
|
var Environment$1;
|
|
15
273
|
(function (Environment) {
|
|
16
274
|
Environment["PRODUCTION"] = "production";
|
|
@@ -23,6 +281,8 @@ class ImmutableConfiguration {
|
|
|
23
281
|
publishableKey;
|
|
24
282
|
constructor(options) {
|
|
25
283
|
this.environment = options.environment;
|
|
284
|
+
setEnvironment(options.environment);
|
|
285
|
+
track('config', 'load_imtbl_config');
|
|
26
286
|
}
|
|
27
287
|
}
|
|
28
288
|
|
|
@@ -16695,6 +16955,244 @@ class TokenBridge {
|
|
|
16695
16955
|
}
|
|
16696
16956
|
}
|
|
16697
16957
|
|
|
16958
|
+
const isNode = () => typeof window === 'undefined';
|
|
16959
|
+
const isBrowser = () => !isNode();
|
|
16960
|
+
|
|
16961
|
+
var Detail;
|
|
16962
|
+
(function (Detail) {
|
|
16963
|
+
Detail["RUNTIME_ID"] = "rid";
|
|
16964
|
+
Detail["PASSPORT_CLIENT_ID"] = "passportClientId";
|
|
16965
|
+
Detail["ENVIRONMENT"] = "env";
|
|
16966
|
+
Detail["PUBLISHABLE_API_KEY"] = "pak";
|
|
16967
|
+
Detail["IDENTITY"] = "uid";
|
|
16968
|
+
Detail["DOMAIN"] = "domain";
|
|
16969
|
+
})(Detail || (Detail = {}));
|
|
16970
|
+
var Store;
|
|
16971
|
+
(function (Store) {
|
|
16972
|
+
Store["EVENTS"] = "events";
|
|
16973
|
+
Store["RUNTIME"] = "runtime";
|
|
16974
|
+
})(Store || (Store = {}));
|
|
16975
|
+
const POLLING_FREQUENCY = 5000;
|
|
16976
|
+
|
|
16977
|
+
const IMTBL_API = 'https://api.x.immutable.com';
|
|
16978
|
+
async function post(path, data) {
|
|
16979
|
+
const client = axios$1.create({
|
|
16980
|
+
baseURL: IMTBL_API,
|
|
16981
|
+
});
|
|
16982
|
+
const payload = JSON.stringify(data);
|
|
16983
|
+
const body = {
|
|
16984
|
+
payload: btoa(payload),
|
|
16985
|
+
};
|
|
16986
|
+
const response = await client.post(path, body);
|
|
16987
|
+
return response.data;
|
|
16988
|
+
}
|
|
16989
|
+
|
|
16990
|
+
/**
|
|
16991
|
+
* Abstraction on localstorage
|
|
16992
|
+
*/
|
|
16993
|
+
const localStoragePrefix = '__IMX-';
|
|
16994
|
+
const hasLocalstorage = () => isBrowser() && window.localStorage;
|
|
16995
|
+
const parseItem = (payload) => {
|
|
16996
|
+
// Try to parse, if can't be parsed assume string
|
|
16997
|
+
// and return string
|
|
16998
|
+
if (payload === null)
|
|
16999
|
+
return undefined;
|
|
17000
|
+
try {
|
|
17001
|
+
return JSON.parse(payload);
|
|
17002
|
+
}
|
|
17003
|
+
catch (error) {
|
|
17004
|
+
// Assumes it's a string.
|
|
17005
|
+
return payload;
|
|
17006
|
+
}
|
|
17007
|
+
};
|
|
17008
|
+
const serialiseItem = (payload) => {
|
|
17009
|
+
if (typeof payload === 'string') {
|
|
17010
|
+
return payload;
|
|
17011
|
+
}
|
|
17012
|
+
return JSON.stringify(payload);
|
|
17013
|
+
};
|
|
17014
|
+
/**
|
|
17015
|
+
* GenKey will take into account the namespace
|
|
17016
|
+
* as well as if being run in the Link, it will tap into the link
|
|
17017
|
+
* @param {string} key
|
|
17018
|
+
* @returns key
|
|
17019
|
+
*/
|
|
17020
|
+
const genKey = (key) => `${localStoragePrefix}${key}`;
|
|
17021
|
+
function getItem(key) {
|
|
17022
|
+
if (hasLocalstorage()) {
|
|
17023
|
+
return parseItem(window.localStorage.getItem(genKey(key)));
|
|
17024
|
+
}
|
|
17025
|
+
return undefined;
|
|
17026
|
+
}
|
|
17027
|
+
const setItem = (key, payload) => {
|
|
17028
|
+
if (hasLocalstorage()) {
|
|
17029
|
+
window.localStorage.setItem(genKey(key), serialiseItem(payload));
|
|
17030
|
+
return true;
|
|
17031
|
+
}
|
|
17032
|
+
return false;
|
|
17033
|
+
};
|
|
17034
|
+
|
|
17035
|
+
// In memory storage for events and other data
|
|
17036
|
+
let EVENT_STORE;
|
|
17037
|
+
let RUNTIME_DETAILS;
|
|
17038
|
+
// Initialise store and runtime
|
|
17039
|
+
const initialise$1 = () => {
|
|
17040
|
+
EVENT_STORE = getItem(Store.EVENTS) || [];
|
|
17041
|
+
RUNTIME_DETAILS = getItem(Store.RUNTIME) || {};
|
|
17042
|
+
};
|
|
17043
|
+
initialise$1();
|
|
17044
|
+
// Runtime Details
|
|
17045
|
+
const storeDetail = (key, value) => {
|
|
17046
|
+
RUNTIME_DETAILS = {
|
|
17047
|
+
...RUNTIME_DETAILS,
|
|
17048
|
+
[key]: value,
|
|
17049
|
+
};
|
|
17050
|
+
setItem(Store.RUNTIME, RUNTIME_DETAILS);
|
|
17051
|
+
};
|
|
17052
|
+
const getDetail = (key) => {
|
|
17053
|
+
// Handle the scenario where detail is a falsy value
|
|
17054
|
+
if (RUNTIME_DETAILS[key] === undefined) {
|
|
17055
|
+
return undefined;
|
|
17056
|
+
}
|
|
17057
|
+
return RUNTIME_DETAILS[key];
|
|
17058
|
+
};
|
|
17059
|
+
const getAllDetails = () => RUNTIME_DETAILS;
|
|
17060
|
+
// Events
|
|
17061
|
+
const getEvents = () => EVENT_STORE;
|
|
17062
|
+
const removeSentEvents = (numberOfEvents) => {
|
|
17063
|
+
EVENT_STORE = EVENT_STORE.slice(numberOfEvents);
|
|
17064
|
+
setItem(Store.EVENTS, EVENT_STORE);
|
|
17065
|
+
};
|
|
17066
|
+
const flattenProperties = (properties) => {
|
|
17067
|
+
const propertyMap = [];
|
|
17068
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
17069
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
17070
|
+
propertyMap.push([key, value.toString()]);
|
|
17071
|
+
}
|
|
17072
|
+
});
|
|
17073
|
+
return propertyMap;
|
|
17074
|
+
};
|
|
17075
|
+
|
|
17076
|
+
let initialised = false;
|
|
17077
|
+
const isInitialised = () => initialised;
|
|
17078
|
+
const getReferrer = () => {
|
|
17079
|
+
if (isNode()) {
|
|
17080
|
+
return '';
|
|
17081
|
+
}
|
|
17082
|
+
if (window.location.ancestorOrigins
|
|
17083
|
+
&& window.location.ancestorOrigins.length > 0) {
|
|
17084
|
+
return new URL(window.location.ancestorOrigins[0]).hostname;
|
|
17085
|
+
}
|
|
17086
|
+
return document.referrer ? new URL(window.document.referrer).hostname : '';
|
|
17087
|
+
};
|
|
17088
|
+
const runtimeHost = () => {
|
|
17089
|
+
if (isNode()) {
|
|
17090
|
+
return '';
|
|
17091
|
+
}
|
|
17092
|
+
if (window.opener || window.parent !== window) {
|
|
17093
|
+
return getReferrer();
|
|
17094
|
+
}
|
|
17095
|
+
return new URL(window.location.href).hostname;
|
|
17096
|
+
};
|
|
17097
|
+
const getRuntimeDetails = () => {
|
|
17098
|
+
if (isNode()) {
|
|
17099
|
+
return { browser: 'nodejs' };
|
|
17100
|
+
}
|
|
17101
|
+
const domain = runtimeHost();
|
|
17102
|
+
if (domain) {
|
|
17103
|
+
storeDetail(Detail.DOMAIN, domain);
|
|
17104
|
+
}
|
|
17105
|
+
return {
|
|
17106
|
+
browser: window.navigator.userAgent,
|
|
17107
|
+
domain,
|
|
17108
|
+
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
17109
|
+
screen: `${window.screen.width}x${window.screen.height}`,
|
|
17110
|
+
};
|
|
17111
|
+
};
|
|
17112
|
+
const initialise = async () => {
|
|
17113
|
+
const runtimeDetails = flattenProperties(getRuntimeDetails());
|
|
17114
|
+
// Get any existing runtimeId and send it along with the initialise
|
|
17115
|
+
const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
|
|
17116
|
+
const body = {
|
|
17117
|
+
version: 1,
|
|
17118
|
+
data: {
|
|
17119
|
+
runtimeDetails,
|
|
17120
|
+
runtimeId: existingRuntimeId,
|
|
17121
|
+
},
|
|
17122
|
+
};
|
|
17123
|
+
const response = await post('/v1/sdk/initialise', body);
|
|
17124
|
+
// Get runtimeId and store it
|
|
17125
|
+
const { runtimeId } = response;
|
|
17126
|
+
storeDetail(Detail.RUNTIME_ID, runtimeId);
|
|
17127
|
+
initialised = true;
|
|
17128
|
+
};
|
|
17129
|
+
|
|
17130
|
+
function errorBoundary(fn) {
|
|
17131
|
+
const wrappedFunction = ((...args) => {
|
|
17132
|
+
try {
|
|
17133
|
+
// Execute the original function
|
|
17134
|
+
const result = fn(...args);
|
|
17135
|
+
if (result instanceof Promise) {
|
|
17136
|
+
// Silent fail for now, in future
|
|
17137
|
+
// we can send errors to a logging service
|
|
17138
|
+
return result.catch(() => undefined);
|
|
17139
|
+
}
|
|
17140
|
+
return result;
|
|
17141
|
+
}
|
|
17142
|
+
catch (error) {
|
|
17143
|
+
// As above, fail silently for now
|
|
17144
|
+
return undefined;
|
|
17145
|
+
}
|
|
17146
|
+
});
|
|
17147
|
+
return wrappedFunction;
|
|
17148
|
+
}
|
|
17149
|
+
|
|
17150
|
+
function isTestEnvironment() {
|
|
17151
|
+
if (typeof process === 'undefined') {
|
|
17152
|
+
return false;
|
|
17153
|
+
}
|
|
17154
|
+
return process.env.JEST_WORKER_ID !== undefined;
|
|
17155
|
+
}
|
|
17156
|
+
// Sending events to the server
|
|
17157
|
+
const flushFn = async () => {
|
|
17158
|
+
// Don't flush if not initialised
|
|
17159
|
+
if (isInitialised() === false) {
|
|
17160
|
+
await initialise();
|
|
17161
|
+
return;
|
|
17162
|
+
}
|
|
17163
|
+
const events = getEvents();
|
|
17164
|
+
if (events.length === 0) {
|
|
17165
|
+
return;
|
|
17166
|
+
}
|
|
17167
|
+
// Track events length here, incase
|
|
17168
|
+
const numEvents = events.length;
|
|
17169
|
+
// Get details and send it with the track request
|
|
17170
|
+
const details = getAllDetails();
|
|
17171
|
+
const metricsPayload = {
|
|
17172
|
+
version: 1,
|
|
17173
|
+
data: {
|
|
17174
|
+
events,
|
|
17175
|
+
details,
|
|
17176
|
+
},
|
|
17177
|
+
};
|
|
17178
|
+
const response = await post('/v1/sdk/metrics', metricsPayload);
|
|
17179
|
+
if (response instanceof Error) {
|
|
17180
|
+
return;
|
|
17181
|
+
}
|
|
17182
|
+
// Clear events if successfully posted
|
|
17183
|
+
removeSentEvents(numEvents);
|
|
17184
|
+
};
|
|
17185
|
+
const flush = errorBoundary(flushFn);
|
|
17186
|
+
// Flush events every 5 seconds
|
|
17187
|
+
const flushPoll = async () => {
|
|
17188
|
+
await flush();
|
|
17189
|
+
setTimeout(flushPoll, POLLING_FREQUENCY);
|
|
17190
|
+
};
|
|
17191
|
+
// This will get initialised when module is imported.
|
|
17192
|
+
if (!isTestEnvironment()) {
|
|
17193
|
+
errorBoundary(flushPoll)();
|
|
17194
|
+
}
|
|
17195
|
+
|
|
16698
17196
|
var Environment;
|
|
16699
17197
|
(function (Environment) {
|
|
16700
17198
|
Environment["PRODUCTION"] = "production";
|
|
@@ -16871,7 +17369,7 @@ class ApproveError extends ExchangeError {
|
|
|
16871
17369
|
/* Autogenerated file. Do not edit manually. */
|
|
16872
17370
|
/* tslint:disable */
|
|
16873
17371
|
/* eslint-disable */
|
|
16874
|
-
const _abi$
|
|
17372
|
+
const _abi$4 = [
|
|
16875
17373
|
{
|
|
16876
17374
|
constant: true,
|
|
16877
17375
|
inputs: [],
|
|
@@ -17094,19 +17592,19 @@ const _abi$3 = [
|
|
|
17094
17592
|
},
|
|
17095
17593
|
];
|
|
17096
17594
|
class ERC20__factory {
|
|
17097
|
-
static abi = _abi$
|
|
17595
|
+
static abi = _abi$4;
|
|
17098
17596
|
static createInterface() {
|
|
17099
|
-
return new utils$2.Interface(_abi$
|
|
17597
|
+
return new utils$2.Interface(_abi$4);
|
|
17100
17598
|
}
|
|
17101
17599
|
static connect(address, signerOrProvider) {
|
|
17102
|
-
return new Contract$1(address, _abi$
|
|
17600
|
+
return new Contract$1(address, _abi$4, signerOrProvider);
|
|
17103
17601
|
}
|
|
17104
17602
|
}
|
|
17105
17603
|
|
|
17106
17604
|
/* Autogenerated file. Do not edit manually. */
|
|
17107
17605
|
/* tslint:disable */
|
|
17108
17606
|
/* eslint-disable */
|
|
17109
|
-
const _abi$
|
|
17607
|
+
const _abi$3 = [
|
|
17110
17608
|
{
|
|
17111
17609
|
inputs: [
|
|
17112
17610
|
{
|
|
@@ -17880,7 +18378,7 @@ class ImmutableSwapProxy__factory extends ContractFactory {
|
|
|
17880
18378
|
super(...args);
|
|
17881
18379
|
}
|
|
17882
18380
|
else {
|
|
17883
|
-
super(_abi$
|
|
18381
|
+
super(_abi$3, _bytecode$2, args[0]);
|
|
17884
18382
|
}
|
|
17885
18383
|
}
|
|
17886
18384
|
deploy(_admin, _uniRouter, _wimx, overrides) {
|
|
@@ -17896,19 +18394,19 @@ class ImmutableSwapProxy__factory extends ContractFactory {
|
|
|
17896
18394
|
return super.connect(signer);
|
|
17897
18395
|
}
|
|
17898
18396
|
static bytecode = _bytecode$2;
|
|
17899
|
-
static abi = _abi$
|
|
18397
|
+
static abi = _abi$3;
|
|
17900
18398
|
static createInterface() {
|
|
17901
|
-
return new utils$2.Interface(_abi$
|
|
18399
|
+
return new utils$2.Interface(_abi$3);
|
|
17902
18400
|
}
|
|
17903
18401
|
static connect(address, signerOrProvider) {
|
|
17904
|
-
return new Contract$1(address, _abi$
|
|
18402
|
+
return new Contract$1(address, _abi$3, signerOrProvider);
|
|
17905
18403
|
}
|
|
17906
18404
|
}
|
|
17907
18405
|
|
|
17908
18406
|
/* Autogenerated file. Do not edit manually. */
|
|
17909
18407
|
/* tslint:disable */
|
|
17910
18408
|
/* eslint-disable */
|
|
17911
|
-
const _abi$
|
|
18409
|
+
const _abi$2 = [
|
|
17912
18410
|
{
|
|
17913
18411
|
inputs: [],
|
|
17914
18412
|
name: "getCurrentBlockTimestamp",
|
|
@@ -18008,7 +18506,7 @@ class Multicall__factory extends ContractFactory {
|
|
|
18008
18506
|
super(...args);
|
|
18009
18507
|
}
|
|
18010
18508
|
else {
|
|
18011
|
-
super(_abi$
|
|
18509
|
+
super(_abi$2, _bytecode$1, args[0]);
|
|
18012
18510
|
}
|
|
18013
18511
|
}
|
|
18014
18512
|
deploy(overrides) {
|
|
@@ -18024,19 +18522,19 @@ class Multicall__factory extends ContractFactory {
|
|
|
18024
18522
|
return super.connect(signer);
|
|
18025
18523
|
}
|
|
18026
18524
|
static bytecode = _bytecode$1;
|
|
18027
|
-
static abi = _abi$
|
|
18525
|
+
static abi = _abi$2;
|
|
18028
18526
|
static createInterface() {
|
|
18029
|
-
return new utils$2.Interface(_abi$
|
|
18527
|
+
return new utils$2.Interface(_abi$2);
|
|
18030
18528
|
}
|
|
18031
18529
|
static connect(address, signerOrProvider) {
|
|
18032
|
-
return new Contract$1(address, _abi$
|
|
18530
|
+
return new Contract$1(address, _abi$2, signerOrProvider);
|
|
18033
18531
|
}
|
|
18034
18532
|
}
|
|
18035
18533
|
|
|
18036
18534
|
/* Autogenerated file. Do not edit manually. */
|
|
18037
18535
|
/* tslint:disable */
|
|
18038
18536
|
/* eslint-disable */
|
|
18039
|
-
const _abi = [
|
|
18537
|
+
const _abi$1 = [
|
|
18040
18538
|
{
|
|
18041
18539
|
inputs: [],
|
|
18042
18540
|
stateMutability: "nonpayable",
|
|
@@ -19032,7 +19530,7 @@ class UniswapV3Pool__factory extends ContractFactory {
|
|
|
19032
19530
|
super(...args);
|
|
19033
19531
|
}
|
|
19034
19532
|
else {
|
|
19035
|
-
super(_abi, _bytecode, args[0]);
|
|
19533
|
+
super(_abi$1, _bytecode, args[0]);
|
|
19036
19534
|
}
|
|
19037
19535
|
}
|
|
19038
19536
|
deploy(overrides) {
|
|
@@ -19048,6 +19546,298 @@ class UniswapV3Pool__factory extends ContractFactory {
|
|
|
19048
19546
|
return super.connect(signer);
|
|
19049
19547
|
}
|
|
19050
19548
|
static bytecode = _bytecode;
|
|
19549
|
+
static abi = _abi$1;
|
|
19550
|
+
static createInterface() {
|
|
19551
|
+
return new utils$2.Interface(_abi$1);
|
|
19552
|
+
}
|
|
19553
|
+
static connect(address, signerOrProvider) {
|
|
19554
|
+
return new Contract$1(address, _abi$1, signerOrProvider);
|
|
19555
|
+
}
|
|
19556
|
+
}
|
|
19557
|
+
|
|
19558
|
+
/* Autogenerated file. Do not edit manually. */
|
|
19559
|
+
/* tslint:disable */
|
|
19560
|
+
/* eslint-disable */
|
|
19561
|
+
const _abi = [
|
|
19562
|
+
{
|
|
19563
|
+
constant: true,
|
|
19564
|
+
inputs: [],
|
|
19565
|
+
name: "name",
|
|
19566
|
+
outputs: [
|
|
19567
|
+
{
|
|
19568
|
+
name: "",
|
|
19569
|
+
type: "string",
|
|
19570
|
+
},
|
|
19571
|
+
],
|
|
19572
|
+
payable: false,
|
|
19573
|
+
stateMutability: "view",
|
|
19574
|
+
type: "function",
|
|
19575
|
+
},
|
|
19576
|
+
{
|
|
19577
|
+
constant: false,
|
|
19578
|
+
inputs: [
|
|
19579
|
+
{
|
|
19580
|
+
name: "guy",
|
|
19581
|
+
type: "address",
|
|
19582
|
+
},
|
|
19583
|
+
{
|
|
19584
|
+
name: "wad",
|
|
19585
|
+
type: "uint256",
|
|
19586
|
+
},
|
|
19587
|
+
],
|
|
19588
|
+
name: "approve",
|
|
19589
|
+
outputs: [
|
|
19590
|
+
{
|
|
19591
|
+
name: "",
|
|
19592
|
+
type: "bool",
|
|
19593
|
+
},
|
|
19594
|
+
],
|
|
19595
|
+
payable: false,
|
|
19596
|
+
stateMutability: "nonpayable",
|
|
19597
|
+
type: "function",
|
|
19598
|
+
},
|
|
19599
|
+
{
|
|
19600
|
+
constant: true,
|
|
19601
|
+
inputs: [],
|
|
19602
|
+
name: "totalSupply",
|
|
19603
|
+
outputs: [
|
|
19604
|
+
{
|
|
19605
|
+
name: "",
|
|
19606
|
+
type: "uint256",
|
|
19607
|
+
},
|
|
19608
|
+
],
|
|
19609
|
+
payable: false,
|
|
19610
|
+
stateMutability: "view",
|
|
19611
|
+
type: "function",
|
|
19612
|
+
},
|
|
19613
|
+
{
|
|
19614
|
+
constant: false,
|
|
19615
|
+
inputs: [
|
|
19616
|
+
{
|
|
19617
|
+
name: "src",
|
|
19618
|
+
type: "address",
|
|
19619
|
+
},
|
|
19620
|
+
{
|
|
19621
|
+
name: "dst",
|
|
19622
|
+
type: "address",
|
|
19623
|
+
},
|
|
19624
|
+
{
|
|
19625
|
+
name: "wad",
|
|
19626
|
+
type: "uint256",
|
|
19627
|
+
},
|
|
19628
|
+
],
|
|
19629
|
+
name: "transferFrom",
|
|
19630
|
+
outputs: [
|
|
19631
|
+
{
|
|
19632
|
+
name: "",
|
|
19633
|
+
type: "bool",
|
|
19634
|
+
},
|
|
19635
|
+
],
|
|
19636
|
+
payable: false,
|
|
19637
|
+
stateMutability: "nonpayable",
|
|
19638
|
+
type: "function",
|
|
19639
|
+
},
|
|
19640
|
+
{
|
|
19641
|
+
constant: false,
|
|
19642
|
+
inputs: [
|
|
19643
|
+
{
|
|
19644
|
+
name: "wad",
|
|
19645
|
+
type: "uint256",
|
|
19646
|
+
},
|
|
19647
|
+
],
|
|
19648
|
+
name: "withdraw",
|
|
19649
|
+
outputs: [],
|
|
19650
|
+
payable: false,
|
|
19651
|
+
stateMutability: "nonpayable",
|
|
19652
|
+
type: "function",
|
|
19653
|
+
},
|
|
19654
|
+
{
|
|
19655
|
+
constant: true,
|
|
19656
|
+
inputs: [],
|
|
19657
|
+
name: "decimals",
|
|
19658
|
+
outputs: [
|
|
19659
|
+
{
|
|
19660
|
+
name: "",
|
|
19661
|
+
type: "uint8",
|
|
19662
|
+
},
|
|
19663
|
+
],
|
|
19664
|
+
payable: false,
|
|
19665
|
+
stateMutability: "view",
|
|
19666
|
+
type: "function",
|
|
19667
|
+
},
|
|
19668
|
+
{
|
|
19669
|
+
constant: true,
|
|
19670
|
+
inputs: [
|
|
19671
|
+
{
|
|
19672
|
+
name: "",
|
|
19673
|
+
type: "address",
|
|
19674
|
+
},
|
|
19675
|
+
],
|
|
19676
|
+
name: "balanceOf",
|
|
19677
|
+
outputs: [
|
|
19678
|
+
{
|
|
19679
|
+
name: "",
|
|
19680
|
+
type: "uint256",
|
|
19681
|
+
},
|
|
19682
|
+
],
|
|
19683
|
+
payable: false,
|
|
19684
|
+
stateMutability: "view",
|
|
19685
|
+
type: "function",
|
|
19686
|
+
},
|
|
19687
|
+
{
|
|
19688
|
+
constant: true,
|
|
19689
|
+
inputs: [],
|
|
19690
|
+
name: "symbol",
|
|
19691
|
+
outputs: [
|
|
19692
|
+
{
|
|
19693
|
+
name: "",
|
|
19694
|
+
type: "string",
|
|
19695
|
+
},
|
|
19696
|
+
],
|
|
19697
|
+
payable: false,
|
|
19698
|
+
stateMutability: "view",
|
|
19699
|
+
type: "function",
|
|
19700
|
+
},
|
|
19701
|
+
{
|
|
19702
|
+
constant: false,
|
|
19703
|
+
inputs: [
|
|
19704
|
+
{
|
|
19705
|
+
name: "dst",
|
|
19706
|
+
type: "address",
|
|
19707
|
+
},
|
|
19708
|
+
{
|
|
19709
|
+
name: "wad",
|
|
19710
|
+
type: "uint256",
|
|
19711
|
+
},
|
|
19712
|
+
],
|
|
19713
|
+
name: "transfer",
|
|
19714
|
+
outputs: [
|
|
19715
|
+
{
|
|
19716
|
+
name: "",
|
|
19717
|
+
type: "bool",
|
|
19718
|
+
},
|
|
19719
|
+
],
|
|
19720
|
+
payable: false,
|
|
19721
|
+
stateMutability: "nonpayable",
|
|
19722
|
+
type: "function",
|
|
19723
|
+
},
|
|
19724
|
+
{
|
|
19725
|
+
constant: false,
|
|
19726
|
+
inputs: [],
|
|
19727
|
+
name: "deposit",
|
|
19728
|
+
outputs: [],
|
|
19729
|
+
payable: true,
|
|
19730
|
+
stateMutability: "payable",
|
|
19731
|
+
type: "function",
|
|
19732
|
+
},
|
|
19733
|
+
{
|
|
19734
|
+
constant: true,
|
|
19735
|
+
inputs: [
|
|
19736
|
+
{
|
|
19737
|
+
name: "",
|
|
19738
|
+
type: "address",
|
|
19739
|
+
},
|
|
19740
|
+
{
|
|
19741
|
+
name: "",
|
|
19742
|
+
type: "address",
|
|
19743
|
+
},
|
|
19744
|
+
],
|
|
19745
|
+
name: "allowance",
|
|
19746
|
+
outputs: [
|
|
19747
|
+
{
|
|
19748
|
+
name: "",
|
|
19749
|
+
type: "uint256",
|
|
19750
|
+
},
|
|
19751
|
+
],
|
|
19752
|
+
payable: false,
|
|
19753
|
+
stateMutability: "view",
|
|
19754
|
+
type: "function",
|
|
19755
|
+
},
|
|
19756
|
+
{
|
|
19757
|
+
payable: true,
|
|
19758
|
+
stateMutability: "payable",
|
|
19759
|
+
type: "fallback",
|
|
19760
|
+
},
|
|
19761
|
+
{
|
|
19762
|
+
anonymous: false,
|
|
19763
|
+
inputs: [
|
|
19764
|
+
{
|
|
19765
|
+
indexed: true,
|
|
19766
|
+
name: "src",
|
|
19767
|
+
type: "address",
|
|
19768
|
+
},
|
|
19769
|
+
{
|
|
19770
|
+
indexed: true,
|
|
19771
|
+
name: "guy",
|
|
19772
|
+
type: "address",
|
|
19773
|
+
},
|
|
19774
|
+
{
|
|
19775
|
+
indexed: false,
|
|
19776
|
+
name: "wad",
|
|
19777
|
+
type: "uint256",
|
|
19778
|
+
},
|
|
19779
|
+
],
|
|
19780
|
+
name: "Approval",
|
|
19781
|
+
type: "event",
|
|
19782
|
+
},
|
|
19783
|
+
{
|
|
19784
|
+
anonymous: false,
|
|
19785
|
+
inputs: [
|
|
19786
|
+
{
|
|
19787
|
+
indexed: true,
|
|
19788
|
+
name: "src",
|
|
19789
|
+
type: "address",
|
|
19790
|
+
},
|
|
19791
|
+
{
|
|
19792
|
+
indexed: true,
|
|
19793
|
+
name: "dst",
|
|
19794
|
+
type: "address",
|
|
19795
|
+
},
|
|
19796
|
+
{
|
|
19797
|
+
indexed: false,
|
|
19798
|
+
name: "wad",
|
|
19799
|
+
type: "uint256",
|
|
19800
|
+
},
|
|
19801
|
+
],
|
|
19802
|
+
name: "Transfer",
|
|
19803
|
+
type: "event",
|
|
19804
|
+
},
|
|
19805
|
+
{
|
|
19806
|
+
anonymous: false,
|
|
19807
|
+
inputs: [
|
|
19808
|
+
{
|
|
19809
|
+
indexed: true,
|
|
19810
|
+
name: "dst",
|
|
19811
|
+
type: "address",
|
|
19812
|
+
},
|
|
19813
|
+
{
|
|
19814
|
+
indexed: false,
|
|
19815
|
+
name: "wad",
|
|
19816
|
+
type: "uint256",
|
|
19817
|
+
},
|
|
19818
|
+
],
|
|
19819
|
+
name: "Deposit",
|
|
19820
|
+
type: "event",
|
|
19821
|
+
},
|
|
19822
|
+
{
|
|
19823
|
+
anonymous: false,
|
|
19824
|
+
inputs: [
|
|
19825
|
+
{
|
|
19826
|
+
indexed: true,
|
|
19827
|
+
name: "src",
|
|
19828
|
+
type: "address",
|
|
19829
|
+
},
|
|
19830
|
+
{
|
|
19831
|
+
indexed: false,
|
|
19832
|
+
name: "wad",
|
|
19833
|
+
type: "uint256",
|
|
19834
|
+
},
|
|
19835
|
+
],
|
|
19836
|
+
name: "Withdrawal",
|
|
19837
|
+
type: "event",
|
|
19838
|
+
},
|
|
19839
|
+
];
|
|
19840
|
+
class WIMX__factory {
|
|
19051
19841
|
static abi = _abi;
|
|
19052
19842
|
static createInterface() {
|
|
19053
19843
|
return new utils$2.Interface(_abi);
|
|
@@ -19676,6 +20466,13 @@ class NativeTokenService {
|
|
|
19676
20466
|
maybeWrapAmount(amount) {
|
|
19677
20467
|
return newAmount(amount.value, this.maybeWrapToken(amount.token));
|
|
19678
20468
|
}
|
|
20469
|
+
isWrappedNative(token) {
|
|
20470
|
+
return token.type === 'erc20' && token.address.toLowerCase() === this.wrappedToken.address.toLowerCase();
|
|
20471
|
+
}
|
|
20472
|
+
isWrapOrUnwrap(tokenIn, tokenOut) {
|
|
20473
|
+
return ((tokenIn === this.nativeToken && (this.isWrappedNative(tokenOut))) ||
|
|
20474
|
+
((this.isWrappedNative(tokenIn)) && tokenOut === this.nativeToken));
|
|
20475
|
+
}
|
|
19679
20476
|
}
|
|
19680
20477
|
|
|
19681
20478
|
// slippageToPercent takes the slippage as a percentage (e.g. 0.1) and
|
|
@@ -19774,6 +20571,16 @@ class Fees {
|
|
|
19774
20571
|
}
|
|
19775
20572
|
}
|
|
19776
20573
|
|
|
20574
|
+
// 45038 is the upper bound of the gas estimate for the deposit function.
|
|
20575
|
+
// This upper bound is reached when a user is wrapping for the first time (cold + unused storage slot)
|
|
20576
|
+
// The lower bound is 27,938, so the difference is 17,100 gas. If transactions are 10 gwei IMX,
|
|
20577
|
+
// this is about 0.000171 IMX difference. In order to avoid an extra remote call, we just use the upper bound instead.
|
|
20578
|
+
const IMX_WRAP_GAS_COST = 45038;
|
|
20579
|
+
// 35216 is the upper bound of the gas estimate for the withdraw function.
|
|
20580
|
+
// The differenfce between upper and normal is less than 0.0001 IMX, so we just use the upper bound
|
|
20581
|
+
// to avoid an extra remote call.
|
|
20582
|
+
const IMX_UNWRAP_GAS_COST = 35216;
|
|
20583
|
+
|
|
19777
20584
|
const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com';
|
|
19778
20585
|
const IMMUTABLE_TESTNET_CHAIN_ID = 13473;
|
|
19779
20586
|
|
|
@@ -20287,6 +21094,67 @@ class Exchange {
|
|
|
20287
21094
|
decimals,
|
|
20288
21095
|
};
|
|
20289
21096
|
}
|
|
21097
|
+
async getUnwrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
21098
|
+
const calldata = wimxInterface.encodeFunctionData('withdraw', [tokenAmount]);
|
|
21099
|
+
const gasEstimate = ethers.BigNumber.from(IMX_UNWRAP_GAS_COST);
|
|
21100
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
21101
|
+
// This transaction is for calling calling `withdraw` on the WETH/WIMX contract.
|
|
21102
|
+
const transactionDetails = {
|
|
21103
|
+
transaction: {
|
|
21104
|
+
data: calldata,
|
|
21105
|
+
to: this.wrappedNativeToken.address,
|
|
21106
|
+
from: fromAddress,
|
|
21107
|
+
},
|
|
21108
|
+
gasFeeEstimate,
|
|
21109
|
+
};
|
|
21110
|
+
return {
|
|
21111
|
+
transaction: transactionDetails,
|
|
21112
|
+
approval: null,
|
|
21113
|
+
};
|
|
21114
|
+
}
|
|
21115
|
+
getWrapTransaction(fromAddress, tokenAmount, wimxInterface, gasPrice) {
|
|
21116
|
+
const calldata = wimxInterface.encodeFunctionData('deposit');
|
|
21117
|
+
const gasEstimate = ethers.BigNumber.from(IMX_WRAP_GAS_COST);
|
|
21118
|
+
const gasFeeEstimate = gasPrice ? toPublicAmount(calculateGasFee(gasPrice, gasEstimate)) : null;
|
|
21119
|
+
// This transaction is for calling calling `deposit` on the WETH/WIMX contract.
|
|
21120
|
+
const transactionDetails = {
|
|
21121
|
+
transaction: {
|
|
21122
|
+
data: calldata,
|
|
21123
|
+
to: this.wrappedNativeToken.address,
|
|
21124
|
+
value: tokenAmount,
|
|
21125
|
+
from: fromAddress,
|
|
21126
|
+
},
|
|
21127
|
+
gasFeeEstimate,
|
|
21128
|
+
};
|
|
21129
|
+
return {
|
|
21130
|
+
transaction: transactionDetails,
|
|
21131
|
+
approval: null,
|
|
21132
|
+
};
|
|
21133
|
+
}
|
|
21134
|
+
async getUnsignedWrapUnwrapTx(tokenSpecified, amountIn, fromAddress, gasPrice) {
|
|
21135
|
+
const isWrap = amountIn.token.type === 'native';
|
|
21136
|
+
const quoteToken = tokenSpecified.type === 'native' ? this.wrappedNativeToken : this.nativeToken;
|
|
21137
|
+
const otherTokenCoinAmount = {
|
|
21138
|
+
token: quoteToken,
|
|
21139
|
+
value: amountIn.value,
|
|
21140
|
+
};
|
|
21141
|
+
// The quote is always 1:1 (0 {price impact, slippage}) when wrapping/unwrapping.
|
|
21142
|
+
const quote = {
|
|
21143
|
+
amount: toPublicAmount(otherTokenCoinAmount),
|
|
21144
|
+
amountWithMaxSlippage: toPublicAmount(otherTokenCoinAmount),
|
|
21145
|
+
slippage: 0,
|
|
21146
|
+
fees: [],
|
|
21147
|
+
};
|
|
21148
|
+
const wimxInterface = WIMX__factory.createInterface();
|
|
21149
|
+
let transactionDetails;
|
|
21150
|
+
if (isWrap) {
|
|
21151
|
+
transactionDetails = this.getWrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
21152
|
+
}
|
|
21153
|
+
else {
|
|
21154
|
+
transactionDetails = await this.getUnwrapTransaction(fromAddress, otherTokenCoinAmount.value, wimxInterface, gasPrice);
|
|
21155
|
+
}
|
|
21156
|
+
return { quote, approval: transactionDetails.approval, swap: transactionDetails.transaction };
|
|
21157
|
+
}
|
|
20290
21158
|
async getUnsignedSwapTx(fromAddress, tokenInLiteral, tokenOutLiteral, amount, slippagePercent, maxHops, deadline, tradeType) {
|
|
20291
21159
|
Exchange.validate(tokenInLiteral, tokenOutLiteral, maxHops, slippagePercent, fromAddress);
|
|
20292
21160
|
// get the decimals of the tokens that will be swapped
|
|
@@ -20302,6 +21170,11 @@ class Exchange {
|
|
|
20302
21170
|
// determine which amount was specified for the swap from the TradeType
|
|
20303
21171
|
const [tokenSpecified, otherToken] = tradeType === TradeType.EXACT_INPUT ? [tokenIn, tokenOut] : [tokenOut, tokenIn];
|
|
20304
21172
|
const amountSpecified = newAmount(amount, tokenSpecified);
|
|
21173
|
+
if (this.nativeTokenService.isWrapOrUnwrap(tokenIn, tokenOut)) {
|
|
21174
|
+
// If the user is swapping between the native token and the wrapped native token,
|
|
21175
|
+
// we want to just wrap/unwrap the native token instead of swapping
|
|
21176
|
+
return this.getUnsignedWrapUnwrapTx(tokenSpecified, newAmount(amount, tokenIn), fromAddress, gasPrice);
|
|
21177
|
+
}
|
|
20305
21178
|
const fees = new Fees(secondaryFees, tokenIn);
|
|
20306
21179
|
const ourQuoteReqAmount = getOurQuoteReqAmount(amountSpecified, fees, tradeType, this.nativeTokenService);
|
|
20307
21180
|
// Quotes will always use ERC20s. If the user-specified token is Native, we use the Wrapped Native Token pool
|
|
@@ -25961,7 +26834,7 @@ class APIError extends Error {
|
|
|
25961
26834
|
|
|
25962
26835
|
/* eslint-disable implicit-arrow-linebreak */
|
|
25963
26836
|
const defaultHeaders = {
|
|
25964
|
-
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.
|
|
26837
|
+
sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.45.3-alpha',
|
|
25965
26838
|
};
|
|
25966
26839
|
/**
|
|
25967
26840
|
* createAPIConfiguration to create a custom Configuration
|
|
@@ -26612,6 +27485,7 @@ var WalletAction;
|
|
|
26612
27485
|
WalletAction["ADD_NETWORK"] = "wallet_addEthereumChain";
|
|
26613
27486
|
WalletAction["SWITCH_NETWORK"] = "wallet_switchEthereumChain";
|
|
26614
27487
|
WalletAction["GET_CHAINID"] = "eth_chainId";
|
|
27488
|
+
WalletAction["REQUEST_PERMISSIONS"] = "wallet_requestPermissions";
|
|
26615
27489
|
})(WalletAction || (WalletAction = {}));
|
|
26616
27490
|
/**
|
|
26617
27491
|
* Enum representing the platform filters used in {@link GetWalletAllowListParams}.
|
|
@@ -27322,7 +28196,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
|
|
|
27322
28196
|
maxPriorityFeePerGas: BigNumber$1.from(10e9),
|
|
27323
28197
|
};
|
|
27324
28198
|
|
|
27325
|
-
const SDK_VERSION_MARKER = '0.45.
|
|
28199
|
+
const SDK_VERSION_MARKER = '0.45.3-alpha';
|
|
27326
28200
|
// This SDK version is replaced by the `yarn build` command ran on the root level
|
|
27327
28201
|
const globalPackageVersion = () => SDK_VERSION_MARKER;
|
|
27328
28202
|
|
|
@@ -27906,6 +28780,21 @@ async function connectSite(web3Provider) {
|
|
|
27906
28780
|
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
27907
28781
|
return web3Provider;
|
|
27908
28782
|
}
|
|
28783
|
+
async function requestPermissions(web3Provider) {
|
|
28784
|
+
if (!web3Provider || !web3Provider.provider?.request) {
|
|
28785
|
+
throw new CheckoutError('Incompatible provider', CheckoutErrorType.PROVIDER_REQUEST_MISSING_ERROR, { details: 'Attempting to connect with an incompatible provider' });
|
|
28786
|
+
}
|
|
28787
|
+
await withCheckoutError(async () => {
|
|
28788
|
+
if (!web3Provider.provider.request)
|
|
28789
|
+
return;
|
|
28790
|
+
await web3Provider.provider.request({
|
|
28791
|
+
method: WalletAction.REQUEST_PERMISSIONS,
|
|
28792
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28793
|
+
params: [{ eth_accounts: {} }],
|
|
28794
|
+
});
|
|
28795
|
+
}, { type: CheckoutErrorType.USER_REJECTED_REQUEST_ERROR });
|
|
28796
|
+
return web3Provider;
|
|
28797
|
+
}
|
|
27909
28798
|
|
|
27910
28799
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
27911
28800
|
async function getMetaMaskProvider() {
|
|
@@ -31054,7 +31943,12 @@ class Checkout {
|
|
|
31054
31943
|
*/
|
|
31055
31944
|
async connect(params) {
|
|
31056
31945
|
const web3Provider = await validateProvider(this.config, params.provider, { allowUnsupportedProvider: true });
|
|
31057
|
-
|
|
31946
|
+
if (params.requestWalletPermissions && !web3Provider.provider?.isPassport) {
|
|
31947
|
+
await requestPermissions(web3Provider);
|
|
31948
|
+
}
|
|
31949
|
+
else {
|
|
31950
|
+
await connectSite(web3Provider);
|
|
31951
|
+
}
|
|
31058
31952
|
return { provider: web3Provider };
|
|
31059
31953
|
}
|
|
31060
31954
|
/**
|