@cityofzion/bs-neo3 1.15.2 → 1.15.3

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.
@@ -1,16 +1,13 @@
1
- import { INeo3NeoXBridgeService, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceCalculateMaxAmountParams, TNeo3NeoXBridgeServiceValidatedInputs, TNeo3NeoXBridgeServiceValidateInputParams, TNeo3NeoXBridgeServiceWaitParams } from '@cityofzion/blockchain-service';
1
+ import { INeo3NeoXBridgeService, TBridgeToken, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceConstants, TNeo3NeoXBridgeServiceGetNonceParams, TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams } from '@cityofzion/blockchain-service';
2
2
  import { BSNeo3 } from '../../BSNeo3';
3
3
  export declare class Neo3NeoXBridgeService<BSName extends string = string> implements INeo3NeoXBridgeService<BSName> {
4
4
  #private;
5
5
  readonly BRIDGE_SCRIPT_HASH = "0xbb19cfc864b73159277e1fd39694b3fd5fc613d2";
6
- readonly BRIDGE_GAS_FEE = 0.1;
7
- readonly BRIDGE_MIN_AMOUNT = 1;
8
- readonly BRIDGE_NEOX_BASE_CONFIRMATION_URL = "https://xexplorer.neo.org:8877/api/v1/transactions/deposits";
9
- readonly BRIDGE_NEOX_NEO_TOKEN_HASH = "0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f";
6
+ tokens: TBridgeToken[];
10
7
  constructor(service: BSNeo3<BSName>);
11
- calculateMaxAmount({ account, balances, receiverAddress, token, }: TNeo3NeoXBridgeServiceCalculateMaxAmountParams<BSName>): Promise<string>;
12
- calculateFee(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
8
+ getApprovalFee(): Promise<string>;
9
+ getBridgeConstants(token: TBridgeToken): Promise<TNeo3NeoXBridgeServiceConstants>;
13
10
  bridge(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
14
- validateInputs(params: TNeo3NeoXBridgeServiceValidateInputParams<BSName>): Promise<TNeo3NeoXBridgeServiceValidatedInputs>;
15
- wait(params: TNeo3NeoXBridgeServiceWaitParams): Promise<boolean>;
11
+ getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams): Promise<string | null>;
12
+ getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams): Promise<string | null>;
16
13
  }
@@ -22,7 +22,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
- var _Neo3NeoXBridgeService_instances, _Neo3NeoXBridgeService_service, _Neo3NeoXBridgeService_buildGasCIM, _Neo3NeoXBridgeService_buildNeoCIM, _Neo3NeoXBridgeService_buildCIM, _Neo3NeoXBridgeService_validateGas, _Neo3NeoXBridgeService_validateNeo;
25
+ var _Neo3NeoXBridgeService_service;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Neo3NeoXBridgeService = void 0;
28
28
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -33,60 +33,75 @@ const DoraBDSNeo3_1 = require("../blockchain-data/DoraBDSNeo3");
33
33
  const axios_1 = __importDefault(require("axios"));
34
34
  class Neo3NeoXBridgeService {
35
35
  constructor(service) {
36
- _Neo3NeoXBridgeService_instances.add(this);
37
36
  this.BRIDGE_SCRIPT_HASH = '0xbb19cfc864b73159277e1fd39694b3fd5fc613d2';
38
- this.BRIDGE_GAS_FEE = 0.1;
39
- this.BRIDGE_MIN_AMOUNT = 1;
40
- this.BRIDGE_NEOX_BASE_CONFIRMATION_URL = 'https://xexplorer.neo.org:8877/api/v1/transactions/deposits';
41
- this.BRIDGE_NEOX_NEO_TOKEN_HASH = '0xc28736dc83f4fd43d6fb832Fd93c3eE7bB26828f';
42
37
  _Neo3NeoXBridgeService_service.set(this, void 0);
43
38
  __classPrivateFieldSet(this, _Neo3NeoXBridgeService_service, service, "f");
39
+ this.tokens = [
40
+ Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN), { multichainId: 'gas' }),
41
+ Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN), { multichainId: 'neo' }),
42
+ ];
44
43
  }
