@cityofzion/bs-multichain 1.0.2 → 1.0.4

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.
@@ -2,7 +2,7 @@ import { Account, BalanceResponse, IBridgeOrchestrator, TBridgeOrchestratorEvent
2
2
  import { BSNeo3 } from '@cityofzion/bs-neo3';
3
3
  import { BSNeoX } from '@cityofzion/bs-neox';
4
4
  import TypedEmitter from 'typed-emitter';
5
- import { TNeo3NeoXBridgeOrchestratorInitParams } from './types';
5
+ import { TNeo3NeoXBridgeOrchestratorInitParams, TNeo3NeoXBridgeOrchestratorWaitParams } from './types';
6
6
  export declare class Neo3NeoXBridgeOrchestrator<BSName extends string> implements IBridgeOrchestrator<BSName> {
7
7
  #private;
8
8
  eventEmitter: TypedEmitter<TBridgeOrchestratorEvents<BSName>>;
@@ -11,11 +11,11 @@ export declare class Neo3NeoXBridgeOrchestrator<BSName extends string> implement
11
11
  constructor(params: TNeo3NeoXBridgeOrchestratorInitParams<BSName>);
12
12
  init(): Promise<void>;
13
13
  switchTokens(): Promise<void>;
14
- setTokenToUse(token: TBridgeToken | null): Promise<void>;
14
+ setTokenToUse(token: TBridgeToken<BSName> | null): Promise<void>;
15
15
  setAccountToUse(account: Account<BSName> | null): Promise<void>;
16
16
  setAddressToReceive(address: string | null): Promise<void>;
17
17
  setBalances(balances: BalanceResponse[] | null): Promise<void>;
18
18
  setAmountToUse(amount: string | null): Promise<void>;
19
19
  bridge(): Promise<string>;
20
- wait(): Promise<boolean>;
20
+ static wait<BSName extends string = string>({ tokenToUse, tokenToReceive, transactionHash, neo3Service, neoXService, }: TNeo3NeoXBridgeOrchestratorWaitParams<BSName>): Promise<void>;
21
21
  }
@@ -22,7 +22,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
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;
25
+ var _Neo3NeoXBridgeOrchestrator_instances, _Neo3NeoXBridgeOrchestrator_balances, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout, _Neo3NeoXBridgeOrchestrator_amountToUseTimeout, _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
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Neo3NeoXBridgeOrchestrator = void 0;
28
28
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -33,7 +33,7 @@ class Neo3NeoXBridgeOrchestrator {
33
33
  _Neo3NeoXBridgeOrchestrator_balances.set(this, null);
34
34
  _Neo3NeoXBridgeOrchestrator_feeTokenBalance.set(this, null);
35
35
  _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout.set(this, undefined);
36
- _Neo3NeoXBridgeOrchestrator_transactionHash.set(this, null);
36
+ _Neo3NeoXBridgeOrchestrator_amountToUseTimeout.set(this, undefined);
37
37
  _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse.set(this, { value: null, loading: false, error: null });
38
38
  _Neo3NeoXBridgeOrchestrator_internalTokenToUse.set(this, { value: null, loading: false, error: null });
39
39
  _Neo3NeoXBridgeOrchestrator_internalAccountToUse.set(this, { value: null, loading: false, error: null });
@@ -46,8 +46,9 @@ class Neo3NeoXBridgeOrchestrator {
46
46
  _Neo3NeoXBridgeOrchestrator_internalTokenToUseBalance.set(this, { value: null, loading: false, error: null });
47
47
  _Neo3NeoXBridgeOrchestrator_internalBridgeFee.set(this, { value: null, loading: false, error: null });
48
48
  this.eventEmitter = new events_1.default();
49
- this.fromService = params.neo3Service;
50
- this.toService = params.neoXService;
49
+ const isInitialNeoX = params.initialFromServiceName === params.neoXService.name;
50
+ this.fromService = isInitialNeoX ? params.neoXService : params.neo3Service;
51
+ this.toService = isInitialNeoX ? params.neo3Service : params.neoXService;
51
52
  }
52
53
  init() {
53
54
  return __awaiter(this, void 0, void 0, function* () {
@@ -64,7 +65,6 @@ class Neo3NeoXBridgeOrchestrator {
64
65
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_tokenToReceive_set);
65
66
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_tokenToUseBalance_set);
66
67
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
67
- __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, null, "f");
68
68
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_balances, null, "f");
69
69
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, null, "f");
70
70
  });
