ESLint standard

This commit is contained in:
Aleksandr Kraiz
2023-02-08 02:15:43 +04:00
parent f5b7b019c8
commit ed33a83570
14 changed files with 354 additions and 72 deletions

View File

@@ -6,16 +6,13 @@ module.exports = {
node: true,
},
extends: [
'airbnb-base',
'standard',
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:import/typescript'
],
include: [
'jest.config.ts'
],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
@@ -29,6 +26,10 @@ module.exports = {
'@typescript-eslint',
],
rules: {
"comma-dangle": 0,
"semi": 0,
"space-before-function-paren": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"no-param-reassign": [
"error",
{
@@ -58,6 +59,9 @@ module.exports = {
1,
140,
2,
{
ignoreComments: true,
}
],
'import/extensions': [
'error',

269
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.17.0-rc.0",
"version": "0.17.0-rc.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.17.0-rc.0",
"version": "0.17.0-rc.1",
"license": "ISC",
"dependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
@@ -47,7 +47,11 @@
"concurrently": "^7.0.0",
"eslint": "^8.33.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-standard": "^17.0.0",
"eslint-config-standard-with-typescript": "^34.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"husky": "^7.0.4",
"jest": "^29.4.2",
"ts-jest": "^29.0.5",
@@ -3999,6 +4003,30 @@
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
"integrity": "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ=="
},
"node_modules/builtins": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.1.tgz",
"integrity": "sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==",
"dev": true,
"dependencies": {
"semver": "^7.0.0"
}
},
"node_modules/builtins/node_modules/semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
@@ -4899,6 +4927,50 @@
"eslint-plugin-import": "^2.25.2"
}
},
"node_modules/eslint-config-standard": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz",
"integrity": "sha512-/2ks1GKyqSOkH7JFvXJicu0iMpoojkwB+f5Du/1SC0PtBL+s8v30k9njRZ21pm2drKYm2342jFnGWzttxPmZVg==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"peerDependencies": {
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0"
}
},
"node_modules/eslint-config-standard-with-typescript": {
"version": "34.0.0",
"resolved": "https://registry.npmjs.org/eslint-config-standard-with-typescript/-/eslint-config-standard-with-typescript-34.0.0.tgz",
"integrity": "sha512-zhCsI4/A0rJ1ma8sf3RLXYc0gc7yPmdTWRVXMh9dtqeUx3yBQyALH0wosHhk1uQ9QyItynLdNOtcHKNw8G7lQw==",
"dev": true,
"dependencies": {
"@typescript-eslint/parser": "^5.0.0",
"eslint-config-standard": "17.0.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"typescript": "*"
}
},
"node_modules/eslint-import-resolver-node": {
"version": "0.3.7",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz",
@@ -4945,6 +5017,49 @@
"ms": "^2.1.1"
}
},
"node_modules/eslint-plugin-es": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz",
"integrity": "sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==",
"dev": true,
"dependencies": {
"eslint-utils": "^2.0.0",
"regexpp": "^3.0.0"
},
"engines": {
"node": ">=8.10.0"
},
"funding": {
"url": "https://github.com/sponsors/mysticatea"
},
"peerDependencies": {
"eslint": ">=4.19.1"
}
},
"node_modules/eslint-plugin-es/node_modules/eslint-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz",
"integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==",
"dev": true,
"dependencies": {
"eslint-visitor-keys": "^1.1.0"
},
"engines": {
"node": ">=6"
},
"funding": {
"url": "https://github.com/sponsors/mysticatea"
}
},
"node_modules/eslint-plugin-es/node_modules/eslint-visitor-keys": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
"integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/eslint-plugin-import": {
"version": "2.27.5",
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz",
@@ -4995,6 +5110,58 @@
"node": ">=0.10.0"
}
},
"node_modules/eslint-plugin-n": {
"version": "15.6.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-15.6.1.tgz",
"integrity": "sha512-R9xw9OtCRxxaxaszTQmQAlPgM+RdGjaL1akWuY/Fv9fRAi8Wj4CUKc6iYVG8QNRjRuo8/BqVYIpfqberJUEacA==",
"dev": true,
"dependencies": {
"builtins": "^5.0.1",
"eslint-plugin-es": "^4.1.0",
"eslint-utils": "^3.0.0",
"ignore": "^5.1.1",
"is-core-module": "^2.11.0",
"minimatch": "^3.1.2",
"resolve": "^1.22.1",
"semver": "^7.3.8"
},
"engines": {
"node": ">=12.22.0"
},
"funding": {
"url": "https://github.com/sponsors/mysticatea"
},
"peerDependencies": {
"eslint": ">=7.0.0"
}
},
"node_modules/eslint-plugin-n/node_modules/semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/eslint-plugin-promise": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz",
"integrity": "sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==",
"dev": true,
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0"
}
},
"node_modules/eslint-scope": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
@@ -13900,6 +14067,26 @@
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
"integrity": "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ=="
},
"builtins": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.1.tgz",
"integrity": "sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==",
"dev": true,
"requires": {
"semver": "^7.0.0"
},
"dependencies": {
"semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
}
}
},
"bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
@@ -14684,6 +14871,23 @@
"semver": "^6.3.0"
}
},
"eslint-config-standard": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/eslint-config-standard/-/eslint-config-standard-17.0.0.tgz",
"integrity": "sha512-/2ks1GKyqSOkH7JFvXJicu0iMpoojkwB+f5Du/1SC0PtBL+s8v30k9njRZ21pm2drKYm2342jFnGWzttxPmZVg==",
"dev": true,
"requires": {}
},
"eslint-config-standard-with-typescript": {
"version": "34.0.0",
"resolved": "https://registry.npmjs.org/eslint-config-standard-with-typescript/-/eslint-config-standard-with-typescript-34.0.0.tgz",
"integrity": "sha512-zhCsI4/A0rJ1ma8sf3RLXYc0gc7yPmdTWRVXMh9dtqeUx3yBQyALH0wosHhk1uQ9QyItynLdNOtcHKNw8G7lQw==",
"dev": true,
"requires": {
"@typescript-eslint/parser": "^5.0.0",
"eslint-config-standard": "17.0.0"
}
},
"eslint-import-resolver-node": {
"version": "0.3.7",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz",
@@ -14726,6 +14930,33 @@
}
}
},
"eslint-plugin-es": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz",
"integrity": "sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==",
"dev": true,
"requires": {
"eslint-utils": "^2.0.0",
"regexpp": "^3.0.0"
},
"dependencies": {
"eslint-utils": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz",
"integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==",
"dev": true,
"requires": {
"eslint-visitor-keys": "^1.1.0"
}
},
"eslint-visitor-keys": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
"integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
"dev": true
}
}
},
"eslint-plugin-import": {
"version": "2.27.5",
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.27.5.tgz",
@@ -14769,6 +15000,40 @@
}
}
},
"eslint-plugin-n": {
"version": "15.6.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-15.6.1.tgz",
"integrity": "sha512-R9xw9OtCRxxaxaszTQmQAlPgM+RdGjaL1akWuY/Fv9fRAi8Wj4CUKc6iYVG8QNRjRuo8/BqVYIpfqberJUEacA==",
"dev": true,
"requires": {
"builtins": "^5.0.1",
"eslint-plugin-es": "^4.1.0",
"eslint-utils": "^3.0.0",
"ignore": "^5.1.1",
"is-core-module": "^2.11.0",
"minimatch": "^3.1.2",
"resolve": "^1.22.1",
"semver": "^7.3.8"
},
"dependencies": {
"semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
"integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
}
}
},
"eslint-plugin-promise": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz",
"integrity": "sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==",
"dev": true,
"requires": {}
},
"eslint-scope": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.17.0-rc.1",
"version": "0.17.0-rc.2",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",
@@ -54,7 +54,11 @@
"concurrently": "^7.0.0",
"eslint": "^8.33.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-standard": "^17.0.0",
"eslint-config-standard-with-typescript": "^34.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-promise": "^6.1.1",
"husky": "^7.0.4",
"jest": "^29.4.2",
"ts-jest": "^29.0.5",