45
- calculateMaxAmount({ account, balances, receiverAddress, token, }) {
44
+ getApprovalFee() {
46
45
  return __awaiter(this, void 0, void 0, function* () {
47
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
48
- throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
49
- const normalizedSelectedToken = blockchain_service_1.BSTokenHelper.normalizeToken(token);
50
- const selectedTokenBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.normalizeHash(balance.token.hash) === normalizedSelectedToken.hash);
51
- if (!selectedTokenBalance) {
52
- throw new blockchain_service_1.BSError('Token balance not found', 'TOKEN_BALANCE_NOT_FOUND');
53
- }
54
- const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(selectedTokenBalance.amount);
55
- const validatedInputs = {
56
- receiveAmount: amountNumber.minus(this.BRIDGE_MIN_AMOUNT).toString(),
57
- token,
58
- amount: amountNumber.toString(),
59
- };
60
- const fee = yield this.calculateFee({
61
- account,
62
- receiverAddress,
63
- validatedInputs,
64
- });
65
- const maxAmount = amountNumber.minus(fee).toString();
66
- return maxAmount;
46
+ throw new blockchain_service_1.BSError('Neo3 does not require approval', 'APPROVAl_NOT_NEEDED');
67
47
  });
68
48
  }
69
- calculateFee(params) {
49
+ getBridgeConstants(token) {
70
50
  return __awaiter(this, void 0, void 0, function* () {
71
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
72
- throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
73
- try {
74
- const { account } = params;
75
- const { neonJsAccount } = yield __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").generateSigningCallback(account);
76
- const invoker = yield neon_dappkit_1.NeonInvoker.init({
77
- rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
78
- account: neonJsAccount,
79
- });
80
- const contractInvocationMulti = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildCIM).call(this, params, neonJsAccount);
81
- const { total } = yield invoker.calculateFee(contractInvocationMulti);
82
- return total.toString();
51
+ const invoker = yield neon_dappkit_1.NeonInvoker.init({
52
+ rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
53
+ });
54
+ const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
55
+ let invocations;
56
+ if (isNativeToken) {
57
+ invocations = [
58
+ { operation: 'nativeDepositFee', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
59
+ { operation: 'minNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
60
+ { operation: 'maxNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
61
+ ];
83
62
  }
84
- catch (error) {
85
- throw new blockchain_service_1.BSError(error.message, 'FEE_CALCULATION_ERROR');
63
+ else {
64
+ invocations = [
65
+ {
66
+ operation: 'tokenDepositFee',
67
+ scriptHash: this.BRIDGE_SCRIPT_HASH,
68
+ args: [{ type: 'Hash160', value: token.hash }],
69
+ },
70
+ {
71
+ operation: 'minTokenDeposit',
72
+ scriptHash: this.BRIDGE_SCRIPT_HASH,
73
+ args: [{ type: 'Hash160', value: token.hash }],
74
+ },
75
+ {
76
+ operation: 'maxTokenDeposit',
77
+ scriptHash: this.BRIDGE_SCRIPT_HASH,
78
+ args: [{ type: 'Hash160', value: token.hash }],
79
+ },
80
+ ];
86
81
  }
82
+ const response = yield invoker.testInvoke({
83
+ invocations,
84
+ });
85
+ const [depositFeeItem, minDepositItem, maxDepositItem] = response.stack;
86
+ if (!neon_dappkit_1.TypeChecker.isStackTypeInteger(depositFeeItem) ||
87
+ !neon_dappkit_1.TypeChecker.isStackTypeInteger(minDepositItem) ||
88
+ !neon_dappkit_1.TypeChecker.isStackTypeInteger(maxDepositItem))
89
+ throw new blockchain_service_1.BSError('Invalid response', 'INVALID_RESPONSE');
90
+ const bridgeFeeBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(depositFeeItem.value, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals).toString();
91
+ const minAmountBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(minDepositItem.value, token.decimals).toString();
92
+ const maxAmountBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(maxDepositItem.value, token.decimals).toString();
93
+ const bridgeFee = blockchain_service_1.BSBigNumberHelper.format(bridgeFeeBn, { decimals: BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals });
94
+ const bridgeMinAmount = blockchain_service_1.BSBigNumberHelper.format(minAmountBn, { decimals: token.decimals });
95
+ const bridgeMaxAmount = blockchain_service_1.BSBigNumberHelper.format(maxAmountBn, { decimals: token.decimals });
96
+ return {
97
+ bridgeFee,
98
+ bridgeMinAmount,
99
+ bridgeMaxAmount,
100
+ };
87
101
  });
88
102
  }
89
103
  bridge(params) {
104
+ var _a, _b;
90
105
  return __awaiter(this, void 0, void 0, function* () {
91
106
  if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
92
107
  throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
@@ -97,206 +112,74 @@ class Neo3NeoXBridgeService {
97
112
  account: neonJsAccount,
98
113
  signingCallback: signingCallback,
99
114
  });
100
- const contractInvocationMulti = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildCIM).call(this, params, neonJsAccount);
101
- const transactionHash = yield invoker.invokeFunction(contractInvocationMulti);
102
- return transactionHash;
103
- });
104
- }
105
- validateInputs(params) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
108
- throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
109
- const normalizedSelectedToken = blockchain_service_1.BSTokenHelper.normalizeToken(params.token);
110
- const isGasToken = normalizedSelectedToken.hash === BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash;
111
- const isNeoToken = normalizedSelectedToken.hash === BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash;
112
- if (isGasToken) {
113
- return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_validateGas).call(this, params);
114
- }
115
- else if (isNeoToken) {
116
- return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_validateNeo).call(this, params);
117
- }
118
- else {
119
- throw new blockchain_service_1.BSError('Only GAS and NEO tokens are supported for bridging', 'UNSUPPORTED_TOKEN');
120
- }
121
- });
122
- }
123
- wait(params) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
126
- throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
127
- try {
128
- const { transactionHash, validatedInputs } = params;
129
- let nonce;
130
- const log = yield blockchain_service_1.BSUtilsHelper.retry(() => DoraBDSNeo3_1.DoraNeoRest.log(transactionHash, __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.id), {
131
- retries: 10,
132
- delay: 30000,
133
- });
134
- if (log.vmstate !== 'HALT') {
135
- throw new Error();
136
- }
137
- const isGasToken = blockchain_service_1.BSTokenHelper.predicateByHash(validatedInputs.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
138
- if (isGasToken) {
139
- const notification = log.notifications.find(item => item.event_name === 'NativeDeposit');
140
- nonce = notification === null || notification === void 0 ? void 0 : notification.state.value[0].value;
141
- }
142
- else {
143
- const notification = log.notifications.find(item => item.event_name === 'TokenDeposit');
144
- nonce = notification === null || notification === void 0 ? void 0 : notification.state.value[2].value;
145
- }
146
- if (!nonce) {
147
- throw new Error();
148
- }
149
- yield blockchain_service_1.BSUtilsHelper.retry(() => __awaiter(this, void 0, void 0, function* () {
150
- var _a;
151
- let url;
152
- if (isGasToken) {
153
- url = `${this.BRIDGE_NEOX_BASE_CONFIRMATION_URL}/${nonce}`;
154
- }
155
- else {
156
- url = `${this.BRIDGE_NEOX_BASE_CONFIRMATION_URL}/${this.BRIDGE_NEOX_NEO_TOKEN_HASH}/${nonce}`;
157
- }
158
- const response = yield axios_1.default.get(url);
159
- if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.txid)) {
160
- throw new blockchain_service_1.BSError('Transaction not found', 'TRANSACTION_NOT_FOUND');
161
- }
162
- }), {
163
- retries: 10,
164
- delay: 30000,
165
- });
166
- return true;
167
- }
168
- catch (error) {
169
- return false;
170
- }
171
- });
172
- }
173
- }
174
- exports.Neo3NeoXBridgeService = Neo3NeoXBridgeService;
175
- _Neo3NeoXBridgeService_service = new WeakMap(), _Neo3NeoXBridgeService_instances = new WeakSet(), _Neo3NeoXBridgeService_buildGasCIM = function _Neo3NeoXBridgeService_buildGasCIM({ receiverAddress, validatedInputs }, neonJsAccount) {
176
- return {
177
- invocations: [
178
- {
115
+ const contractInvocation = {
179
116
  scriptHash: this.BRIDGE_SCRIPT_HASH,
180
117
  operation: 'depositNative',
181
118
  args: [
182
119
  { type: 'Hash160', value: neonJsAccount.address },
183
- { type: 'Hash160', value: receiverAddress },
120
+ { type: 'Hash160', value: params.receiverAddress },
184
121
  {
185
122
  type: 'Integer',
186
- value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(validatedInputs.receiveAmount), validatedInputs.token.decimals),
123
+ value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(params.amount), params.token.decimals),
187
124
  },
188
125
  {
189
126
  type: 'Integer',
190
- value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
127
+ value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(params.bridgeFee), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
191
128
  },
192
129
  ],
193
- },
194
- ],
195
- signers: [
196
- {
130
+ };
131
+ const signer = {
197
132
  scopes: 16,
198
133
  allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash],
199
- },
200
- ],
201
- };
202
- }, _Neo3NeoXBridgeService_buildNeoCIM = function _Neo3NeoXBridgeService_buildNeoCIM({ receiverAddress, validatedInputs }, neonJsAccount) {
203
- return {
204
- invocations: [
205
- {
206
- scriptHash: this.BRIDGE_SCRIPT_HASH,
207
- operation: 'depositToken',
208
- args: [
209
- { type: 'Hash160', value: BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash },
210
- { type: 'Hash160', value: neonJsAccount.scriptHash },
211
- { type: 'Hash160', value: receiverAddress },
212
- {
213
- type: 'Integer',
214
- value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(validatedInputs.receiveAmount), validatedInputs.token.decimals),
215
- },
216
- {
217
- type: 'Integer',
218
- value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
219
- },
220
- ],
221
- },
222
- ],
223
- signers: [
224
- {
225
- scopes: 16,
226
- allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash],
227
- },
228
- ],
229
- };
230
- }, _Neo3NeoXBridgeService_buildCIM = function _Neo3NeoXBridgeService_buildCIM(params, neonJsAccount) {
231
- const isGasToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.validatedInputs.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
232
- if (isGasToken) {
233
- return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildGasCIM).call(this, params, neonJsAccount);
134
+ };
135
+ const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
136
+ if (!isNativeToken) {
137
+ (_a = contractInvocation.args) === null || _a === void 0 ? void 0 : _a.unshift({ type: 'Hash160', value: BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash });
138
+ (_b = signer.allowedContracts) === null || _b === void 0 ? void 0 : _b.push(BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash);
139
+ }
140
+ const transactionHash = yield invoker.invokeFunction({
141
+ invocations: [contractInvocation],
142
+ signers: [signer],
143
+ });
144
+ return transactionHash;
145
+ });
234
146
  }