@@ -159,12 +159,13 @@ class Neo3NeoXBridgeOrchestrator {
159
159
  ? balances === null || balances === void 0 ? void 0 : balances.find(item => blockchain_service_1.BSTokenHelper.predicateByHash(this.fromService.feeToken)(item.token))
160
160
  : null;
161
161
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, feeTokenBalance, "f");
162
+ if (tokenToUseBalance === null || !__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value) {
163
+ return;
164
+ }
162
165
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_set);
163
166
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
164
167
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true, error: null }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
165
168
  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
169
  const constants = yield this.fromService.neo3NeoXBridgeService.getBridgeConstants(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
169
170
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeMinAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_set);
170
171
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: constants.bridgeFee }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
@@ -188,60 +189,67 @@ class Neo3NeoXBridgeOrchestrator {
188
189
  });
189
190
  }
190
191
  setAmountToUse(amount) {
191
- var _a, _b;
192
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) {
193
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: amount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
194
+ if (!amount) {
199
195
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
196
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: null, loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_set);
200
197
  return;
201
198
  }
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');
199
+ if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_amountToUseTimeout, "f") !== null)
200
+ clearTimeout(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_amountToUseTimeout, "f"));
201
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_amountToUseTimeout, setTimeout(() => __awaiter(this, void 0, void 0, function* () {
202
+ var _a, _b;
203
+ if (!__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value)
204
+ return;
205
+ const formattedAmount = blockchain_service_1.BSBigNumberHelper.format(amount, { decimals: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value.decimals });
206
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToReceive_set);
207
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { value: formattedAmount }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
208
+ try {
209
+ if (__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value === null ||
210
+ __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_get).value === null ||
211
+ __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_get).value === null ||
212
+ __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value === null ||
213
+ __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value === null ||
214
+ __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_feeTokenBalance, "f") === null) {
215
+ return;
216
+ }
217
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
218
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: true }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
219
+ const amountToUseBn = blockchain_service_1.BSBigNumberHelper.fromNumber(formattedAmount);
220
+ if (amountToUseBn.isLessThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMin_get).value)) {
221
+ throw new blockchain_service_1.BSError('Amount is below the minimum', 'AMOUNT_BELOW_MINIMUM');
222
+ }
223
+ if (amountToUseBn.isGreaterThan(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_amountToUseMax_get).value)) {
224
+ throw new blockchain_service_1.BSError('Amount is above the maximum', 'AMOUNT_ABOVE_MAXIMUM');
225
+ }
226
+ const approvalFee = yield this.fromService.neo3NeoXBridgeService
227
+ .getApprovalFee({
228
+ account: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_accountToUse_get).value,
229
+ token: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value,
230
+ amount: formattedAmount,
231
+ })
232
+ .then(fee => fee)
233
+ .catch(() => '0');
234
+ const newBridgeFee = blockchain_service_1.BSBigNumberHelper.fromNumber(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value).plus(approvalFee);
235
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, {
236
+ value: blockchain_service_1.BSBigNumberHelper.format(newBridgeFee, { decimals: this.fromService.feeToken.decimals }),
237
+ }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
238
+ const isFeeToken = blockchain_service_1.BSTokenHelper.predicateByHash(this.fromService.feeToken)(__classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_tokenToUse_get).value);
239
+ 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)) {
240
+ throw new blockchain_service_1.BSError('You do not have enough fee token balance to cover the bridge fee', 'INSUFFICIENT_FEE_TOKEN_BALANCE');
241
+ }
242
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: true }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
210
243
  }
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');
244
+ catch (error) {
245
+ const treatedError = __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "m", _Neo3NeoXBridgeOrchestrator_treatError).call(this, error);
246
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { valid: false, error: treatedError }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
217
247
  }
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');
248
+ finally {
249
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_amountToUse_set);
250
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_instances, { loading: false }, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_set);
233
251
  }
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
- }
252
+ }), 1500), "f");
245
253
  });
246
254
  }
