@cityofzion/bs-multichain 0.0.1 → 1.0.2
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/LICENSE +674 -0
- package/dist/BSAggregator.d.ts +14 -0
- package/dist/BSAggregator.js +65 -0
- package/dist/features/bridge/Neo3NeoXBridgeOrchestrator.d.ts +21 -0
- package/dist/features/bridge/Neo3NeoXBridgeOrchestrator.js +360 -0
- package/dist/features/bridge/index.d.ts +2 -0
- package/dist/features/bridge/index.js +18 -0
- package/dist/features/bridge/types.d.ts +6 -0
- package/dist/features/bridge/types.js +2 -0
- package/dist/features/swap/SimpleSwapApi.d.ts +23 -0
- package/dist/features/swap/SimpleSwapApi.js +258 -0
- package/dist/features/swap/SimpleSwapOrchestrator.d.ts +17 -0
- package/dist/features/swap/SimpleSwapOrchestrator.js +441 -0
- package/dist/features/swap/SimpleSwapService.d.ts +6 -0
- package/dist/features/swap/SimpleSwapService.js +56 -0
- package/dist/features/swap/index.d.ts +4 -0
- package/dist/features/swap/index.js +20 -0
- package/dist/features/swap/types.d.ts +64 -0
- package/dist/features/swap/types.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/package.json +38 -11
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Account, BlockchainService, UntilIndexRecord } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare class BSAggregator<BSName extends string> {
|
|
3
|
+
#private;
|
|
4
|
+
readonly blockchainServicesByName: Record<BSName, BlockchainService<BSName>>;
|
|
5
|
+
constructor(blockchainServices: BlockchainService<BSName>[]);
|
|
6
|
+
validateAddressAllBlockchains(address: string): boolean;
|
|
7
|
+
validateTextAllBlockchains(text: string): boolean;
|
|
8
|
+
validateKeyAllBlockchains(wif: string): boolean;
|
|
9
|
+
validateEncryptedAllBlockchains(keyOrJson: string): boolean;
|
|
10
|
+
getBlockchainNameByAddress(address: string): BSName[];
|
|
11
|
+
getBlockchainNameByKey(wif: string): BSName[];
|
|
12
|
+
getBlockchainNameByEncrypted(keyOrJson: string): BSName[];
|
|
13
|
+
generateAccountsFromMnemonic(mnemonic: string, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _BSAggregator_blockchainServices;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.BSAggregator = void 0;
|
|
25
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
26
|
+
class BSAggregator {
|
|
27
|
+
constructor(blockchainServices) {
|
|
28
|
+
_BSAggregator_blockchainServices.set(this, void 0);
|
|
29
|
+
__classPrivateFieldSet(this, _BSAggregator_blockchainServices, blockchainServices, "f");
|
|
30
|
+
this.blockchainServicesByName = blockchainServices.reduce((acc, service) => {
|
|
31
|
+
acc[service.name] = service;
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
validateAddressAllBlockchains(address) {
|
|
36
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateAddress(address));
|
|
37
|
+
}
|
|
38
|
+
validateTextAllBlockchains(text) {
|
|
39
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => [bs.validateAddress(text), bs.validateEncrypted(text), bs.validateKey(text)].some(it => it === true));
|
|
40
|
+
}
|
|
41
|
+
validateKeyAllBlockchains(wif) {
|
|
42
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateKey(wif));
|
|
43
|
+
}
|
|
44
|
+
validateEncryptedAllBlockchains(keyOrJson) {
|
|
45
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").some(bs => bs.validateEncrypted(keyOrJson));
|
|
46
|
+
}
|
|
47
|
+
getBlockchainNameByAddress(address) {
|
|
48
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateAddress(address)).map(bs => bs.name);
|
|
49
|
+
}
|
|
50
|
+
getBlockchainNameByKey(wif) {
|
|
51
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateKey(wif)).map(bs => bs.name);
|
|
52
|
+
}
|
|
53
|
+
getBlockchainNameByEncrypted(keyOrJson) {
|
|
54
|
+
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateEncrypted(keyOrJson)).map(bs => bs.name);
|
|
55
|
+
}
|
|
56
|
+
generateAccountsFromMnemonic(mnemonic, untilIndexByBlockchainService) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return (0, blockchain_service_1.generateAccountForBlockchainService)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return service.generateAccountFromMnemonic(mnemonic, index);
|
|
60
|
+
}), untilIndexByBlockchainService);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.BSAggregator = BSAggregator;
|
|
65
|
+
_BSAggregator_blockchainServices = new WeakMap();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Account, BalanceResponse, IBridgeOrchestrator, TBridgeOrchestratorEvents, TBridgeToken } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSNeo3 } from '@cityofzion/bs-neo3';
|
|
3
|
+
import { BSNeoX } from '@cityofzion/bs-neox';
|
|
4
|
+
import TypedEmitter from 'typed-emitter';
|
|
5
|
+
import { TNeo3NeoXBridgeOrchestratorInitParams } from './types';
|
|
6
|
+
export declare class Neo3NeoXBridgeOrchestrator<BSName extends string> implements IBridgeOrchestrator<BSName> {
|
|
7
|
+
#private;
|
|
8
|
+
eventEmitter: TypedEmitter<TBridgeOrchestratorEvents<BSName>>;
|
|
9
|
+
fromService: BSNeo3<BSName> | BSNeoX<BSName>;
|
|
10
|
+
toService: BSNeo3<BSName> | BSNeoX<BSName>;
|
|
11
|
+
constructor(params: TNeo3NeoXBridgeOrchestratorInitParams<BSName>);
|
|
12
|
+
init(): Promise<void>;
|
|
13
|
+
switchTokens(): Promise<void>;
|
|
14
|
+
setTokenToUse(token: TBridgeToken | null): Promise<void>;
|
|
15
|
+
setAccountToUse(account: Account<BSName> | null): Promise<void>;
|
|
16
|
+
setAddressToReceive(address: string | null): Promise<void>;
|
|
17
|
+
setBalances(balances: BalanceResponse[] | null): Promise<void>;
|
|
18
|
+
setAmountToUse(amount: string | null): Promise<void>;
|
|
19
|
+
bridge(): Promise<string>;
|
|
20
|
+
wait(): Promise<boolean>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,360 @@
|
|
|
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
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
20
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _Neo3NeoXBridgeOrchestrator_instances, _Neo3NeoXBridgeOrchestrator_balances, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout, _Neo3NeoXBridgeOrchestrator_transactionHash, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, _Neo3NeoXBridgeOrchestrator_internalTokenToUse, _Neo3NeoXBridgeOrchestrator_internalAccountToUse, _Neo3NeoXBridgeOrchestrator_internalAmountToUse, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax, _Neo3NeoXBridgeOrchestrator_internalTokenToReceive, _Neo3NeoXBridgeOrchestrator_internalAddressToReceive, _Neo3NeoXBridgeOrchestrator_internalAmountToReceive, _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance, _Neo3NeoXBridgeOrchestrator_internalBridgeFee, _Neo3NeoXBridgeOrchestrator_availableTokensToUse_get, _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set, _Neo3NeoXBridgeOrchestrator_tokenToUse_get, _Neo3NeoXBridgeOrchestrator_tokenToUse_set, _Neo3NeoXBridgeOrchestrator_accountToUse_get, _Neo3NeoXBridgeOrchestrator_accountToUse_set, _Neo3NeoXBridgeOrchestrator_amountToUse_get, _Neo3NeoXBridgeOrchestrator_amountToUse_set, _Neo3NeoXBridgeOrchestrator_amountToUseMin_get, _Neo3NeoXBridgeOrchestrator_amountToUseMin_set, _Neo3NeoXBridgeOrchestrator_amountToUseMax_get, _Neo3NeoXBridgeOrchestrator_amountToUseMax_set, _Neo3NeoXBridgeOrchestrator_tokenToReceive_get, _Neo3NeoXBridgeOrchestrator_tokenToReceive_set, _Neo3NeoXBridgeOrchestrator_addressToReceive_get, _Neo3NeoXBridgeOrchestrator_addressToReceive_set, _Neo3NeoXBridgeOrchestrator_amountToReceive_get, _Neo3NeoXBridgeOrchestrator_amountToReceive_set, _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_get, _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set, _Neo3NeoXBridgeOrchestrator_bridgeFee_get, _Neo3NeoXBridgeOrchestrator_bridgeFee_set, _Neo3NeoXBridgeOrchestrator_treatError;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Neo3NeoXBridgeOrchestrator = void 0;
|
|
28
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
29
|
+
const events_1 = __importDefault(require("events"));
|
|
30
|
+
class Neo3NeoXBridgeOrchestrator {
|
|
31
|
+
constructor(params) {
|
|
32
|
+
_Neo3NeoXBridgeOrchestrator_instances.add(this);
|
|
33
|
+
_Neo3NeoXBridgeOrchestrator_balances.set(this, null);
|
|
34
|
+
_Neo3NeoXBridgeOrchestrator_feeTokenBalance.set(this, null);
|
|
35
|
+
_Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout.set(this, undefined);
|
|
36
|
+
_Neo3NeoXBridgeOrchestrator_transactionHash.set(this, null);
|
|
37
|
+
_Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse.set(this, { value: null, loading: false, error: null });
|
|
38
|
+
_Neo3NeoXBridgeOrchestrator_internalTokenToUse.set(this, { value: null, loading: false, error: null });
|
|
39
|
+
_Neo3NeoXBridgeOrchestrator_internalAccountToUse.set(this, { value: null, loading: false, error: null });
|
|
40
|
+
_Neo3NeoXBridgeOrchestrator_internalAmountToUse.set(this, { value: null, valid: null, loading: false, error: null });
|
|
41
|
+
_Neo3NeoXBridgeOrchestrator_internalAmountToUseMin.set(this, { value: null, loading: false, error: null });
|
|
42
|
+
_Neo3NeoXBridgeOrchestrator_internalAmountToUseMax.set(this, { value: null, loading: false, error: null });
|
|
43
|
+
_Neo3NeoXBridgeOrchestrator_internalTokenToReceive.set(this, { value: null, loading: false, error: null });
|
|
44
|
+
_Neo3NeoXBridgeOrchestrator_internalAddressToReceive.set(this, { value: null, valid: null, loading: false, error: null });
|
|
45
|
+
_Neo3NeoXBridgeOrchestrator_internalAmountToReceive.set(this, { value: null, loading: false, error: null });
|
|
46
|
+
_Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance.set(this, { value: null, loading: false, error: null });
|
|
47
|
+
_Neo3NeoXBridgeOrchestrator_internalBridgeFee.set(this, { value: null, loading: false, error: null });
|
|
48
|
+
this.eventEmitter = new events_1.default();
|
|
49
|
+
this.fromService = params.neo3Service;
|
|
50
|
+
this.toService = params.neoXService;
|
|
51
|
+
}
|
|
52
|
+
init() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
55
|
+
value: this.fromService.neo3NeoXBridgeService.tokens,
|
|
56
|
+
}, "a", _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set);
|
|
57
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_set);
|
|
58
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, valid: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_set);
|
|
59
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, valid: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
60
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
61
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
62
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_set);
|
|
63
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_set);
|
|
64
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_tokenToReceive_set);
|
|
65
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set);
|
|
66
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
67
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, null, "f");
|
|
68
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_balances, null, "f");
|
|
69
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, null, "f");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
switchTokens() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const fromService = this.fromService;
|
|
75
|
+
const toService = this.toService;
|
|
76
|
+
this.fromService = toService;
|
|
77
|
+
this.toService = fromService;
|
|
78
|
+
const tokenToReceive = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToReceive_get).value;
|
|
79
|
+
yield this.init();
|
|
80
|
+
yield this.setTokenToUse(tokenToReceive);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
setTokenToUse(token) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
let tokenToReceive;
|
|
86
|
+
try {
|
|
87
|
+
if (!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_availableTokensToUse_get).value)
|
|
88
|
+
throw new blockchain_service_1.BSError('No available tokens to use', 'NO_AVAILABLE_TOKENS');
|
|
89
|
+
if (token) {
|
|
90
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value && blockchain_service_1.BSTokenHelper.predicate(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value)(token))
|
|
91
|
+
return;
|
|
92
|
+
if (!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_availableTokensToUse_get).value.some(blockchain_service_1.BSTokenHelper.predicate(token)))
|
|
93
|
+
throw new blockchain_service_1.BSError('You are trying to use a token that is not available', 'TOKEN_NOT_AVAILABLE');
|
|
94
|
+
tokenToReceive = this.toService.neo3NeoXBridgeService.tokens.find(item => token.multichainId === item.multichainId);
|
|
95
|
+
if (!tokenToReceive)
|
|
96
|
+
throw new blockchain_service_1.BSError('Pair token not found', 'PAIR_TOKEN_NOT_FOUND');
|
|
97
|
+
}
|
|
98
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: tokenToReceive !== null && tokenToReceive !== void 0 ? tokenToReceive : null, error: null }, "a", _Neo3NeoXBridgeOrchestrator_tokenToReceive_set);
|
|
99
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: token, error: null }, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_set);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
|
|
103
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_set);
|
|
104
|
+
throw treatedError;
|
|
105
|
+
}
|
|
106
|
+
yield Promise.allSettled([this.setBalances(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_balances, "f")), this.setAmountToUse(null)]);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
setAccountToUse(account) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
try {
|
|
112
|
+
if (account) {
|
|
113
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value && blockchain_service_1.BSAccountHelper.predicate(account)(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value))
|
|
114
|
+
return;
|
|
115
|
+
if (this.fromService.name !== account.blockchain)
|
|
116
|
+
throw new blockchain_service_1.BSError('You are trying to use an account that is not compatible with the selected token', 'ACCOUNT_NOT_COMPATIBLE_WITH_TOKEN');
|
|
117
|
+
}
|
|
118
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: account, error: null }, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_set);
|
|
119
|
+
yield Promise.allSettled([this.setBalances(null), this.setAmountToUse(null)]);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
|
|
123
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_set);
|
|
124
|
+
throw treatedError;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
setAddressToReceive(address) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
131
|
+
value: address,
|
|
132
|
+
loading: !!address,
|
|
133
|
+
valid: null,
|
|
134
|
+
error: null,
|
|
135
|
+
}, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_set);
|
|
136
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout, "f") !== null)
|
|
137
|
+
clearTimeout(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout, "f"));
|
|
138
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout, setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_get).value) {
|
|
140
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
141
|
+
valid: this.toService.validateAddress(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_get).value),
|
|
142
|
+
loading: false,
|
|
143
|
+
}, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_set);
|
|
144
|
+
}
|
|
145
|
+
}), 1500), "f");
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
setBalances(balances) {
|
|
149
|
+
var _a;
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_balances, balances, "f");
|
|
152
|
+
const tokenToUseBalance = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value && balances
|
|
153
|
+
? balances === null || balances === void 0 ? void 0 : balances.find(item => blockchain_service_1.BSTokenHelper.predicateByHash(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value)(item.token))
|
|
154
|
+
: null;
|
|
155
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
156
|
+
value: tokenToUseBalance,
|
|
157
|
+
}, "a", _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set);
|
|
158
|
+
const feeTokenBalance = balances
|
|
159
|
+
? balances === null || balances === void 0 ? void 0 : balances.find(item => blockchain_service_1.BSTokenHelper.predicateByHash(this.fromService.feeToken)(item.token))
|
|
160
|
+
: null;
|
|
161
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, feeTokenBalance, "f");
|
|
162
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
163
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
164
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
165
|
+
try {
|
|
166
|
+
if (tokenToUseBalance === null || !__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value)
|
|
167
|
+
throw new blockchain_service_1.BSError('Token to use is not set', 'TOKEN_NOT_SET');
|
|
168
|
+
const constants = yield this.fromService.neo3NeoXBridgeService.getBridgeConstants(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
|
|
169
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeMinAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
170
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeFee }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
171
|
+
const bridgeMaxAmountBn = blockchain_service_1.BSBigNumberHelper.fromNumber(constants.bridgeMaxAmount);
|
|
172
|
+
const tokenBalanceAmountBn = blockchain_service_1.BSBigNumberHelper.fromNumber((_a = tokenToUseBalance === null || tokenToUseBalance === void 0 ? void 0 : tokenToUseBalance.amount) !== null && _a !== void 0 ? _a : 0);
|
|
173
|
+
const max = Math.max(0, Math.min(bridgeMaxAmountBn.toNumber(), tokenBalanceAmountBn.minus(constants.bridgeFee).toNumber()));
|
|
174
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: blockchain_service_1.BSBigNumberHelper.format(max, { decimals: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value.decimals }) }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
|
|
178
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
179
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
180
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
181
|
+
throw treatedError;
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
|
|
185
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
|
|
186
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
setAmountToUse(amount) {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
const formattedAmount = amount && __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value
|
|
194
|
+
? blockchain_service_1.BSBigNumberHelper.format(amount, { decimals: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value.decimals })
|
|
195
|
+
: amount;
|
|
196
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
197
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_set);
|
|
198
|
+
if (formattedAmount === null) {
|
|
199
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value === null ||
|
|
204
|
+
__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_get).value === null ||
|
|
205
|
+
__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_get).value === null ||
|
|
206
|
+
__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value === null ||
|
|
207
|
+
__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value === null ||
|
|
208
|
+
__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, "f") === null) {
|
|
209
|
+
throw new blockchain_service_1.BSError('Required parameters are not set', 'REQUIRED_PARAMETERS_NOT_SET');
|
|
210
|
+
}
|
|
211
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
212
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
213
|
+
const amountToUseBn = blockchain_service_1.BSBigNumberHelper.fromNumber(formattedAmount);
|
|
214
|
+
if (amountToUseBn.isLessThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_get).value) ||
|
|
215
|
+
amountToUseBn.isGreaterThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_get).value)) {
|
|
216
|
+
throw new blockchain_service_1.BSError('Amount is out of range', 'AMOUNT_OUT_OF_RANGE');
|
|
217
|
+
}
|
|
218
|
+
const approvalFee = yield this.fromService.neo3NeoXBridgeService
|
|
219
|
+
.getApprovalFee({
|
|
220
|
+
account: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value,
|
|
221
|
+
token: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value,
|
|
222
|
+
amount: formattedAmount,
|
|
223
|
+
})
|
|
224
|
+
.then(fee => fee)
|
|
225
|
+
.catch(() => '0');
|
|
226
|
+
const newBridgeFee = blockchain_service_1.BSBigNumberHelper.fromNumber(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value).plus(approvalFee);
|
|
227
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
|
|
228
|
+
value: blockchain_service_1.BSBigNumberHelper.format(newBridgeFee, { decimals: this.fromService.feeToken.decimals }),
|
|
229
|
+
}, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
230
|
+
const isFeeToken = blockchain_service_1.BSTokenHelper.predicateByHash(this.fromService.feeToken)(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
|
|
231
|
+
if (newBridgeFee.plus(isFeeToken ? amountToUseBn : 0).isGreaterThan((_b = (_a = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, "f")) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0)) {
|
|
232
|
+
throw new blockchain_service_1.BSError('You do not have enough fee token balance to cover the bridge fee', 'INSUFFICIENT_FEE_TOKEN_BALANCE');
|
|
233
|
+
}
|
|
234
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: true }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
|
|
238
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: false, error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
239
|
+
throw treatedError;
|
|
240
|
+
}
|
|
241
|
+
finally {
|
|
242
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
|
|
243
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
bridge() {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
if (!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value ||
|
|
250
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value ||
|
|
251
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToReceive_get).value ||
|
|
252
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_get).valid ||
|
|
253
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_get).value ||
|
|
254
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_get).value ||
|
|
255
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_get).value ||
|
|
256
|
+
!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value) {
|
|
257
|
+
throw new blockchain_service_1.BSError('Required parameters are not set for bridging', 'BRIDGE_NOT_READY');
|
|
258
|
+
}
|
|
259
|
+
const transaction = yield this.fromService.neo3NeoXBridgeService.bridge({
|
|
260
|
+
account: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value,
|
|
261
|
+
token: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value,
|
|
262
|
+
amount: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_get).value,
|
|
263
|
+
receiverAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_get).value,
|
|
264
|
+
bridgeFee: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value,
|
|
265
|
+
});
|
|
266
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, transaction, "f");
|
|
267
|
+
return transaction;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
wait() {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, "f") === null || __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value === null) {
|
|
273
|
+
throw new blockchain_service_1.BSError('You need to bridge before', 'BRIDGE_NOT_EXECUTED');
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
const transactionHash = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, "f");
|
|
277
|
+
const token = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value;
|
|
278
|
+
const nonce = yield blockchain_service_1.BSUtilsHelper.retry(() => this.fromService.neo3NeoXBridgeService.getNonce({
|
|
279
|
+
token,
|
|
280
|
+
transactionHash,
|
|
281
|
+
}), {
|
|
282
|
+
retries: 10,
|
|
283
|
+
delay: 30000,
|
|
284
|
+
});
|
|
285
|
+
if (!nonce) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
yield blockchain_service_1.BSUtilsHelper.retry(() => this.toService.neo3NeoXBridgeService.getTransactionHashByNonce({ nonce, token }), {
|
|
289
|
+
retries: 10,
|
|
290
|
+
delay: 30000,
|
|
291
|
+
});
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
catch (_a) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.Neo3NeoXBridgeOrchestrator = Neo3NeoXBridgeOrchestrator;
|
|
301
|
+
_Neo3NeoXBridgeOrchestrator_balances = new WeakMap(), _Neo3NeoXBridgeOrchestrator_feeTokenBalance = new WeakMap(), _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout = new WeakMap(), _Neo3NeoXBridgeOrchestrator_transactionHash = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalTokenToUse = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAccountToUse = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAmountToUse = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalTokenToReceive = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAddressToReceive = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalAmountToReceive = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance = new WeakMap(), _Neo3NeoXBridgeOrchestrator_internalBridgeFee = new WeakMap(), _Neo3NeoXBridgeOrchestrator_instances = new WeakSet(), _Neo3NeoXBridgeOrchestrator_availableTokensToUse_get = function _Neo3NeoXBridgeOrchestrator_availableTokensToUse_get() {
|
|
302
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, "f");
|
|
303
|
+
}, _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set = function _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set(value) {
|
|
304
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, "f")), value), "f");
|
|
305
|
+
this.eventEmitter.emit('availableTokensToUse', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, "f"));
|
|
306
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToUse_get = function _Neo3NeoXBridgeOrchestrator_tokenToUse_get() {
|
|
307
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUse, "f");
|
|
308
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToUse_set = function _Neo3NeoXBridgeOrchestrator_tokenToUse_set(value) {
|
|
309
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUse, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUse, "f")), value), "f");
|
|
310
|
+
this.eventEmitter.emit('tokenToUse', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUse, "f"));
|
|
311
|
+
}, _Neo3NeoXBridgeOrchestrator_accountToUse_get = function _Neo3NeoXBridgeOrchestrator_accountToUse_get() {
|
|
312
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAccountToUse, "f");
|
|
313
|
+
}, _Neo3NeoXBridgeOrchestrator_accountToUse_set = function _Neo3NeoXBridgeOrchestrator_accountToUse_set(value) {
|
|
314
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAccountToUse, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAccountToUse, "f")), value), "f");
|
|
315
|
+
this.eventEmitter.emit('accountToUse', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAccountToUse, "f"));
|
|
316
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUse_get = function _Neo3NeoXBridgeOrchestrator_amountToUse_get() {
|
|
317
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUse, "f");
|
|
318
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUse_set = function _Neo3NeoXBridgeOrchestrator_amountToUse_set(value) {
|
|
319
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUse, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUse, "f")), value), "f");
|
|
320
|
+
this.eventEmitter.emit('amountToUse', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUse, "f"));
|
|
321
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUseMin_get = function _Neo3NeoXBridgeOrchestrator_amountToUseMin_get() {
|
|
322
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin, "f");
|
|
323
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUseMin_set = function _Neo3NeoXBridgeOrchestrator_amountToUseMin_set(value) {
|
|
324
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin, "f")), value), "f");
|
|
325
|
+
this.eventEmitter.emit('amountToUseMin', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMin, "f"));
|
|
326
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUseMax_get = function _Neo3NeoXBridgeOrchestrator_amountToUseMax_get() {
|
|
327
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax, "f");
|
|
328
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToUseMax_set = function _Neo3NeoXBridgeOrchestrator_amountToUseMax_set(value) {
|
|
329
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax, "f")), value), "f");
|
|
330
|
+
this.eventEmitter.emit('amountToUseMax', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToUseMax, "f"));
|
|
331
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToReceive_get = function _Neo3NeoXBridgeOrchestrator_tokenToReceive_get() {
|
|
332
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToReceive, "f");
|
|
333
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToReceive_set = function _Neo3NeoXBridgeOrchestrator_tokenToReceive_set(value) {
|
|
334
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToReceive, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToReceive, "f")), value), "f");
|
|
335
|
+
this.eventEmitter.emit('tokenToReceive', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToReceive, "f"));
|
|
336
|
+
}, _Neo3NeoXBridgeOrchestrator_addressToReceive_get = function _Neo3NeoXBridgeOrchestrator_addressToReceive_get() {
|
|
337
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAddressToReceive, "f");
|
|
338
|
+
}, _Neo3NeoXBridgeOrchestrator_addressToReceive_set = function _Neo3NeoXBridgeOrchestrator_addressToReceive_set(value) {
|
|
339
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAddressToReceive, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAddressToReceive, "f")), value), "f");
|
|
340
|
+
this.eventEmitter.emit('addressToReceive', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAddressToReceive, "f"));
|
|
341
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToReceive_get = function _Neo3NeoXBridgeOrchestrator_amountToReceive_get() {
|
|
342
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToReceive, "f");
|
|
343
|
+
}, _Neo3NeoXBridgeOrchestrator_amountToReceive_set = function _Neo3NeoXBridgeOrchestrator_amountToReceive_set(value) {
|
|
344
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToReceive, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToReceive, "f")), value), "f");
|
|
345
|
+
this.eventEmitter.emit('amountToReceive', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAmountToReceive, "f"));
|
|
346
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_get = function _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_get() {
|
|
347
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance, "f");
|
|
348
|
+
}, _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set = function _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set(value) {
|
|
349
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance, "f")), value), "f");
|
|
350
|
+
this.eventEmitter.emit('tokenToUseBalance', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance, "f"));
|
|
351
|
+
}, _Neo3NeoXBridgeOrchestrator_bridgeFee_get = function _Neo3NeoXBridgeOrchestrator_bridgeFee_get() {
|
|
352
|
+
return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalBridgeFee, "f");
|
|
353
|
+
}, _Neo3NeoXBridgeOrchestrator_bridgeFee_set = function _Neo3NeoXBridgeOrchestrator_bridgeFee_set(value) {
|
|
354
|
+
__classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalBridgeFee, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalBridgeFee, "f")), value), "f");
|
|
355
|
+
this.eventEmitter.emit('bridgeFee', __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalBridgeFee, "f"));
|
|
356
|
+
}, _Neo3NeoXBridgeOrchestrator_treatError = function _Neo3NeoXBridgeOrchestrator_treatError(error) {
|
|
357
|
+
if (error instanceof blockchain_service_1.BSError)
|
|
358
|
+
return error;
|
|
359
|
+
return new blockchain_service_1.BSError('An unexpected error occurred', 'UNEXPECTED_ERROR', { cause: error });
|
|
360
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./Neo3NeoXBridgeOrchestrator"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TSimpleSwapApiCreateExchangeParams, TSimpleSwapApiCurrency, TSimpleSwapOrchestratorInitParams } from './types';
|
|
2
|
+
export declare class SimpleSwapApi<BSName extends string = string> {
|
|
3
|
+
#private;
|
|
4
|
+
constructor();
|
|
5
|
+
getCurrencies(options: TSimpleSwapOrchestratorInitParams<BSName>): Promise<TSimpleSwapApiCurrency<BSName>[]>;
|
|
6
|
+
getPairs(ticker: string, network: string): Promise<TSimpleSwapApiCurrency<BSName>[]>;
|
|
7
|
+
getRange(currencyFrom: TSimpleSwapApiCurrency, currencyTo: TSimpleSwapApiCurrency): Promise<{
|
|
8
|
+
min: string;
|
|
9
|
+
max: string | null;
|
|
10
|
+
}>;
|
|
11
|
+
getEstimate(currencyFrom: TSimpleSwapApiCurrency, currencyTo: TSimpleSwapApiCurrency, amount: string): Promise<string>;
|
|
12
|
+
createExchange({ currencyFrom, currencyTo, amount, refundAddress, address, extraIdToReceive, }: TSimpleSwapApiCreateExchangeParams): Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
depositAddress: string;
|
|
15
|
+
log: string;
|
|
16
|
+
}>;
|
|
17
|
+
getExchange(id: string): Promise<{
|
|
18
|
+
status: string;
|
|
19
|
+
txFrom: string | undefined;
|
|
20
|
+
txTo: string | undefined;
|
|
21
|
+
log: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|