View File

@@ -82,9 +82,9 @@ export default class BalanceGuard {
return requirements
.reduce<AggregatedBalanceRequirement[]>((prev, curr) => {
const aggregatedBalanceRequirement = prev.find(
(item) => item.asset.address === curr.asset.address
&& arrayEquals(item.sources, curr.sources)
&& item.spenderAddress === curr.spenderAddress,
(item) => item.asset.address === curr.asset.address &&
arrayEquals(item.sources, curr.sources) &&
item.spenderAddress === curr.spenderAddress,
);
if (aggregatedBalanceRequirement) {
@@ -163,9 +163,9 @@ export default class BalanceGuard {
async check(fixAutofixable?: boolean) {
this.logger?.(`Balance requirements: ${this.requirements
.map((requirement) => `${requirement.amount} ${requirement.asset.name} `
+ `for '${requirement.reason}' `
+ `from [${requirement.sources.join(' + ')}]`)
.map((requirement) => `${requirement.amount} ${requirement.asset.name} ` +
`for '${requirement.reason}' ` +
`from [${requirement.sources.join(' + ')}]`)
.join(', ')}`);
const remainingBalances = clone(this.balances);
@@ -206,9 +206,9 @@ export default class BalanceGuard {
balanceIssues.push({
asset,
sources: ['exchange'],
message: `Not enough ${asset.name} on exchange balance. `
+ `Needed: ${itemsAmountSum.toString()}, available: ${exchangeBalance?.toString()}. `
+ `You need to deposit at least ${lackAmount.toString()} ${asset.name} into exchange contract`,
message: `Not enough ${asset.name} on exchange balance. ` +
`Needed: ${itemsAmountSum.toString()}, available: ${(exchangeBalance ?? '[UNDEFINED]')?.toString()}. ` +
`You need to deposit at least ${lackAmount.toString()} ${asset.name} into exchange contract`,
});
}
});
@@ -260,10 +260,10 @@ export default class BalanceGuard {
const exchangeBalance = this.balances?.[asset.name]?.exchange;
const available = exchangeBalance?.plus(approvedWalletBalance);
const issueMessage = `Not enough ${asset.name} on exchange + wallet balance. `
+ `Needed: ${itemsAmountSum.toString()}, available: ${available?.toString()} `
+ `(exchange: ${exchangeBalance?.toString()}, available (approved): ${approvedWalletBalance.toString()}).`
+ ` ${approveIsHelpful
const issueMessage = `Not enough ${asset.name} on exchange + wallet balance. ` +
`Needed: ${itemsAmountSum.toString()}, available: ${(available ?? '[UNDEFINED]')?.toString()} ` +
`(exchange: ${(exchangeBalance ?? '[UNKNOWN]')?.toString()}, available (approved): ${approvedWalletBalance.toString()}).` +
` ${approveIsHelpful
? `You need approve at least ${lackAmount.toString()} ${asset.name}`
: 'Approve is not helpful'}`;
if (approveIsHelpful) {
@@ -290,11 +290,13 @@ export default class BalanceGuard {
asset,
sources: ['exchange', 'wallet'],
fixes: [
...resetRequired ? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}] : [],
...resetRequired
? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}]
: [],
{
type: 'byApprove',
targetAmount: targetApprove,
@@ -351,8 +353,8 @@ export default class BalanceGuard {
const approveIsHelpful = approveAvailable.gte(lackAmount);
const targetApprove = approvedWalletBalance.plus(lackAmount);
const issueMessage = `Not enough ${asset.name} on wallet balance. `
+ `Needed: ${itemsAmountSum.toString()}, available (approved): ${approvedWalletBalance.toString()}. ${approveIsHelpful
const issueMessage = `Not enough ${asset.name} on wallet balance. ` +
`Needed: ${itemsAmountSum.toString()}, available (approved): ${approvedWalletBalance.toString()}. ${approveIsHelpful
? `You need approve at least ${lackAmount.toString()} ${asset.name}`
: 'Approve is not helpful'}`;
if (approveIsHelpful) {
@@ -379,11 +381,13 @@ export default class BalanceGuard {
asset,
sources: ['wallet'],
fixes: [
...resetRequired ? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}] : [],
...resetRequired
? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}]
: [],
{
type: 'byApprove',
targetAmount: targetApprove,
@@ -418,8 +422,8 @@ export default class BalanceGuard {
balanceIssues.push({
asset,
sources: ['wallet'],
message: `Not enough ${asset.name} on wallet balance. `
+ `You need to deposit at least ${lackAmount.toString()} ${asset.name} into wallet contract`,
message: `Not enough ${asset.name} on wallet balance. ` +
`You need to deposit at least ${lackAmount.toString()} ${asset.name} into wallet contract`,
});
}
});
@@ -428,7 +432,10 @@ export default class BalanceGuard {
const unfixed = await this.fixAllAutofixableBalanceIssues(balanceIssues);
if (unfixed.length > 0) throw new Error(`Balance issues: ${unfixed.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`);
} else if (balanceIssues.length > 0) {
throw new Error(`Balance issues (address ${walletAddress}): ${balanceIssues.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`);
throw new Error(
`Balance issues (address ${walletAddress}): ` +
`${balanceIssues.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`
);
}
}
}

View File

@@ -117,9 +117,13 @@ export default class Orion {
if (isValidChainId(networkCodeOrChainId)) {
unit = this.units[networkCodeOrChainId];
} else {
unit = this.unitsArray.find((unit) => unit.networkCode === networkCodeOrChainId);
unit = this.unitsArray.find((u) => u.networkCode === networkCodeOrChainId);
}
if (!unit) {
throw new Error(
`Invalid network code: ${networkCodeOrChainId}. ` +
`Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`);
}
if (!unit) throw new Error(`Invalid network code: ${networkCodeOrChainId}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`);
return unit;
}

View File

@@ -85,11 +85,11 @@ export default async function getSwapInfo({
if (options?.poolOnly) {
route = 'pool';
} else if (
swapExchanges !== undefined
&& poolExchangesList.length > 0
&& swapExchanges.length === 1
&& firstSwapExchange
&& poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
swapExchanges !== undefined &&
poolExchangesList.length > 0 &&
swapExchanges.length === 1 &&
firstSwapExchange &&
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
) {
route = 'pool';
} else {

View File

@@ -170,11 +170,11 @@ export default async function swapMarket({
options?.logger?.('Swap is through pool (because "poolOnly" option is true)');
route = 'pool';
} else if (
swapExchanges !== undefined
&& poolExchangesList.length > 0
&& swapExchanges.length === 1
&& firstSwapExchange
&& poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
swapExchanges !== undefined &&
poolExchangesList.length > 0 &&
swapExchanges.length === 1 &&
firstSwapExchange &&
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
) {
options?.logger?.(`Swap is through pool [via ${firstSwapExchange}] (detected by "exchanges" field)`);
route = 'pool';

View File

@@ -7,9 +7,9 @@ import { INTERNAL_ORION_PRECISION } from '../constants';
import { CFDOrder, SignedCFDOrder, SupportedChainId } from '../types';
import normalizeNumber from '../utils/normalizeNumber';
import getDomainData from './getDomainData';
import signCFDOrderPersonal from "./signCFDOrderPersonal";
import hashCFDOrder from "./hashCFDOrder";
import CFD_ORDER_TYPES from "../constants/cfdOrderTypes";
import signCFDOrderPersonal from './signCFDOrderPersonal';
import hashCFDOrder from './hashCFDOrder';
import CFD_ORDER_TYPES from '../constants/cfdOrderTypes';
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days

View File

@@ -133,7 +133,7 @@ type BufferLike =
| Uint8Array
| ArrayBuffer
| SharedArrayBuffer
| ReadonlyArray<any>
| ReadonlyArray<unknown>
| ReadonlyArray<number>
| { valueOf(): ArrayBuffer }
| { valueOf(): SharedArrayBuffer }
@@ -142,7 +142,6 @@ type BufferLike =
| { valueOf(): string }
| { [Symbol.toPrimitive](hint: string): string };
const isSubType = (subType: string): subType is keyof Subscription => Object.values(SubscriptionType).some((t) => t === subType);
class OrionAggregatorWS {
private ws: WebSocket | undefined;
@@ -483,7 +482,7 @@ class OrionAggregatorWS {
});
}
break;
case MessageType.CFD_ADDRESS_UPDATE: {
case MessageType.CFD_ADDRESS_UPDATE:
switch (json.k) { // message kind
case 'i': { // initial
const fullOrders = json.o
@@ -522,7 +521,6 @@ class OrionAggregatorWS {
default:
break;
}
}
break;
case MessageType.ADDRESS_UPDATE: {
const balances = json.b

View File

@@ -1,8 +1,8 @@
import { z } from "zod";
import { fullOrderSchema, orderUpdateSchema } from "./addressUpdateSchema";
import baseMessageSchema from "./baseMessageSchema";
import MessageType from "../MessageType";
import cfdBalancesSchema from "./cfdBalancesSchema";
import { z } from 'zod';
import { fullOrderSchema, orderUpdateSchema } from './addressUpdateSchema';
import baseMessageSchema from './baseMessageSchema';
import MessageType from '../MessageType';
import cfdBalancesSchema from './cfdBalancesSchema';
const baseCfdAddressUpdate = baseMessageSchema.extend({
id: z.string(),

View File

@@ -1,5 +1,5 @@
import { z } from 'zod';
import positionStatuses from "../../../../constants/positionStatuses";
import positionStatuses from '../../../../constants/positionStatuses';
const cfdBalanceSchema = z
.object({

View File

@@ -1,4 +1,4 @@
const arrayEquals = (a: unknown[], b: unknown[]) => a.length === b.length
&& a.every((value, index) => value === b[index]);
const arrayEquals = (a: unknown[], b: unknown[]) => a.length === b.length &&
a.every((value, index) => value === b[index]);
export default arrayEquals;

View File

@@ -1,11 +1,11 @@
const httpToWS = (url: string) => {
const parsedUrl = new URL(url);
if (parsedUrl.protocol === 'https:') {
parsedUrl.protocol = 'wss:';
} else if (parsedUrl.protocol === 'http:') {
parsedUrl.protocol = 'ws:';
}
return parsedUrl.toString();
const parsedUrl = new URL(url);
if (parsedUrl.protocol === 'https:') {
parsedUrl.protocol = 'wss:';
} else if (parsedUrl.protocol === 'http:') {
parsedUrl.protocol = 'ws:';
}
return parsedUrl.toString();
};
export default httpToWS;
export default httpToWS;

View File

@@ -9,6 +9,6 @@ export default function isNetworkCodeInEnvironment(networkCode: string, env: str
if (envNetworks === undefined) throw new Error('Env networks is undefined (isNetworkCodeInEnvironment)');
return Object.values(chains)
.some((chain) => chain.code.toLowerCase() === networkCode.toLowerCase()
&& chain.chainId in envNetworks);
.some((chain) => chain.code.toLowerCase() === networkCode.toLowerCase() &&
chain.chainId in envNetworks);
}