@lifi/sdk 2.0.0-beta.4 → 2.0.0-beta.5
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/cjs/helpers.js +33 -1
- package/dist/cjs/services/ConfigService.js +6 -1
- package/dist/cjs/types/internal.types.d.ts +6 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/helpers.js +30 -1
- package/dist/services/ConfigService.js +7 -1
- package/dist/types/internal.types.d.ts +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -7
package/dist/cjs/helpers.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.request = exports.requestSettings = exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
|
|
7
|
+
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
4
8
|
const errors_1 = require("./utils/errors");
|
|
5
9
|
const utils_1 = require("./utils/utils");
|
|
6
10
|
const version_1 = require("./version");
|
|
@@ -109,6 +113,7 @@ const convertQuoteToRoute = (step) => {
|
|
|
109
113
|
toAmountUSD: step.estimate.toAmountUSD,
|
|
110
114
|
steps: [lifiStep],
|
|
111
115
|
toAmountMin: step.estimate.toAmountMin,
|
|
116
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
112
117
|
};
|
|
113
118
|
return route;
|
|
114
119
|
};
|
|
@@ -117,8 +122,35 @@ exports.requestSettings = {
|
|
|
117
122
|
retries: 1,
|
|
118
123
|
};
|
|
119
124
|
const request = async (url, options, retries = exports.requestSettings.retries) => {
|
|
125
|
+
const { userId, integrator, widgetVersion } = ConfigService_1.default.getInstance().getConfig();
|
|
120
126
|
try {
|
|
121
|
-
const
|
|
127
|
+
const updatedOptions = {
|
|
128
|
+
...(options ?? {}),
|
|
129
|
+
};
|
|
130
|
+
if (userId) {
|
|
131
|
+
updatedOptions.headers = {
|
|
132
|
+
...options?.headers,
|
|
133
|
+
'X-LIFI-UserId': userId,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (widgetVersion) {
|
|
137
|
+
updatedOptions.headers = {
|
|
138
|
+
...options?.headers,
|
|
139
|
+
'X-LIFI-Widget': widgetVersion,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (version_1.version) {
|
|
143
|
+
updatedOptions.headers = {
|
|
144
|
+
...options?.headers,
|
|
145
|
+
'X-LIFI-SDK': version_1.version,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// integrator is mandatory during SDK initialization
|
|
149
|
+
updatedOptions.headers = {
|
|
150
|
+
...options?.headers,
|
|
151
|
+
'X-LIFI-Integrator': integrator,
|
|
152
|
+
};
|
|
153
|
+
const response = await fetch(url, updatedOptions);
|
|
122
154
|
if (!response.ok) {
|
|
123
155
|
throw new errors_1.HTTPError(response);
|
|
124
156
|
}
|
|
@@ -39,6 +39,10 @@ class ConfigService {
|
|
|
39
39
|
this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
|
|
40
40
|
// OPTIONS
|
|
41
41
|
this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
|
|
42
|
+
this.config.userId = configUpdate.userId || this.config.userId;
|
|
43
|
+
this.config.integrator = configUpdate.integrator || this.config.integrator;
|
|
44
|
+
this.config.widgetVersion =
|
|
45
|
+
configUpdate.widgetVersion || this.config.widgetVersion;
|
|
42
46
|
return this.config;
|
|
43
47
|
};
|
|
44
48
|
this.updateChains = (chains) => {
|
|
@@ -78,7 +82,6 @@ class ConfigService {
|
|
|
78
82
|
return this.instance;
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
|
-
exports.default = ConfigService;
|
|
82
85
|
ConfigService.getDefaultConfig = () => {
|
|
83
86
|
return {
|
|
84
87
|
apiUrl: 'https://li.quest/v1',
|
|
@@ -88,5 +91,7 @@ ConfigService.getDefaultConfig = () => {
|
|
|
88
91
|
defaultRouteOptions: {
|
|
89
92
|
integrator: 'lifi-sdk',
|
|
90
93
|
},
|
|
94
|
+
integrator: 'lifi-sdk',
|
|
91
95
|
};
|
|
92
96
|
};
|
|
97
|
+
exports.default = ConfigService;
|
|
@@ -30,6 +30,9 @@ export type Config = {
|
|
|
30
30
|
defaultExecutionSettings: InternalExecutionSettings;
|
|
31
31
|
defaultRouteOptions: RouteOptions;
|
|
32
32
|
disableVersionCheck?: boolean;
|
|
33
|
+
userId?: string;
|
|
34
|
+
integrator: string;
|
|
35
|
+
widgetVersion?: string;
|
|
33
36
|
};
|
|
34
37
|
export type ConfigUpdate = {
|
|
35
38
|
apiUrl?: string;
|
|
@@ -38,6 +41,9 @@ export type ConfigUpdate = {
|
|
|
38
41
|
defaultExecutionSettings?: ExecutionSettings;
|
|
39
42
|
defaultRouteOptions?: RouteOptions;
|
|
40
43
|
disableVersionCheck?: boolean;
|
|
44
|
+
userId?: string;
|
|
45
|
+
integrator: string;
|
|
46
|
+
widgetVersion?: string;
|
|
41
47
|
};
|
|
42
48
|
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
43
49
|
export interface AcceptSlippageUpdateHookParams {
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.5";
|
package/dist/cjs/version.js
CHANGED
package/dist/helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ConfigService from './services/ConfigService';
|
|
1
2
|
import { HTTPError, ValidationError } from './utils/errors';
|
|
2
3
|
import { sleep } from './utils/utils';
|
|
3
4
|
import { name, version } from './version';
|
|
@@ -101,6 +102,7 @@ export const convertQuoteToRoute = (step) => {
|
|
|
101
102
|
toAmountUSD: step.estimate.toAmountUSD,
|
|
102
103
|
steps: [lifiStep],
|
|
103
104
|
toAmountMin: step.estimate.toAmountMin,
|
|
105
|
+
insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
|
|
104
106
|
};
|
|
105
107
|
return route;
|
|
106
108
|
};
|
|
@@ -108,8 +110,35 @@ export const requestSettings = {
|
|
|
108
110
|
retries: 1,
|
|
109
111
|
};
|
|
110
112
|
export const request = async (url, options, retries = requestSettings.retries) => {
|
|
113
|
+
const { userId, integrator, widgetVersion } = ConfigService.getInstance().getConfig();
|
|
111
114
|
try {
|
|
112
|
-
const
|
|
115
|
+
const updatedOptions = {
|
|
116
|
+
...(options ?? {}),
|
|
117
|
+
};
|
|
118
|
+
if (userId) {
|
|
119
|
+
updatedOptions.headers = {
|
|
120
|
+
...options?.headers,
|
|
121
|
+
'X-LIFI-UserId': userId,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (widgetVersion) {
|
|
125
|
+
updatedOptions.headers = {
|
|
126
|
+
...options?.headers,
|
|
127
|
+
'X-LIFI-Widget': widgetVersion,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (version) {
|
|
131
|
+
updatedOptions.headers = {
|
|
132
|
+
...options?.headers,
|
|
133
|
+
'X-LIFI-SDK': version,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// integrator is mandatory during SDK initialization
|
|
137
|
+
updatedOptions.headers = {
|
|
138
|
+
...options?.headers,
|
|
139
|
+
'X-LIFI-Integrator': integrator,
|
|
140
|
+
};
|
|
141
|
+
const response = await fetch(url, updatedOptions);
|
|
113
142
|
if (!response.ok) {
|
|
114
143
|
throw new HTTPError(response);
|
|
115
144
|
}
|
|
@@ -8,7 +8,7 @@ const DefaultExecutionSettings = {
|
|
|
8
8
|
infiniteApproval: false,
|
|
9
9
|
executeInBackground: false,
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
class ConfigService {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.resolveSetupPromise = undefined;
|
|
14
14
|
/**
|
|
@@ -37,6 +37,10 @@ export default class ConfigService {
|
|
|
37
37
|
this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
|
|
38
38
|
// OPTIONS
|
|
39
39
|
this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
|
|
40
|
+
this.config.userId = configUpdate.userId || this.config.userId;
|
|
41
|
+
this.config.integrator = configUpdate.integrator || this.config.integrator;
|
|
42
|
+
this.config.widgetVersion =
|
|
43
|
+
configUpdate.widgetVersion || this.config.widgetVersion;
|
|
40
44
|
return this.config;
|
|
41
45
|
};
|
|
42
46
|
this.updateChains = (chains) => {
|
|
@@ -85,5 +89,7 @@ ConfigService.getDefaultConfig = () => {
|
|
|
85
89
|
defaultRouteOptions: {
|
|
86
90
|
integrator: 'lifi-sdk',
|
|
87
91
|
},
|
|
92
|
+
integrator: 'lifi-sdk',
|
|
88
93
|
};
|
|
89
94
|
};
|
|
95
|
+
export default ConfigService;
|
|
@@ -30,6 +30,9 @@ export type Config = {
|
|
|
30
30
|
defaultExecutionSettings: InternalExecutionSettings;
|
|
31
31
|
defaultRouteOptions: RouteOptions;
|
|
32
32
|
disableVersionCheck?: boolean;
|
|
33
|
+
userId?: string;
|
|
34
|
+
integrator: string;
|
|
35
|
+
widgetVersion?: string;
|
|
33
36
|
};
|
|
34
37
|
export type ConfigUpdate = {
|
|
35
38
|
apiUrl?: string;
|
|
@@ -38,6 +41,9 @@ export type ConfigUpdate = {
|
|
|
38
41
|
defaultExecutionSettings?: ExecutionSettings;
|
|
39
42
|
defaultRouteOptions?: RouteOptions;
|
|
40
43
|
disableVersionCheck?: boolean;
|
|
44
|
+
userId?: string;
|
|
45
|
+
integrator: string;
|
|
46
|
+
widgetVersion?: string;
|
|
41
47
|
};
|
|
42
48
|
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>;
|
|
43
49
|
export interface AcceptSlippageUpdateHookParams {
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.5";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '2.0.0-beta.
|
|
2
|
+
export const version = '2.0.0-beta.5';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@ethersproject/abi": "^5.7.0",
|
|
78
78
|
"@ethersproject/contracts": "^5.7.0",
|
|
79
|
-
"@lifi/types": "^2.
|
|
79
|
+
"@lifi/types": "^2.5.2",
|
|
80
80
|
"bignumber.js": "^9.1.1",
|
|
81
81
|
"eth-rpc-errors": "^4.0.3",
|
|
82
82
|
"ethers": "^5.7.2"
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@commitlint/cli": "^17.4.4",
|
|
86
86
|
"@commitlint/config-conventional": "^17.4.4",
|
|
87
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
88
|
-
"@typescript-eslint/parser": "^5.
|
|
89
|
-
"@vitest/coverage-c8": "^0.29.
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
88
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
89
|
+
"@vitest/coverage-c8": "^0.29.3",
|
|
90
90
|
"cross-fetch": "^3.1.5",
|
|
91
91
|
"eslint": "^8.36.0",
|
|
92
92
|
"eslint-config-prettier": "^8.7.0",
|
|
@@ -99,8 +99,8 @@
|
|
|
99
99
|
"prettier": "^2.8.4",
|
|
100
100
|
"standard-version": "^9.5.0",
|
|
101
101
|
"ts-loader": "^9.4.2",
|
|
102
|
-
"typescript": "^
|
|
103
|
-
"vitest": "^0.29.
|
|
102
|
+
"typescript": "^5.0.2",
|
|
103
|
+
"vitest": "^0.29.3"
|
|
104
104
|
},
|
|
105
105
|
"directories": {
|
|
106
106
|
"test": "test"
|