@cityofzion/blockchain-service 1.18.1 → 1.19.0
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/error.d.ts +4 -0
- package/dist/error.js +11 -0
- package/dist/functions.d.ts +2 -10
- package/dist/functions.js +12 -49
- package/dist/helpers/BSBigNumberHelper.d.ts +11 -0
- package/dist/helpers/BSBigNumberHelper.js +41 -0
- package/dist/helpers/BSTokenHelper.d.ts +21 -0
- package/dist/helpers/BSTokenHelper.js +39 -0
- package/dist/helpers/BSUtilsHelper.d.ts +10 -0
- package/dist/helpers/BSUtilsHelper.js +37 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/interfaces.d.ts +41 -4
- package/dist/services/exchange-data/FlamingoForthewinEDS.d.ts +0 -1
- package/dist/services/exchange-data/FlamingoForthewinEDS.js +5 -9
- package/package.json +10 -4
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSError = void 0;
|
|
4
|
+
class BSError extends Error {
|
|
5
|
+
constructor(message, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = 'BSError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BSError = BSError;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, UntilIndexRecord } from './interfaces';
|
|
1
|
+
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, IBSWithNeo3NeoXBridge, UntilIndexRecord } from './interfaces';
|
|
2
2
|
export declare function hasNameService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithNameService;
|
|
3
3
|
export declare function isClaimable<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSClaimable<BSName>;
|
|
4
4
|
export declare function isCalculableFee<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSCalculableFee<BSName>;
|
|
5
5
|
export declare function hasNft<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithNft;
|
|
6
6
|
export declare function hasExplorerService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithExplorerService;
|
|
7
7
|
export declare function hasLedger<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithLedger<BSName>;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function hasNeo3NeoXBridge<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & IBSWithNeo3NeoXBridge<BSName>;
|
|
9
9
|
/**
|
|
10
10
|
* @deprecated use `waitForAccountTransaction` instead
|
|
11
11
|
*/
|
|
@@ -19,11 +19,3 @@ export declare function waitForAccountTransaction<BSName extends string = string
|
|
|
19
19
|
export declare function fetchAccounts<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
20
20
|
export declare function generateAccount<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, untilIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
21
21
|
export declare function generateAccountForBlockchainService<BSName extends string = string>(blockchainServices: BlockchainService<BSName>[], getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
22
|
-
type NormalizedHashOptions = {
|
|
23
|
-
lowercase?: boolean;
|
|
24
|
-
};
|
|
25
|
-
export declare function normalizeHash(hash: string, options?: NormalizedHashOptions): string;
|
|
26
|
-
export declare function denormalizeHash(hash: string): string;
|
|
27
|
-
export declare function countDecimals(value: string | number): number;
|
|
28
|
-
export declare function formatNumber(value?: string | number, decimals?: number): string;
|
|
29
|
-
export {};
|
package/dist/functions.js
CHANGED
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.hasNeo3NeoXBridge = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
|
+
const BSUtilsHelper_1 = require("./helpers/BSUtilsHelper");
|
|
13
14
|
function hasNameService(service) {
|
|
14
15
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
16
|
}
|
|
@@ -34,10 +35,10 @@ function hasLedger(service) {
|
|
|
34
35
|
return 'ledgerService' in service;
|
|
35
36
|
}
|
|
36
37
|
exports.hasLedger = hasLedger;
|
|
37
|
-
function
|
|
38
|
-
return
|
|
38
|
+
function hasNeo3NeoXBridge(service) {
|
|
39
|
+
return 'neo3NeoXBridgeService' in service;
|
|
39
40
|
}
|
|
40
|
-
exports.
|
|
41
|
+
exports.hasNeo3NeoXBridge = hasNeo3NeoXBridge;
|
|
41
42
|
/**
|
|
42
43
|
* @deprecated use `waitForAccountTransaction` instead
|
|
43
44
|
*/
|
|
@@ -51,11 +52,11 @@ function waitForTransaction(service, txId) {
|
|
|
51
52
|
yield service.blockchainDataService.getTransaction(txId);
|
|
52
53
|
return true;
|
|
53
54
|
}
|
|
54
|
-
catch (
|
|
55
|
+
catch (_a) {
|
|
55
56
|
// Empty block
|
|
56
57
|
}
|
|
57
58
|
attempts++;
|
|
58
|
-
yield wait(waitMs);
|
|
59
|
+
yield BSUtilsHelper_1.BSUtilsHelper.wait(waitMs);
|
|
59
60
|
} while (attempts < maxAttempts);
|
|
60
61
|
return false;
|
|
61
62
|
});
|
|
@@ -66,14 +67,14 @@ function waitForAccountTransaction(params) {
|
|
|
66
67
|
const { address, maxAttempts = 10, service, txId } = params;
|
|
67
68
|
let attempts = 1;
|
|
68
69
|
do {
|
|
69
|
-
yield wait(60000);
|
|
70
|
+
yield BSUtilsHelper_1.BSUtilsHelper.wait(60000);
|
|
70
71
|
try {
|
|
71
72
|
const response = yield service.blockchainDataService.getTransactionsByAddress({ address });
|
|
72
73
|
const isTransactionConfirmed = response.transactions.some(transaction => transaction.hash === txId);
|
|
73
74
|
if (isTransactionConfirmed)
|
|
74
75
|
return true;
|
|
75
76
|
}
|
|
76
|
-
catch (
|
|
77
|
+
catch (_a) {
|
|
77
78
|
// Empty block
|
|
78
79
|
}
|
|
79
80
|
attempts++;
|
|
@@ -96,7 +97,7 @@ function fetchAccounts(blockchainServices, initialIndex, getAccountCallback) {
|
|
|
96
97
|
if (!transactions || transactions.length <= 0)
|
|
97
98
|
shouldBreak = true;
|
|
98
99
|
}
|
|
99
|
-
catch (
|
|
100
|
+
catch (_a) {
|
|
100
101
|
shouldBreak = true;
|
|
101
102
|
}
|
|
102
103
|
accounts.push(generatedAccount);
|
|
@@ -123,9 +124,9 @@ function generateAccountForBlockchainService(blockchainServices, getAccountCallb
|
|
|
123
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
125
|
const accountsByBlockchainService = new Map();
|
|
125
126
|
const promises = blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
var
|
|
127
|
+
var _a;
|
|
127
128
|
const firstAccount = yield getAccountCallback(service, 0);
|
|
128
|
-
const untilIndex = (
|
|
129
|
+
const untilIndex = (_a = untilIndexByBlockchainService === null || untilIndexByBlockchainService === void 0 ? void 0 : untilIndexByBlockchainService[service.name]) === null || _a === void 0 ? void 0 : _a[firstAccount.address];
|
|
129
130
|
if (untilIndex === undefined) {
|
|
130
131
|
const accounts = yield fetchAccounts(service, 1, getAccountCallback);
|
|
131
132
|
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
@@ -140,41 +141,3 @@ function generateAccountForBlockchainService(blockchainServices, getAccountCallb
|
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
143
|
exports.generateAccountForBlockchainService = generateAccountForBlockchainService;
|
|
143
|
-
function normalizeHash(hash, options) {
|
|
144
|
-
const { lowercase = true } = options !== null && options !== void 0 ? options : {};
|
|
145
|
-
hash = hash.replace('0x', '');
|
|
146
|
-
if (lowercase)
|
|
147
|
-
hash = hash.toLowerCase();
|
|
148
|
-
return hash;
|
|
149
|
-
}
|
|
150
|
-
exports.normalizeHash = normalizeHash;
|
|
151
|
-
function denormalizeHash(hash) {
|
|
152
|
-
return hash.startsWith('0x') ? hash : `0x${hash}`;
|
|
153
|
-
}
|
|
154
|
-
exports.denormalizeHash = denormalizeHash;
|
|
155
|
-
function countDecimals(value) {
|
|
156
|
-
var _b;
|
|
157
|
-
const [, decimals] = value.toString().split('.');
|
|
158
|
-
return (_b = decimals === null || decimals === void 0 ? void 0 : decimals.length) !== null && _b !== void 0 ? _b : 0;
|
|
159
|
-
}
|
|
160
|
-
exports.countDecimals = countDecimals;
|
|
161
|
-
function formatNumber(value, decimals = 0) {
|
|
162
|
-
if (!value)
|
|
163
|
-
return '0';
|
|
164
|
-
let newValue = typeof value === 'number' ? value.toFixed(decimals) : value;
|
|
165
|
-
newValue = newValue.replace(/,|\.\.|\.,/g, '.');
|
|
166
|
-
if (decimals === 0) {
|
|
167
|
-
newValue = newValue.split('.')[0];
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
newValue = newValue.replace(/[^\d.]/g, '');
|
|
171
|
-
const countedDecimals = countDecimals(newValue);
|
|
172
|
-
if (countedDecimals > decimals) {
|
|
173
|
-
newValue = newValue.slice(0, newValue.length - countedDecimals + decimals);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return newValue.replace(/\s|-/g, '').replace(/^([^.]*\.)(.*)$/, function (_a, b, c) {
|
|
177
|
-
return b + c.replace(/\./g, '');
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
exports.formatNumber = formatNumber;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
type FormatNumberOptions = {
|
|
3
|
+
decimals?: number;
|
|
4
|
+
};
|
|
5
|
+
export declare class BSBigNumberHelper {
|
|
6
|
+
static toDecimals(value: BigNumber, decimals?: number): string;
|
|
7
|
+
static fromNumber(value: string | number): BigNumber;
|
|
8
|
+
static fromDecimals(value: string | number, decimals?: number): BigNumber;
|
|
9
|
+
static format(value?: string | number | BigNumber, options?: FormatNumberOptions): string;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BSBigNumberHelper = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
class BSBigNumberHelper {
|
|
9
|
+
static toDecimals(value, decimals = 0) {
|
|
10
|
+
return new bignumber_js_1.default(value).shiftedBy(decimals).toString();
|
|
11
|
+
}
|
|
12
|
+
static fromNumber(value) {
|
|
13
|
+
return new bignumber_js_1.default(value);
|
|
14
|
+
}
|
|
15
|
+
static fromDecimals(value, decimals = 0) {
|
|
16
|
+
return new bignumber_js_1.default(value).shiftedBy(-decimals);
|
|
17
|
+
}
|
|
18
|
+
static format(value, options) {
|
|
19
|
+
const { decimals = 0 } = options || {};
|
|
20
|
+
if (!value)
|
|
21
|
+
return '0';
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
value = value.replace(/,|\.\.|\.,/g, '.').replace(/^([^.]*\.)(.*)$/, function (_a, b, c) {
|
|
24
|
+
return b + c.replace(/\./g, '');
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const bigValue = new bignumber_js_1.default(value);
|
|
29
|
+
if (bigValue.isNaN()) {
|
|
30
|
+
return '0';
|
|
31
|
+
}
|
|
32
|
+
const formattedValue = bigValue.decimalPlaces(decimals, bignumber_js_1.default.ROUND_DOWN);
|
|
33
|
+
return formattedValue.toFixed();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('Invalid value provided to format:', value);
|
|
37
|
+
return '0';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.BSBigNumberHelper = BSBigNumberHelper;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Token } from '../interfaces';
|
|
2
|
+
type TPredicateToken = {
|
|
3
|
+
hash: string;
|
|
4
|
+
symbol?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare class BSTokenHelper {
|
|
7
|
+
static predicate({ hash, symbol }: TPredicateToken): (params: TPredicateToken) => boolean;
|
|
8
|
+
static predicateByHash(tokenOrHash: string | {
|
|
9
|
+
hash: string;
|
|
10
|
+
}): (params: string | {
|
|
11
|
+
hash: string;
|
|
12
|
+
}) => boolean;
|
|
13
|
+
static predicateBySymbol(tokenOrSymbol: string | {
|
|
14
|
+
symbol: string;
|
|
15
|
+
}): (params: string | {
|
|
16
|
+
symbol: string;
|
|
17
|
+
}) => boolean;
|
|
18
|
+
static normalizeToken<T extends Token | Token[]>(token: T): T;
|
|
19
|
+
static normalizeHash(hash: string): string;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSTokenHelper = void 0;
|
|
4
|
+
class BSTokenHelper {
|
|
5
|
+
static predicate({ hash, symbol }) {
|
|
6
|
+
const normalizedHash = this.normalizeHash(hash);
|
|
7
|
+
return (params) => {
|
|
8
|
+
if (normalizedHash === this.normalizeHash(params.hash))
|
|
9
|
+
return true;
|
|
10
|
+
if (symbol && params.symbol && symbol.toLowerCase() === params.symbol.toLowerCase())
|
|
11
|
+
return true;
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
static predicateByHash(tokenOrHash) {
|
|
16
|
+
const hash = typeof tokenOrHash === 'string' ? tokenOrHash : tokenOrHash.hash;
|
|
17
|
+
const normalizedHash = this.normalizeHash(hash);
|
|
18
|
+
return (params) => normalizedHash === this.normalizeHash(typeof params === 'string' ? params : params.hash);
|
|
19
|
+
}
|
|
20
|
+
static predicateBySymbol(tokenOrSymbol) {
|
|
21
|
+
const symbol = typeof tokenOrSymbol === 'string' ? tokenOrSymbol : tokenOrSymbol.symbol;
|
|
22
|
+
const lowercaseSymbol = symbol.toLowerCase();
|
|
23
|
+
return (params) => {
|
|
24
|
+
const tokenSymbol = typeof params === 'string' ? params : params.symbol;
|
|
25
|
+
const lowercaseTokenSymbol = tokenSymbol.toLowerCase();
|
|
26
|
+
return lowercaseSymbol === lowercaseTokenSymbol;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
static normalizeToken(token) {
|
|
30
|
+
if (Array.isArray(token)) {
|
|
31
|
+
return token.map(item => (Object.assign(Object.assign({}, item), { hash: this.normalizeHash(item.hash) })));
|
|
32
|
+
}
|
|
33
|
+
return Object.assign(Object.assign({}, token), { hash: this.normalizeHash(token.hash) });
|
|
34
|
+
}
|
|
35
|
+
static normalizeHash(hash) {
|
|
36
|
+
return hash.startsWith('0x') ? hash : `0x${hash}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.BSTokenHelper = BSTokenHelper;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type RetryOptions = {
|
|
2
|
+
retries?: number;
|
|
3
|
+
delay?: number;
|
|
4
|
+
shouldRetry?: (error: any) => boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class BSUtilsHelper {
|
|
7
|
+
static wait(ms: number): Promise<unknown>;
|
|
8
|
+
static retry<T = any>(callback: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BSUtilsHelper = void 0;
|
|
13
|
+
class BSUtilsHelper {
|
|
14
|
+
static wait(ms) {
|
|
15
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
16
|
+
}
|
|
17
|
+
static retry(callback, options) {
|
|
18
|
+
const { retries = 50, delay = 100, shouldRetry } = options || {};
|
|
19
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
20
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
for (let i = 0; i < retries; i++) {
|
|
22
|
+
try {
|
|
23
|
+
const result = yield callback();
|
|
24
|
+
return resolve(result);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (shouldRetry && !shouldRetry(error)) {
|
|
28
|
+
return reject(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
yield this.wait(delay);
|
|
32
|
+
}
|
|
33
|
+
return reject(new Error('timeout'));
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.BSUtilsHelper = BSUtilsHelper;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export * from './constants/BSCommonConstants';
|
|
2
2
|
export * from './helpers/BSFullTransactionsByAddressHelper';
|
|
3
3
|
export * from './helpers/BSPromisesHelper';
|
|
4
|
+
export * from './helpers/BSBigNumberHelper';
|
|
5
|
+
export * from './helpers/BSTokenHelper';
|
|
6
|
+
export * from './helpers/BSUtilsHelper';
|
|
4
7
|
export * from './services/exchange-data/CryptoCompareEDS';
|
|
5
8
|
export * from './services/exchange-data/FlamingoForthewinEDS';
|
|
6
9
|
export * from './BSAggregator';
|
|
7
10
|
export * from './functions';
|
|
8
11
|
export * from './interfaces';
|
|
12
|
+
export * from './error';
|
package/dist/index.js
CHANGED
|
@@ -17,8 +17,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./constants/BSCommonConstants"), exports);
|
|
18
18
|
__exportStar(require("./helpers/BSFullTransactionsByAddressHelper"), exports);
|
|
19
19
|
__exportStar(require("./helpers/BSPromisesHelper"), exports);
|
|
20
|
+
__exportStar(require("./helpers/BSBigNumberHelper"), exports);
|
|
21
|
+
__exportStar(require("./helpers/BSTokenHelper"), exports);
|
|
22
|
+
__exportStar(require("./helpers/BSUtilsHelper"), exports);
|
|
20
23
|
__exportStar(require("./services/exchange-data/CryptoCompareEDS"), exports);
|
|
21
24
|
__exportStar(require("./services/exchange-data/FlamingoForthewinEDS"), exports);
|
|
22
25
|
__exportStar(require("./BSAggregator"), exports);
|
|
23
26
|
__exportStar(require("./functions"), exports);
|
|
24
27
|
__exportStar(require("./interfaces"), exports);
|
|
28
|
+
__exportStar(require("./error"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -76,6 +76,9 @@ export interface BSWithLedger<BSName extends string = string> {
|
|
|
76
76
|
ledgerService: LedgerService<BSName>;
|
|
77
77
|
generateAccountFromPublicKey(publicKey: string): Account<BSName>;
|
|
78
78
|
}
|
|
79
|
+
export interface IBSWithNeo3NeoXBridge<BSName extends string = string> {
|
|
80
|
+
neo3NeoXBridgeService: INeo3NeoXBridgeService<BSName>;
|
|
81
|
+
}
|
|
79
82
|
export type TransactionNotificationTypedResponse = {
|
|
80
83
|
type: string;
|
|
81
84
|
value?: string;
|
|
@@ -137,7 +140,7 @@ export type ExportTransactionsByAddressParams = {
|
|
|
137
140
|
};
|
|
138
141
|
export type FullTransactionNftEvent = {
|
|
139
142
|
eventType: 'nft';
|
|
140
|
-
amount
|
|
143
|
+
amount?: string;
|
|
141
144
|
methodName: string;
|
|
142
145
|
hash: string;
|
|
143
146
|
hashUrl?: string;
|
|
@@ -154,7 +157,7 @@ export type FullTransactionNftEvent = {
|
|
|
154
157
|
};
|
|
155
158
|
export type FullTransactionAssetEvent = {
|
|
156
159
|
eventType: 'token';
|
|
157
|
-
amount
|
|
160
|
+
amount?: string;
|
|
158
161
|
methodName: string;
|
|
159
162
|
hash: string;
|
|
160
163
|
hashUrl?: string;
|
|
@@ -172,8 +175,8 @@ export type FullTransactionsItem = {
|
|
|
172
175
|
date: string;
|
|
173
176
|
invocationCount: number;
|
|
174
177
|
notificationCount: number;
|
|
175
|
-
networkFeeAmount
|
|
176
|
-
systemFeeAmount
|
|
178
|
+
networkFeeAmount?: string;
|
|
179
|
+
systemFeeAmount?: string;
|
|
177
180
|
events: (FullTransactionAssetEvent | FullTransactionNftEvent)[];
|
|
178
181
|
};
|
|
179
182
|
export type FullTransactionsByAddressResponse = {
|
|
@@ -359,3 +362,37 @@ export interface SwapService<BSName extends string = string> {
|
|
|
359
362
|
swap(): Promise<SwapServiceSwapResult>;
|
|
360
363
|
calculateFee(): Promise<string>;
|
|
361
364
|
}
|
|
365
|
+
export type TNeo3NeoXBridgeServiceCalculateMaxAmountParams<BSName extends string> = {
|
|
366
|
+
account: Account<BSName>;
|
|
367
|
+
receiverAddress: string;
|
|
368
|
+
token: Token;
|
|
369
|
+
balances: BalanceResponse[];
|
|
370
|
+
};
|
|
371
|
+
export type TNeo3NeoXBridgeServiceValidatedInputs = {
|
|
372
|
+
amount: string;
|
|
373
|
+
receiveAmount: string;
|
|
374
|
+
token: Token;
|
|
375
|
+
};
|
|
376
|
+
export type TNeo3NeoXBridgeServiceBridgeParam<BSName extends string> = {
|
|
377
|
+
account: Account<BSName>;
|
|
378
|
+
receiverAddress: string;
|
|
379
|
+
validatedInputs: TNeo3NeoXBridgeServiceValidatedInputs;
|
|
380
|
+
};
|
|
381
|
+
export type TNeo3NeoXBridgeServiceValidateInputParams<BSName extends string> = {
|
|
382
|
+
account: Account<BSName>;
|
|
383
|
+
receiverAddress: string;
|
|
384
|
+
amount: string;
|
|
385
|
+
token: Token;
|
|
386
|
+
balances: BalanceResponse[];
|
|
387
|
+
};
|
|
388
|
+
export type TNeo3NeoXBridgeServiceWaitParams = {
|
|
389
|
+
transactionHash: string;
|
|
390
|
+
validatedInputs: TNeo3NeoXBridgeServiceValidatedInputs;
|
|
391
|
+
};
|
|
392
|
+
export interface INeo3NeoXBridgeService<BSName extends string = string> {
|
|
393
|
+
calculateMaxAmount(params: TNeo3NeoXBridgeServiceCalculateMaxAmountParams<BSName>): Promise<string>;
|
|
394
|
+
calculateFee(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
|
|
395
|
+
bridge(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
|
|
396
|
+
validateInputs(params: TNeo3NeoXBridgeServiceValidateInputParams<BSName>): Promise<TNeo3NeoXBridgeServiceValidatedInputs>;
|
|
397
|
+
wait(params: TNeo3NeoXBridgeServiceWaitParams): Promise<boolean>;
|
|
398
|
+
}
|
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.FlamingoForthewinEDS = void 0;
|
|
22
22
|
const axios_1 = __importDefault(require("axios"));
|
|
23
23
|
const CryptoCompareEDS_1 = require("./CryptoCompareEDS");
|
|
24
|
-
const
|
|
24
|
+
const BSTokenHelper_1 = require("../../helpers/BSTokenHelper");
|
|
25
25
|
class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
26
26
|
constructor() {
|
|
27
27
|
super();
|
|
@@ -33,13 +33,13 @@ class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
|
33
33
|
const { data: flamingoData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_flamingoAxiosInstance, "f").get('/live-data/prices/latest');
|
|
34
34
|
const prices = [];
|
|
35
35
|
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO');
|
|
36
|
-
if (neoToken && !flamingoData.find(
|
|
36
|
+
if (neoToken && !flamingoData.find(BSTokenHelper_1.BSTokenHelper.predicate(neoToken)))
|
|
37
37
|
flamingoData.forEach(item => {
|
|
38
38
|
if (item.symbol === 'bNEO')
|
|
39
39
|
flamingoData.push(Object.assign(Object.assign({}, item), { symbol: neoToken.symbol, hash: neoToken.hash }));
|
|
40
40
|
});
|
|
41
41
|
flamingoData.forEach(item => {
|
|
42
|
-
const token = tokens.find(
|
|
42
|
+
const token = tokens.find(BSTokenHelper_1.BSTokenHelper.predicate(item));
|
|
43
43
|
if (!token)
|
|
44
44
|
return;
|
|
45
45
|
prices.push({ usdPrice: item.usd_price, token });
|
|
@@ -47,10 +47,10 @@ class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
|
47
47
|
if (tokens.length > prices.length) {
|
|
48
48
|
const { data: forthewinData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_forthewinAxiosInstance, "f").get('/mainnet/prices');
|
|
49
49
|
Object.entries(forthewinData).forEach(([hash, usdPrice]) => {
|
|
50
|
-
const hasPrice = !!prices.find(({ token }) =>
|
|
50
|
+
const hasPrice = !!prices.find(({ token }) => BSTokenHelper_1.BSTokenHelper.predicate({ hash })(token));
|
|
51
51
|
if (hasPrice)
|
|
52
52
|
return;
|
|
53
|
-
const foundToken = tokens.find(
|
|
53
|
+
const foundToken = tokens.find(BSTokenHelper_1.BSTokenHelper.predicate({ hash }));
|
|
54
54
|
if (!foundToken)
|
|
55
55
|
return;
|
|
56
56
|
prices.push({ usdPrice, token: foundToken });
|
|
@@ -59,10 +59,6 @@ class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
|
59
59
|
return prices;
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
predicateToken({ hash, symbol }) {
|
|
63
|
-
const normalizedHash = (0, functions_1.normalizeHash)(hash);
|
|
64
|
-
return (params) => normalizedHash === (0, functions_1.normalizeHash)(params.hash) || (!!symbol && !!params.symbol && symbol === params.symbol);
|
|
65
|
-
}
|
|
66
62
|
}
|
|
67
63
|
exports.FlamingoForthewinEDS = FlamingoForthewinEDS;
|
|
68
64
|
_FlamingoForthewinEDS_flamingoAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_forthewinAxiosInstance = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/blockchain-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -11,20 +11,26 @@
|
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "~20.2.5",
|
|
14
|
+
"@types/jest": "29.5.3",
|
|
14
15
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
15
16
|
"@typescript-eslint/parser": "^6.5.0",
|
|
17
|
+
"dotenv": "16.3.1",
|
|
16
18
|
"eslint": "^8.48.0",
|
|
17
19
|
"ts-node": "10.9.1",
|
|
18
20
|
"typescript": "4.9.5",
|
|
19
|
-
"typed-emitter": "~2.1.0"
|
|
21
|
+
"typed-emitter": "~2.1.0",
|
|
22
|
+
"jest": "29.6.2",
|
|
23
|
+
"ts-jest": "29.1.1"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
26
|
"@ledgerhq/hw-transport": "~6.30.5",
|
|
23
27
|
"axios": "1.8.2",
|
|
24
|
-
"date-fns": "~4.1.0"
|
|
28
|
+
"date-fns": "~4.1.0",
|
|
29
|
+
"bignumber.js": "~9.3.0"
|
|
25
30
|
},
|
|
26
31
|
"scripts": {
|
|
27
|
-
"build": "tsc",
|
|
32
|
+
"build": "tsc --project tsconfig.build.json",
|
|
33
|
+
"test": "jest --config jest.config.ts",
|
|
28
34
|
"lint": "eslint .",
|
|
29
35
|
"format": "eslint --fix"
|
|
30
36
|
}
|