@cityofzion/bs-neo3 1.14.1 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/BSNeo3.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, ExchangeDataService, ExplorerService, GetLedgerTransport, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
1
+ import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, ExchangeDataService, ExplorerService, GetLedgerTransport, IBSWithNeo3NeoXBridge, INeo3NeoXBridgeService, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
2
  import { NeonDappKitLedgerServiceNeo3 } from './services/ledger/NeonDappKitLedgerServiceNeo3';
3
3
  import { BSNeo3NetworkId } from './constants/BSNeo3Constants';
4
4
  import { GenerateSigningCallbackResponse, VoteService } from './interfaces';
5
- export declare class BSNeo3<BSName extends string = string> implements BlockchainService<BSName, BSNeo3NetworkId>, BSClaimable<BSName>, BSWithNameService, BSCalculableFee<BSName>, BSWithNft, BSWithExplorerService, BSWithLedger<BSName> {
5
+ export declare class BSNeo3<BSName extends string = string> implements BlockchainService<BSName, BSNeo3NetworkId>, BSClaimable<BSName>, BSWithNameService, BSCalculableFee<BSName>, BSWithNft, BSWithExplorerService, BSWithLedger<BSName>, IBSWithNeo3NeoXBridge<BSName> {
6
6
  #private;
7
7
  name: BSName;
8
8
  bip44DerivationPath: string;
@@ -17,6 +17,7 @@ export declare class BSNeo3<BSName extends string = string> implements Blockchai
17
17
  exchangeDataService: ExchangeDataService;
18
18
  explorerService: ExplorerService;
19
19
  voteService: VoteService<BSName>;
20
+ neo3NeoXBridgeService: INeo3NeoXBridgeService<BSName>;
20
21
  network: Network<BSNeo3NetworkId>;
21
22
  constructor(name: BSName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>);
22
23
  generateSigningCallback(account: Account<BSName>): Promise<GenerateSigningCallbackResponse>;
package/dist/BSNeo3.js CHANGED
@@ -16,6 +16,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
16
16
  var _BSNeo3_instances, _BSNeo3_setTokens, _BSNeo3_buildTransferInvocation;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.BSNeo3 = void 0;
19
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
19
20
  const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
20
21
  const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
21
22
  const neon_js_1 = require("@cityofzion/neon-js");
@@ -27,6 +28,7 @@ const NeonDappKitLedgerServiceNeo3_1 = require("./services/ledger/NeonDappKitLed
27
28
  const GhostMarketNDSNeo3_1 = require("./services/nft-data/GhostMarketNDSNeo3");
28
29
  const BSNeo3Constants_1 = require("./constants/BSNeo3Constants");
29
30
  const RpcBDSNeo3_1 = require("./services/blockchain-data/RpcBDSNeo3");
31
+ const Neo3NeoXBridgeService_1 = require("./services/neo3neoXBridge/Neo3NeoXBridgeService");
30
32
  const DoraVoteServiceNeo3_1 = require("./services/vote/DoraVoteServiceNeo3");
31
33
  class BSNeo3 {
32
34
  constructor(name, network, getLedgerTransport) {
@@ -69,6 +71,7 @@ class BSNeo3 {
69
71
  this.nftDataService = new GhostMarketNDSNeo3_1.GhostMarketNDSNeo3(network);
70
72
  this.explorerService = new DoraESNeo3_1.DoraESNeo3(network);
71
73
  this.voteService = new DoraVoteServiceNeo3_1.DoraVoteServiceNeo3(this);
74
+ this.neo3NeoXBridgeService = new Neo3NeoXBridgeService_1.Neo3NeoXBridgeService(this);
72
75
  this.blockchainDataService = new DoraBDSNeo3_1.DoraBDSNeo3(network, this.feeToken, this.claimToken, this.tokens, this.nftDataService, this.explorerService);
73
76
  this.exchangeDataService = new FlamingoForthewinEDSNeo3_1.FlamingoForthewinEDSNeo3(network);
74
77
  }
@@ -216,9 +219,7 @@ _BSNeo3_instances = new WeakSet(), _BSNeo3_setTokens = function _BSNeo3_setToken
216
219
  { type: 'Hash160', value: intent.receiverAddress },
217
220
  {
218
221
  type: 'Integer',
219
- value: intent.tokenDecimals
220
- ? neon_js_1.u.BigInteger.fromDecimal(Number(intent.amount).toFixed(intent.tokenDecimals), intent.tokenDecimals).toString()
221
- : intent.amount,
222
+ value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(intent.amount), decimals),
222
223
  },
223
224
  { type: 'Any', value: null },
224
225
  ],
@@ -2,13 +2,13 @@
2
2
  {
3
3
  "symbol": "GAS",
4
4
  "name": "GAS",
5
- "hash": "d2a4cff31913016155e38e474a2c06d08be276cf",
5
+ "hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
6
6
  "decimals": 8
7
7
  },
8
8
  {
9
9
  "symbol": "NEO",
10
10
  "name": "NEO",
11
- "hash": "ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
11
+ "hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
12
12
  "decimals": 0
13
13
  }
14
14
  ]
@@ -2,6 +2,9 @@ import { Network, NetworkId, Token } from '@cityofzion/blockchain-service';
2
2
  export type BSNeo3NetworkId = NetworkId<'mainnet' | 'testnet'>;
3
3
  export declare class BSNeo3Constants {
4
4
  static EXTRA_TOKENS_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, Token[]>>;
5
+ static NATIVE_ASSETS: Token[];
6
+ static GAS_TOKEN: Token;
7
+ static NEO_TOKEN: Token;
5
8
  static RPC_LIST_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, string[]>>;
6
9
  static MAINNET_NETWORK_IDS: BSNeo3NetworkId[];
7
10
  static TESTNET_NETWORK_IDS: BSNeo3NetworkId[];
@@ -12,5 +15,4 @@ export declare class BSNeo3Constants {
12
15
  static DEFAULT_NETWORK: Network<BSNeo3NetworkId>;
13
16
  static NEO_NS_HASH: string;
14
17
  static DEFAULT_BIP44_DERIVATION_PATH: string;
15
- static NATIVE_ASSETS: Token[];
16
18
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.BSNeo3Constants = void 0;
8
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
8
9
  const mainnet_json_1 = __importDefault(require("../assets/tokens/mainnet.json"));
9
10
  const native_json_1 = __importDefault(require("../assets/tokens/native.json"));
10
11
  class BSNeo3Constants {
@@ -12,8 +13,11 @@ class BSNeo3Constants {
12
13
  exports.BSNeo3Constants = BSNeo3Constants;
13
14
  _a = BSNeo3Constants;
14
15
  BSNeo3Constants.EXTRA_TOKENS_BY_NETWORK_ID = {
15
- mainnet: mainnet_json_1.default,
16
+ mainnet: blockchain_service_1.BSTokenHelper.normalizeToken(mainnet_json_1.default),
16
17
  };
18
+ BSNeo3Constants.NATIVE_ASSETS = blockchain_service_1.BSTokenHelper.normalizeToken(native_json_1.default);
19
+ BSNeo3Constants.GAS_TOKEN = _a.NATIVE_ASSETS.find(token => token.name === 'GAS');
20
+ BSNeo3Constants.NEO_TOKEN = _a.NATIVE_ASSETS.find(token => token.name === 'NEO');
17
21
  BSNeo3Constants.RPC_LIST_BY_NETWORK_ID = {
18
22
  mainnet: [
19
23
  'https://mainnet1.neo.coz.io:443',
@@ -55,7 +59,7 @@ BSNeo3Constants.TESTNET_NETWORKS = [
55
59
  },
56
60
  ];
57
61
  BSNeo3Constants.ALL_NETWORKS = [..._a.MAINNET_NETWORKS, ..._a.TESTNET_NETWORKS];
62
+ // If tou change this, make sure to update the tests accordingly
58
63
  BSNeo3Constants.DEFAULT_NETWORK = _a.MAINNET_NETWORKS[0];
59
64
  BSNeo3Constants.NEO_NS_HASH = '0x50ac1c37690cc2cfc594472833cf57505d5f46de';
60
65
  BSNeo3Constants.DEFAULT_BIP44_DERIVATION_PATH = "m/44'/888'/0'/0/?";
61
- BSNeo3Constants.NATIVE_ASSETS = native_json_1.default;
@@ -1,14 +1,8 @@
1
1
  import { Network } from '@cityofzion/blockchain-service';
2
2
  import { BSNeo3NetworkId } from '../constants/BSNeo3Constants';
3
3
  export declare class BSNeo3Helper {
4
- static getTokens(network: Network<BSNeo3NetworkId>): {
5
- symbol: string;
6
- name: string;
7
- hash: string;
8
- decimals: number;
9
- }[];
4
+ static getTokens(network: Network<BSNeo3NetworkId>): import("@cityofzion/blockchain-service").Token[];
10
5
  static getRpcList(network: Network<BSNeo3NetworkId>): string[];
11
6
  static isMainnet(network: Network<BSNeo3NetworkId>): boolean;
12
7
  static isCustomNet(network: Network<BSNeo3NetworkId>): boolean;
13
- static normalizeHash(hash: string): string;
14
8
  }
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.BSNeo3Helper = void 0;
7
- const blockchain_service_1 = require("@cityofzion/blockchain-service");
8
- const native_json_1 = __importDefault(require("../assets/tokens/native.json"));
9
4
  const BSNeo3Constants_1 = require("../constants/BSNeo3Constants");
10
5
  class BSNeo3Helper {
11
6
  static getTokens(network) {
12
7
  var _a;
13
8
  const extraTokens = (_a = BSNeo3Constants_1.BSNeo3Constants.EXTRA_TOKENS_BY_NETWORK_ID[network.id]) !== null && _a !== void 0 ? _a : [];
14
- return [...extraTokens, ...native_json_1.default];
9
+ return [...extraTokens, ...BSNeo3Constants_1.BSNeo3Constants.NATIVE_ASSETS];
15
10
  }
16
11
  static getRpcList(network) {
17
12
  var _a;
@@ -23,8 +18,5 @@ class BSNeo3Helper {
23
18
  static isCustomNet(network) {
24
19
  return !BSNeo3Constants_1.BSNeo3Constants.ALL_NETWORK_IDS.includes(network.id);
25
20
  }
26
- static normalizeHash(hash) {
27
- return (0, blockchain_service_1.normalizeHash)(hash, { lowercase: false });
28
- }
29
21
  }
30
22
  exports.BSNeo3Helper = BSNeo3Helper;
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './services/explorer/DoraESNeo3';
8
8
  export * from './services/ledger/NeonDappKitLedgerServiceNeo3';
9
9
  export * from './services/nft-data/GhostMarketNDSNeo3';
10
10
  export * from './services/nft-data/RpcNDSNeo3';
11
+ export * from './interfaces';
package/dist/index.js CHANGED
@@ -24,3 +24,4 @@ __exportStar(require("./services/explorer/DoraESNeo3"), exports);
24
24
  __exportStar(require("./services/ledger/NeonDappKitLedgerServiceNeo3"), exports);
25
25
  __exportStar(require("./services/nft-data/GhostMarketNDSNeo3"), exports);
26
26
  __exportStar(require("./services/nft-data/RpcNDSNeo3"), exports);
27
+ __exportStar(require("./interfaces"), exports);
@@ -5,7 +5,7 @@ export type GenerateSigningCallbackResponse = {
5
5
  neonJsAccount: Neon.wallet.Account;
6
6
  signingCallback: api.SigningFunction;
7
7
  };
8
- type Candidate = {
8
+ export type Candidate = {
9
9
  position: number;
10
10
  name: string;
11
11
  description: string;
@@ -20,9 +20,10 @@ type Candidate = {
20
20
  };
21
21
  export type GetCandidatesToVoteResponse = Candidate[];
22
22
  export type GetVoteDetailsByAddressResponse = {
23
- candidateName: string;
24
- candidatePubKey: string;
23
+ candidateName?: string;
24
+ candidatePubKey?: string;
25
25
  neoBalance: number;
26
+ address: string;
26
27
  };
27
28
  export type VoteParams<BSName extends string> = {
28
29
  account: Account<BSName>;
@@ -38,4 +39,3 @@ export interface VoteService<BSName extends string> {
38
39
  vote(params: VoteParams<BSName>): Promise<VoteResponse>;
39
40
  calculateVoteFee(params: CalculateVoteFeeParams<BSName>): Promise<string>;
40
41
  }
41
- export {};
@@ -1,6 +1,8 @@
1
1
  import { BalanceResponse, ContractResponse, FullTransactionsByAddressParams, FullTransactionsByAddressResponse, Network, NftDataService, Token, TransactionResponse, TransactionsByAddressParams, TransactionsByAddressResponse, ExplorerService, ExportTransactionsByAddressParams } from '@cityofzion/blockchain-service';
2
+ import { api } from '@cityofzion/dora-ts';
2
3
  import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
3
4
  import { RpcBDSNeo3 } from './RpcBDSNeo3';
5
+ export declare const DoraNeoRest: api.NeoRESTApi;
4
6
  export declare class DoraBDSNeo3 extends RpcBDSNeo3 {
5
7
  #private;
6
8
  constructor(network: Network<BSNeo3NetworkId>, feeToken: Token, claimToken: Token, tokens: Token[], nftDataService: NftDataService, explorerService: ExplorerService);
@@ -32,13 +32,13 @@ var __rest = (this && this.__rest) || function (s, e) {
32
32
  };
33
33
  var _DoraBDSNeo3_instances, _DoraBDSNeo3_supportedNep11Standards, _DoraBDSNeo3_nftDataService, _DoraBDSNeo3_explorerService, _DoraBDSNeo3_validateAddress, _DoraBDSNeo3_validateFullTransactionsByAddressParams, _DoraBDSNeo3_validateGetFullTransactionsByAddressParams;
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.DoraBDSNeo3 = void 0;
35
+ exports.DoraBDSNeo3 = exports.DoraNeoRest = void 0;
36
36
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
37
37
  const dora_ts_1 = require("@cityofzion/dora-ts");
38
38
  const neon_js_1 = require("@cityofzion/neon-js");
39
39
  const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
40
40
  const RpcBDSNeo3_1 = require("./RpcBDSNeo3");
41
- const NeoRest = new dora_ts_1.api.NeoRESTApi({
41
+ exports.DoraNeoRest = new dora_ts_1.api.NeoRESTApi({
42
42
  doraUrl: blockchain_service_1.BSCommonConstants.DORA_URL,
43
43
  endpoint: '/api/v2/neo3',
44
44
  });
@@ -62,14 +62,15 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
62
62
  return yield _super.getTransaction.call(this, hash);
63
63
  }
64
64
  try {
65
- const data = yield NeoRest.transaction(hash, this._network.id);
65
+ const data = yield exports.DoraNeoRest.transaction(hash, this._network.id);
66
+ const systemFeeNumber = blockchain_service_1.BSBigNumberHelper.fromNumber((_a = data.sysfee) !== null && _a !== void 0 ? _a : 0);
67
+ const networkFeeNumber = blockchain_service_1.BSBigNumberHelper.fromNumber((_b = data.netfee) !== null && _b !== void 0 ? _b : 0);
68
+ const totalFee = systemFeeNumber.plus(networkFeeNumber);
66
69
  return {
67
70
  block: data.block,
68
71
  time: Number(data.time),
69
72
  hash: data.hash,
70
- fee: neon_js_1.u.BigInteger.fromNumber((_a = data.netfee) !== null && _a !== void 0 ? _a : 0)
71
- .add(neon_js_1.u.BigInteger.fromNumber((_b = data.sysfee) !== null && _b !== void 0 ? _b : 0))
72
- .toDecimal(this._feeToken.decimals),
73
+ fee: blockchain_service_1.BSBigNumberHelper.format(totalFee, { decimals: this._feeToken.decimals }),
73
74
  notifications: [],
74
75
  transfers: [],
75
76
  };
@@ -87,7 +88,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
87
88
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network)) {
88
89
  return yield _super.getTransactionsByAddress.call(this, { address, nextPageParams });
89
90
  }
90
- const data = yield NeoRest.addressTXFull(address, nextPageParams, this._network.id);
91
+ const data = yield exports.DoraNeoRest.addressTXFull(address, nextPageParams, this._network.id);
91
92
  const promises = data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
92
93
  var _a, _b;
93
94
  const transferPromises = [];
@@ -130,13 +131,14 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
130
131
  eventName: notification.event_name,
131
132
  state: notification.state,
132
133
  }));
134
+ const systemFeeNumber = blockchain_service_1.BSBigNumberHelper.fromNumber((_a = item.sysfee) !== null && _a !== void 0 ? _a : 0);
135
+ const networkFeeNumber = blockchain_service_1.BSBigNumberHelper.fromNumber((_b = item.netfee) !== null && _b !== void 0 ? _b : 0);
136
+ const totalFee = systemFeeNumber.plus(networkFeeNumber);
133
137
  return {
134
138
  block: item.block,
135
139
  time: Number(item.time),
136
140
  hash: item.hash,
137
- fee: neon_js_1.u.BigInteger.fromNumber((_a = item.netfee) !== null && _a !== void 0 ? _a : 0)
138
- .add(neon_js_1.u.BigInteger.fromNumber((_b = item.sysfee) !== null && _b !== void 0 ? _b : 0))
139
- .toDecimal(this._feeToken.decimals),
141
+ fee: blockchain_service_1.BSBigNumberHelper.format(totalFee, { decimals: this._feeToken.decimals }),
140
142
  transfers,
141
143
  notifications,
142
144
  };
@@ -156,7 +158,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
156
158
  return __awaiter(this, void 0, void 0, function* () {
157
159
  __classPrivateFieldGet(this, _DoraBDSNeo3_instances, "m", _DoraBDSNeo3_validateGetFullTransactionsByAddressParams).call(this, params);
158
160
  const data = [];
159
- const response = yield NeoRest.getFullTransactionsByAddress({
161
+ const response = yield exports.DoraNeoRest.getFullTransactionsByAddress({
160
162
  address: params.address,
161
163
  timestampFrom: params.dateFrom,
162
164
  timestampTo: params.dateTo,
@@ -180,10 +182,10 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
180
182
  invocationCount: item.invocationCount,
181
183
  notificationCount: item.notificationCount,
182
184
  networkFeeAmount: networkFeeAmount
183
- ? blockchain_service_1.BSNumberHelper.formatNumber(networkFeeAmount, { decimals: this._feeToken.decimals })
185
+ ? blockchain_service_1.BSBigNumberHelper.format(networkFeeAmount, { decimals: this._feeToken.decimals })
184
186
  : undefined,
185
187
  systemFeeAmount: systemFeeAmount
186
- ? blockchain_service_1.BSNumberHelper.formatNumber(systemFeeAmount, { decimals: this._feeToken.decimals })
188
+ ? blockchain_service_1.BSBigNumberHelper.format(systemFeeAmount, { decimals: this._feeToken.decimals })
187
189
  : undefined,
188
190
  events: [],
189
191
  };
@@ -222,11 +224,10 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
222
224
  }
223
225
  else {
224
226
  const [token] = yield blockchain_service_1.BSPromisesHelper.tryCatch(() => this.getTokenInfo(hash));
225
- const { amount } = event;
226
227
  assetEvent = {
227
228
  eventType: 'token',
228
- amount: amount
229
- ? blockchain_service_1.BSNumberHelper.formatNumber(amount, { decimals: (_k = token === null || token === void 0 ? void 0 : token.decimals) !== null && _k !== void 0 ? _k : event.tokenDecimals })
229
+ amount: event.amount
230
+ ? blockchain_service_1.BSBigNumberHelper.format(event.amount, { decimals: (_k = token === null || token === void 0 ? void 0 : token.decimals) !== null && _k !== void 0 ? _k : event.tokenDecimals })
230
231
  : undefined,
231
232
  methodName,
232
233
  from,
@@ -251,7 +252,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
251
252
  exportFullTransactionsByAddress(params) {
252
253
  return __awaiter(this, void 0, void 0, function* () {
253
254
  __classPrivateFieldGet(this, _DoraBDSNeo3_instances, "m", _DoraBDSNeo3_validateFullTransactionsByAddressParams).call(this, params);
254
- return yield NeoRest.exportFullTransactionsByAddress({
255
+ return yield exports.DoraNeoRest.exportFullTransactionsByAddress({
255
256
  address: params.address,
256
257
  timestampFrom: params.dateFrom,
257
258
  timestampTo: params.dateTo,
@@ -269,7 +270,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
269
270
  return yield _super.getContract.call(this, contractHash);
270
271
  }
271
272
  try {
272
- const data = yield NeoRest.contract(contractHash, this._network.id);
273
+ const data = yield exports.DoraNeoRest.contract(contractHash, this._network.id);
273
274
  return {
274
275
  hash: data.hash,
275
276
  methods: (_b = (_a = data.manifest.abi) === null || _a === void 0 ? void 0 : _a.methods) !== null && _b !== void 0 ? _b : [],
@@ -289,20 +290,21 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
289
290
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network)) {
290
291
  return yield _super.getTokenInfo.call(this, tokenHash);
291
292
  }
292
- const localToken = this._tokens.find(token => token.hash === tokenHash);
293
- if (localToken)
294
- return localToken;
295
- if (this._tokenCache.has(tokenHash)) {
296
- return this._tokenCache.get(tokenHash);
297
- }
298
293
  try {
299
- const { decimals, symbol, name, scripthash } = yield NeoRest.asset(tokenHash, this._network.id);
300
- const token = {
301
- decimals: Number(decimals),
302
- symbol,
303
- name,
304
- hash: scripthash,
305
- };
294
+ const cachedToken = this._tokenCache.get(tokenHash);
295
+ if (cachedToken) {
296
+ return cachedToken;
297
+ }
298
+ let token = this._tokens.find(blockchain_service_1.BSTokenHelper.predicateByHash(tokenHash));
299
+ if (!token) {
300
+ const { decimals, symbol, name, scripthash } = yield exports.DoraNeoRest.asset(tokenHash, this._network.id);
301
+ token = blockchain_service_1.BSTokenHelper.normalizeToken({
302
+ decimals: Number(decimals),
303
+ symbol,
304
+ name,
305
+ hash: scripthash,
306
+ });
307
+ }
306
308
  this._tokenCache.set(tokenHash, token);
307
309
  return token;
308
310
  }
@@ -319,7 +321,7 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
319
321
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network)) {
320
322
  return yield _super.getBalance.call(this, address);
321
323
  }
322
- const response = yield NeoRest.balance(address, this._network.id);
324
+ const response = yield exports.DoraNeoRest.balance(address, this._network.id);
323
325
  const promises = response.map((balance) => __awaiter(this, void 0, void 0, function* () {
324
326
  try {
325
327
  const token = yield this.getTokenInfo(balance.asset);
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RpcBDSNeo3 = void 0;
13
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
13
14
  const neon_core_1 = require("@cityofzion/neon-core");
14
15
  const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
15
16
  const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
@@ -85,40 +86,41 @@ class RpcBDSNeo3 {
85
86
  }
86
87
  getTokenInfo(tokenHash) {
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
- const localToken = this._tokens.find(token => BSNeo3Helper_1.BSNeo3Helper.normalizeHash(token.hash) === BSNeo3Helper_1.BSNeo3Helper.normalizeHash(tokenHash));
89
- if (localToken)
90
- return localToken;
91
- if (this._tokenCache.has(tokenHash)) {
92
- return this._tokenCache.get(tokenHash);
93
- }
94
89
  try {
95
- const rpcClient = new neon_core_1.rpc.RPCClient(this._network.url);
96
- const contractState = yield rpcClient.getContractState(tokenHash);
97
- const invoker = yield neon_dappkit_1.NeonInvoker.init({
98
- rpcAddress: this._network.url,
99
- });
100
- const response = yield invoker.testInvoke({
101
- invocations: [
102
- {
103
- scriptHash: tokenHash,
104
- operation: 'decimals',
105
- args: [],
106
- },
107
- { scriptHash: tokenHash, operation: 'symbol', args: [] },
108
- ],
109
- });
110
- if (!neon_dappkit_1.TypeChecker.isStackTypeInteger(response.stack[0]))
111
- throw new Error('Invalid decimals');
112
- if (!neon_dappkit_1.TypeChecker.isStackTypeByteString(response.stack[1]))
113
- throw new Error('Invalid symbol');
114
- const decimals = Number(response.stack[0].value);
115
- const symbol = neon_core_1.u.base642utf8(response.stack[1].value);
116
- const token = {
117
- name: contractState.manifest.name,
118
- symbol,
119
- hash: contractState.hash,
120
- decimals,
121
- };
90
+ const cachedToken = this._tokenCache.get(tokenHash);
91
+ if (cachedToken) {
92
+ return cachedToken;
93
+ }
94
+ let token = this._tokens.find(blockchain_service_1.BSTokenHelper.predicateByHash(tokenHash));
95
+ if (!token) {
96
+ const rpcClient = new neon_core_1.rpc.RPCClient(this._network.url);
97
+ const contractState = yield rpcClient.getContractState(tokenHash);
98
+ const invoker = yield neon_dappkit_1.NeonInvoker.init({
99
+ rpcAddress: this._network.url,
100
+ });
101
+ const response = yield invoker.testInvoke({
102
+ invocations: [
103
+ {
104
+ scriptHash: tokenHash,
105
+ operation: 'decimals',
106
+ args: [],
107
+ },
108
+ { scriptHash: tokenHash, operation: 'symbol', args: [] },
109
+ ],
110
+ });
111
+ if (!neon_dappkit_1.TypeChecker.isStackTypeInteger(response.stack[0]))
112
+ throw new Error('Invalid decimals');
113
+ if (!neon_dappkit_1.TypeChecker.isStackTypeByteString(response.stack[1]))
114
+ throw new Error('Invalid symbol');
115
+ const decimals = Number(response.stack[0].value);
116
+ const symbol = neon_core_1.u.base642utf8(response.stack[1].value);
117
+ token = blockchain_service_1.BSTokenHelper.normalizeToken({
118
+ name: contractState.manifest.name,
119
+ symbol,
120
+ hash: contractState.hash,
121
+ decimals,
122
+ });
123
+ }
122
124
  this._tokenCache.set(tokenHash, token);
123
125
  return token;
124
126
  }
@@ -24,17 +24,17 @@ class DoraESNeo3 {
24
24
  buildTransactionUrl(hash) {
25
25
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(__classPrivateFieldGet(this, _DoraESNeo3_network, "f")))
26
26
  throw new Error('DoraESNeo3 is only available on mainnet and testnet');
27
- return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/transaction/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${hash}`;
27
+ return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/transaction/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${blockchain_service_1.BSTokenHelper.normalizeHash(hash)}`;
28
28
  }
29
29
  buildContractUrl(contractHash) {
30
30
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(__classPrivateFieldGet(this, _DoraESNeo3_network, "f")))
31
31
  throw new Error('DoraESNeo3 is only available on mainnet and testnet');
32
- return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/contract/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${contractHash}`;
32
+ return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/contract/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${blockchain_service_1.BSTokenHelper.normalizeHash(contractHash)}`;
33
33
  }
34
34
  buildNftUrl({ contractHash, tokenId }) {
35
35
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(__classPrivateFieldGet(this, _DoraESNeo3_network, "f")))
36
36
  throw new Error('DoraESNeo3 is only available on mainnet and testnet');
37
- return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/nft/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${contractHash}/${tokenId}`;
37
+ return `${__classPrivateFieldGet(this, _DoraESNeo3_BASE_URL, "f")}/nft/neo3/${__classPrivateFieldGet(this, _DoraESNeo3_network, "f").id}/${blockchain_service_1.BSTokenHelper.normalizeHash(contractHash)}/${tokenId}`;
38
38
  }
39
39
  getAddressTemplateUrl() {
40
40
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(__classPrivateFieldGet(this, _DoraESNeo3_network, "f")))
@@ -0,0 +1,16 @@
1
+ import { INeo3NeoXBridgeService, TNeo3NeoXBridgeServiceBridgeParam, TNeo3NeoXBridgeServiceCalculateMaxAmountParams, TNeo3NeoXBridgeServiceValidatedInputs, TNeo3NeoXBridgeServiceValidateInputParams, TNeo3NeoXBridgeServiceWaitParams } from '@cityofzion/blockchain-service';
2
+ import { BSNeo3 } from '../../BSNeo3';
3
+ export declare class Neo3NeoXBridgeService<BSName extends string = string> implements INeo3NeoXBridgeService<BSName> {
4
+ #private;
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";
10
+ constructor(service: BSNeo3<BSName>);
11
+ calculateMaxAmount({ account, balances, receiverAddress, token, }: TNeo3NeoXBridgeServiceCalculateMaxAmountParams<BSName>): Promise<string>;
12
+ calculateFee(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
13
+ bridge(params: TNeo3NeoXBridgeServiceBridgeParam<BSName>): Promise<string>;
14
+ validateInputs(params: TNeo3NeoXBridgeServiceValidateInputParams<BSName>): Promise<TNeo3NeoXBridgeServiceValidatedInputs>;
15
+ wait(params: TNeo3NeoXBridgeServiceWaitParams): Promise<boolean>;
16
+ }
@@ -0,0 +1,302 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ var _Neo3NeoXBridgeService_instances, _Neo3NeoXBridgeService_service, _Neo3NeoXBridgeService_buildGasCIM, _Neo3NeoXBridgeService_buildNeoCIM, _Neo3NeoXBridgeService_buildCIM, _Neo3NeoXBridgeService_validateGas, _Neo3NeoXBridgeService_validateNeo;
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.Neo3NeoXBridgeService = void 0;
28
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
29
+ const BSNeo3Constants_1 = require("../../constants/BSNeo3Constants");
30
+ const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
31
+ const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
32
+ const DoraBDSNeo3_1 = require("../blockchain-data/DoraBDSNeo3");
33
+ const axios_1 = __importDefault(require("axios"));
34
+ class Neo3NeoXBridgeService {
35
+ constructor(service) {
36
+ _Neo3NeoXBridgeService_instances.add(this);
37
+ 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
+ _Neo3NeoXBridgeService_service.set(this, void 0);
43
+ __classPrivateFieldSet(this, _Neo3NeoXBridgeService_service, service, "f");
44
+ }
45
+ calculateMaxAmount({ account, balances, receiverAddress, token, }) {
46
+ 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;
67
+ });
68
+ }
69
+ calculateFee(params) {
70
+ 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();
83
+ }
84
+ catch (error) {
85
+ throw new blockchain_service_1.BSError(error.message, 'FEE_CALCULATION_ERROR');
86
+ }
87
+ });
88
+ }
89
+ bridge(params) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
92
+ throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
93
+ const { account } = params;
94
+ const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").generateSigningCallback(account);
95
+ const invoker = yield neon_dappkit_1.NeonInvoker.init({
96
+ rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
97
+ account: neonJsAccount,
98
+ signingCallback: signingCallback,
99
+ });
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
+ {
179
+ scriptHash: this.BRIDGE_SCRIPT_HASH,
180
+ operation: 'depositNative',
181
+ args: [
182
+ { type: 'Hash160', value: neonJsAccount.address },
183
+ { type: 'Hash160', value: receiverAddress },
184
+ {
185
+ type: 'Integer',
186
+ value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(validatedInputs.receiveAmount), validatedInputs.token.decimals),
187
+ },
188
+ {
189
+ type: 'Integer',
190
+ value: blockchain_service_1.BSBigNumberHelper.toDecimals(blockchain_service_1.BSBigNumberHelper.fromNumber(this.BRIDGE_GAS_FEE), BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals),
191
+ },
192
+ ],
193
+ },
194
+ ],
195
+ signers: [
196
+ {
197
+ scopes: 16,
198
+ 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);
234
+ }
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,
259
+ });
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,
296
+ });
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
+ };
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  var _GhostMarketNDSNeo3_instances, _GhostMarketNDSNeo3_network, _GhostMarketNDSNeo3_treatGhostMarketImage, _GhostMarketNDSNeo3_getUrlWithParams, _GhostMarketNDSNeo3_parse;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.GhostMarketNDSNeo3 = void 0;
28
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
28
29
  const axios_1 = __importDefault(require("axios"));
29
30
  const query_string_1 = __importDefault(require("query-string"));
30
31
  const RpcNDSNeo3_1 = require("./RpcNDSNeo3");
@@ -51,7 +52,7 @@ class GhostMarketNDSNeo3 extends RpcNDSNeo3_1.RpcNDSNeo3 {
51
52
  getNft({ contractHash, tokenId }) {
52
53
  return __awaiter(this, void 0, void 0, function* () {
53
54
  const url = __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_getUrlWithParams).call(this, {
54
- contract: contractHash,
55
+ contract: blockchain_service_1.BSTokenHelper.normalizeHash(contractHash),
55
56
  tokenIds: [tokenId],
56
57
  });
57
58
  const { data } = yield axios_1.default.get(url);
@@ -82,7 +83,7 @@ _GhostMarketNDSNeo3_network = new WeakMap(), _GhostMarketNDSNeo3_instances = new
82
83
  const nftResponse = {
83
84
  collectionImage: __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_treatGhostMarketImage).call(this, (_a = data.collection) === null || _a === void 0 ? void 0 : _a.logoUrl),
84
85
  id: data.tokenId,
85
- contractHash: data.contract.hash,
86
+ contractHash: blockchain_service_1.BSTokenHelper.normalizeHash(data.contract.hash),
86
87
  symbol: data.contract.symbol,
87
88
  collectionName: (_b = data.collection) === null || _b === void 0 ? void 0 : _b.name,
88
89
  image: __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_treatGhostMarketImage).call(this, data.metadata.mediaUri),
@@ -73,6 +73,7 @@ class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
73
73
  });
74
74
  }
75
75
  getVoteDetailsByAddress(address) {
76
+ var _a, _b;
76
77
  return __awaiter(this, void 0, void 0, function* () {
77
78
  if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").network))
78
79
  throw new Error('Only Mainnet is supported');
@@ -80,13 +81,12 @@ class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
80
81
  throw new Error('Missing address');
81
82
  if (!__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").validateAddress(address))
82
83
  throw new Error('Invalid address');
83
- const _a = (yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get(`/mainnet/voter/${address}`)).data, { candidatePubkey } = _a, data = __rest(_a, ["candidatePubkey"]);
84
- if (!candidatePubkey)
85
- throw new Error('There was a problem to get vote details by address');
84
+ const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get(`/mainnet/voter/${address}`);
86
85
  return {
87
- candidateName: data.candidate,
88
- candidatePubKey: candidatePubkey,
86
+ candidateName: (_a = data.candidate) !== null && _a !== void 0 ? _a : undefined,
87
+ candidatePubKey: (_b = data.candidatePubkey) !== null && _b !== void 0 ? _b : undefined,
89
88
  neoBalance: data.balance,
89
+ address,
90
90
  };
91
91
  });
92
92
  }
@@ -24,8 +24,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.RpcVoteServiceNeo3 = void 0;
25
25
  const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
26
26
  const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
27
- const blockchain_service_1 = require("@cityofzion/blockchain-service");
28
27
  const neon_js_1 = require("@cityofzion/neon-js");
28
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
29
29
  class RpcVoteServiceNeo3 {
30
30
  constructor(service) {
31
31
  _RpcVoteServiceNeo3_instances.add(this);
@@ -66,7 +66,7 @@ class RpcVoteServiceNeo3 {
66
66
  address: account.address,
67
67
  candidatePubKey,
68
68
  }));
69
- return blockchain_service_1.BSNumberHelper.formatNumber(total, { decimals: __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").feeToken.decimals });
69
+ return blockchain_service_1.BSBigNumberHelper.format(total, { decimals: __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").feeToken.decimals });
70
70
  });
71
71
  }
72
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.14.1",
3
+ "version": "1.15.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -21,7 +21,7 @@
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.18.2",
24
+ "@cityofzion/blockchain-service": "1.19.0",
25
25
  "@cityofzion/bs-asteroid-sdk": "0.9.1"
26
26
  },
27
27
  "devDependencies": {