235
- return __classPrivateFieldGet(this, _Neo3NeoXBridgeService_instances, "m", _Neo3NeoXBridgeService_buildNeoCIM).call(this, params, neonJsAccount);
236
- }, _Neo3NeoXBridgeService_validateGas = function _Neo3NeoXBridgeService_validateGas({ amount, balances, token, account, receiverAddress, }) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- const gasBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN));
239
- if (!gasBalance) {
240
- throw new blockchain_service_1.BSError('GAS is necessary to bridge', 'GAS_BALANCE_NOT_FOUND');
241
- }
242
- const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(amount);
243
- const gasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(gasBalance.amount);
244
- const validatedInputs = {
245
- receiveAmount: amountNumber.minus(this.BRIDGE_GAS_FEE).toString(),
246
- token,
247
- amount,
248
- };
249
- if (amountNumber.isLessThan(this.BRIDGE_MIN_AMOUNT + this.BRIDGE_GAS_FEE)) {
250
- throw new blockchain_service_1.BSError('Amount is less than the minimum amount plus bridge fee', 'AMOUNT_TOO_LOW');
251
- }
252
- if (amountNumber.isGreaterThan(gasBalanceNumber)) {
253
- throw new blockchain_service_1.BSError('Amount is greater than your balance', 'INSUFFICIENT_GAS_BALANCE');
254
- }
255
- const fee = yield this.calculateFee({
256
- account,
257
- receiverAddress,
258
- validatedInputs,
147
+ getNonce(params) {
148
+ var _a, _b;
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const log = yield DoraBDSNeo3_1.DoraNeoRest.log(params.transactionHash, __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.id);
151
+ if (log.vmstate !== 'HALT') {
152
+ return null;
153
+ }
154
+ const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
155
+ if (isNativeToken) {
156
+ const notification = log.notifications.find(item => item.event_name === 'NativeDeposit');
157
+ return (_a = notification === null || notification === void 0 ? void 0 : notification.state.value[0].value) !== null && _a !== void 0 ? _a : null;
158
+ }
159
+ const notification = log.notifications.find(item => item.event_name === 'TokenDeposit');
160
+ return (_b = notification === null || notification === void 0 ? void 0 : notification.state.value[2].value) !== null && _b !== void 0 ? _b : null;
259
161
  });
260
- if (amountNumber.plus(fee).isGreaterThan(gasBalanceNumber)) {
261
- throw new blockchain_service_1.BSError('Amount is greater than your balance plus fee', 'INSUFFICIENT_GAS_BALANCE_FEE');
262
- }
263
- return validatedInputs;
264
- });
265
- }, _Neo3NeoXBridgeService_validateNeo = function _Neo3NeoXBridgeService_validateNeo({ amount, balances, token, account, receiverAddress, }) {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- const gasBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN));
268
- if (!gasBalance) {
269
- throw new blockchain_service_1.BSError('GAS is necessary to bridge', 'GAS_BALANCE_NOT_FOUND');
270
- }
271
- const neoBalance = balances.find(balance => blockchain_service_1.BSTokenHelper.predicateByHash(balance.token)(BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN));
272
- if (!neoBalance) {
273
- throw new blockchain_service_1.BSError('NEO balance not found', 'NEO_BALANCE_NOT_FOUND');
274
- }
275
- const amountNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(amount);
276
- const gasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(gasBalance.amount);
277
- const minGasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE);
278
- const validatedInputs = {
279
- receiveAmount: amount,
280
- token,
281
- amount,
282
- };
283
- if (amountNumber.isLessThan(this.BRIDGE_MIN_AMOUNT)) {
284
- throw new blockchain_service_1.BSError('Amount is less than the minimum amount', 'AMOUNT_TOO_LOW');
285
- }
286
- if (amountNumber.isGreaterThan(neoBalance.amount)) {
287
- throw new blockchain_service_1.BSError('Amount is greater than your balance', 'INSUFFICIENT_NEO_BALANCE');
288
- }
289
- if (gasBalanceNumber.isLessThan(minGasBalanceNumber)) {
290
- throw new blockchain_service_1.BSError('GAS balance is less than bridge fee', 'INSUFFICIENT_GAS_BALANCE_BRIDGE_FEE');
291
- }
292
- const fee = yield this.calculateFee({
293
- account,
294
- receiverAddress,
295
- validatedInputs,
162
+ }
163
+ getTransactionHashByNonce(params) {
164
+ var _a;
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ const isNativeToken = blockchain_service_1.BSTokenHelper.predicateByHash(params.token)(BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
167
+ const { data } = yield axios_1.default.post('https://neofura.ngd.network', {
168
+ jsonrpc: '2.0',
169
+ method: 'GetBridgeTxByNonce',
170
+ params: {
171
+ ContractHash: this.BRIDGE_SCRIPT_HASH,
172
+ TokenHash: isNativeToken ? '' : BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash,
173
+ Nonce: Number(params.nonce),
174
+ },
175
+ id: 1,
176
+ });
177
+ if (!(data === null || data === void 0 ? void 0 : data.result)) {
178
+ throw new blockchain_service_1.BSError('Transaction not found', 'INVALID_RESPONSE');
179
+ }
180
+ return data.result.Vmstate === 'HALT' ? (_a = data.result.txid) !== null && _a !== void 0 ? _a : null : null;
296
181
  });
297
- if (minGasBalanceNumber.plus(fee).isGreaterThan(gasBalanceNumber)) {
298
- throw new blockchain_service_1.BSError('GAS balance is less than fees', 'INSUFFICIENT_GAS_BALANCE_FEES');
299
- }
300
- return validatedInputs;
301
- });
302
- };
182
+ }
183
+ }
184
+ exports.Neo3NeoXBridgeService = Neo3NeoXBridgeService;
185
+ _Neo3NeoXBridgeService_service = new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.15.2",
3
+ "version": "1.15.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -10,22 +10,22 @@
10
10
  "/dist"