247
255
  bridge() {
@@ -263,42 +271,30 @@ class Neo3NeoXBridgeOrchestrator {
263
271
  receiverAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_addressToReceive_get).value,
264
272
  bridgeFee: __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_instances, "a", _Neo3NeoXBridgeOrchestrator_bridgeFee_get).value,
265
273
  });
266
- __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_transactionHash, transaction, "f");
267
274
  return transaction;
268
275
  });
269
276
  }
270
- wait() {
277
+ static wait({ tokenToUse, tokenToReceive, transactionHash, neo3Service, neoXService, }) {
271
278
  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
- }
279
+ const isNeo3Service = tokenToUse.blockchain === neo3Service.name;
280
+ const fromService = isNeo3Service ? neo3Service : neoXService;
281
+ const toService = isNeo3Service ? neoXService : neo3Service;
282
+ const nonce = yield blockchain_service_1.BSUtilsHelper.retry(() => fromService.neo3NeoXBridgeService.getNonce({
283
+ token: tokenToUse,
284
+ transactionHash,
285
+ }), {
286
+ retries: 10,
287
+ delay: 30000,
288
+ });
289
+ yield blockchain_service_1.BSUtilsHelper.retry(() => toService.neo3NeoXBridgeService.getTransactionHashByNonce({ nonce, token: tokenToReceive }), {
290
+ retries: 10,
291
+ delay: 30000,
292
+ });
297
293
  });
298
294
  }
299
295
  }
300
296
  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() {
297
+ _Neo3NeoXBridgeOrchestrator_balances = new WeakMap(), _Neo3NeoXBridgeOrchestrator_feeTokenBalance = new WeakMap(), _Neo3NeoXBridgeOrchestrator_addressToReceiveTimeout = new WeakMap(), _Neo3NeoXBridgeOrchestrator_amountToUseTimeout = 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
298
  return __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, "f");
303
299
  }, _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set = function _Neo3NeoXBridgeOrchestrator_availableTokensToUse_set(value) {
304
300
  __classPrivateFieldSet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Neo3NeoXBridgeOrchestrator_internalAvailableTokensToUse, "f")), value), "f");
@@ -1,6 +1,15 @@
1
+ import { TBridgeToken } from '@cityofzion/blockchain-service';
1
2
  import { BSNeo3 } from '@cityofzion/bs-neo3';
2
3
  import { BSNeoX } from '@cityofzion/bs-neox';
3
4
  export type TNeo3NeoXBridgeOrchestratorInitParams<BSName extends string> = {
4
5
  neo3Service: BSNeo3<BSName>;
5
6
  neoXService: BSNeoX<BSName>;
7
+ initialFromServiceName?: BSName;
8
+ };
9
+ export type TNeo3NeoXBridgeOrchestratorWaitParams<BSName extends string = string> = {
10
+ neo3Service: BSNeo3<BSName>;
11
+ neoXService: BSNeoX<BSName>;
12
+ transactionHash: string;
13
+ tokenToUse: TBridgeToken<BSName>;
14
+ tokenToReceive: TBridgeToken<BSName>;
6
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-multichain",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -12,7 +12,7 @@
12
12
  "dependencies": {
13
13
  "axios": "~1.8.2",
14
14
  "lodash": "~4.17.21",
15
- "@cityofzion/blockchain-service": "1.19.2"
15
+ "@cityofzion/blockchain-service": "1.19.3"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/jest": "29.5.3",
@@ -27,10 +27,10 @@
27
27
  "@types/node": "~22.8.6",
28
28
  "@typescript-eslint/eslint-plugin": "~8.12.2",
29
29
  "@typescript-eslint/parser": "~8.12.2",
30
- "@cityofzion/bs-neo3": "1.15.3",
31
- "@cityofzion/bs-ethereum": "2.12.7",
32
- "@cityofzion/bs-neo-legacy": "1.12.6",
33
- "@cityofzion/bs-neox": "1.2.4"
30
+ "@cityofzion/bs-neo3": "1.15.4",
31
+ "@cityofzion/bs-neo-legacy": "1.12.8",
32
+ "@cityofzion/bs-ethereum": "2.12.8",
33
+ "@cityofzion/bs-neox": "1.2.5"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsc --project tsconfig.build.json",