11
11
  ],
12
12
  "dependencies": {
13
- "@cityofzion/neon-js": "5.5.1",
14
- "@cityofzion/neon-core": "5.5.1",
13
+ "@cityofzion/neon-js": "~5.7.0",
14
+ "@cityofzion/neon-core": "~5.7.0",
15
15
  "@cityofzion/dora-ts": "0.5.1",
16
16
  "axios": "1.8.2",
17
17
  "query-string": "7.1.3",
18
- "@ledgerhq/hw-transport": "~6.30.5",
19
- "@cityofzion/neon-dappkit": "0.4.1",
18
+ "@ledgerhq/hw-transport": "~6.31.8",
19
+ "@cityofzion/neon-dappkit": "~0.6.0",
20
20
  "bignumber.js": "^9.1.2",
21
21
  "isomorphic-ws": "^5.0.0",
22
22
  "lodash.clonedeep": "^4.5.0",
23
23
  "date-fns": "~4.1.0",
24
- "@cityofzion/blockchain-service": "1.19.1",
24
+ "@cityofzion/blockchain-service": "1.19.2",
25
25
  "@cityofzion/bs-asteroid-sdk": "0.9.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@cityofzion/neon-dappkit-types": "~0.3.1",
28
+ "@cityofzion/neon-dappkit-types": "~0.5.0",
29
29
  "@ledgerhq/hw-transport-node-hid": "~6.28.5",
30
30
  "@types/lodash.clonedeep": "^4.5.9",
31
31
  "@types/jest": "29.5.3",