@cityofzion/bs-neo-legacy 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/.rush/temp/operation/build/all.log +1 -0
  2. package/.rush/temp/operation/build/state.json +3 -0
  3. package/.rush/temp/package-deps_build.json +6 -4
  4. package/.rush/temp/shrinkwrap-deps.json +350 -101
  5. package/CHANGELOG.json +22 -0
  6. package/CHANGELOG.md +11 -0
  7. package/bs-neo-legacy.build.log +1 -2
  8. package/dist/BSNeoLegacy.d.ts +24 -24
  9. package/dist/BSNeoLegacy.js +173 -173
  10. package/dist/CryptoCompareEDSNeoLegacy.d.ts +7 -7
  11. package/dist/CryptoCompareEDSNeoLegacy.js +51 -41
  12. package/dist/DoraBDSNeoLegacy.d.ts +16 -16
  13. package/dist/DoraBDSNeoLegacy.js +163 -163
  14. package/dist/DoraESNeoLegacy.d.ts +7 -7
  15. package/dist/DoraESNeoLegacy.js +17 -17
  16. package/dist/assets/tokens/common.json +18 -18
  17. package/dist/assets/tokens/mainnet.json +620 -620
  18. package/dist/constants.d.ts +13 -13
  19. package/dist/constants.js +23 -23
  20. package/dist/index.d.ts +4 -4
  21. package/dist/index.js +20 -20
  22. package/jest.config.ts +13 -13
  23. package/jest.setup.ts +1 -1
  24. package/package.json +26 -25
  25. package/src/BSNeoLegacy.ts +198 -198
  26. package/src/CryptoCompareEDSNeoLegacy.ts +50 -40
  27. package/src/DoraBDSNeoLegacy.ts +173 -173
  28. package/src/DoraESNeoLegacy.ts +18 -18
  29. package/src/__tests__/BDSNeoLegacy.spec.ts +120 -120
  30. package/src/__tests__/BSNeoLegacy.spec.ts +127 -127
  31. package/src/__tests__/CryptoCompareExchange.spec.ts +48 -46
  32. package/src/__tests__/DoraESNeoLegacy.spec.ts +15 -15
  33. package/src/assets/tokens/common.json +17 -17
  34. package/src/assets/tokens/mainnet.json +619 -619
  35. package/src/constants.ts +23 -23
  36. package/src/index.ts +4 -4
  37. package/tsconfig.build.json +4 -4
  38. package/tsconfig.json +14 -14
  39. package/dist/BDSNeoLegacy.d.ts +0 -15
  40. package/dist/BDSNeoLegacy.js +0 -199
  41. package/dist/asset/tokens.json +0 -480
  42. package/dist/explorer/dora/DoraResponsesNeoLegacy.d.ts +0 -95
  43. package/dist/explorer/dora/DoraResponsesNeoLegacy.js +0 -2
  44. package/dist/explorer/dora/DoraRoutesNeoLegacy.d.ts +0 -7
  45. package/dist/explorer/dora/DoraRoutesNeoLegacy.js +0 -10
  46. package/dist/explorer/index.d.ts +0 -6
  47. package/dist/explorer/index.js +0 -23
  48. package/docs/.nojekyll +0 -1
  49. package/docs/assets/highlight.css +0 -22
  50. package/docs/assets/main.js +0 -58
  51. package/docs/assets/search.js +0 -1
  52. package/docs/assets/style.css +0 -1280
  53. package/docs/classes/BDSNeoLegacy.html +0 -243
  54. package/docs/classes/BSNeoLegacy.html +0 -423
  55. package/docs/index.html +0 -70
  56. package/docs/interfaces/DoraNeoLegacyAsset.html +0 -103
  57. package/docs/interfaces/DoraNeoLegacyAssetResponse.html +0 -117
  58. package/docs/interfaces/DoraNeoLegacyBalance.html +0 -89
  59. package/docs/interfaces/DoraNeoLegacyConsensusNode.html +0 -75
  60. package/docs/interfaces/DoraNeoLegacyDetails.html +0 -138
  61. package/docs/interfaces/DoraNeoLegacyEntriesEntity.html +0 -110
  62. package/docs/interfaces/DoraNeoLegacyNameEntity.html +0 -75
  63. package/docs/interfaces/DoraNeoLegacyScriptsEntity.html +0 -75
  64. package/docs/interfaces/DoraNeoLegacyTransaction.html +0 -152
  65. package/docs/interfaces/DoraNeoLegacyTransactionsHistory.html +0 -96
  66. package/docs/interfaces/DoraNeoLegacyUnclaimed.html +0 -82
  67. package/docs/interfaces/DoraNeoLegacyVinEntity.html +0 -75
  68. package/docs/interfaces/DoraNeoLegacyVoutEntity.html +0 -89
  69. package/docs/modules.html +0 -98
  70. package/docs/variables/DORA_NEO_LEGACY_ASSET.html +0 -69
  71. package/docs/variables/DORA_NEO_LEGACY_BALANCE.html +0 -69
  72. package/docs/variables/DORA_NEO_LEGACY_CONTRACT.html +0 -69
  73. package/docs/variables/DORA_NEO_LEGACY_HISTORY_TRANSACTIONS.html +0 -69
  74. package/docs/variables/DORA_NEO_LEGACY_NODES.html +0 -69
  75. package/docs/variables/DORA_NEO_LEGACY_TRANSACTION.html +0 -69
  76. package/docs/variables/DORA_NEO_LEGACY_UNCLAIMED.html +0 -69
  77. package/docs/variables/explorerNeoLegacyOption.html +0 -74
package/CHANGELOG.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@cityofzion/bs-neo-legacy",
3
+ "entries": [
4
+ {
5
+ "version": "0.8.0",
6
+ "tag": "@cityofzion/bs-neo-legacy_v0.8.0",
7
+ "date": "Mon, 27 Nov 2023 22:13:46 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Inserted within the TokenPricesResponse type the token hash"
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.8.0`"
17
+ }
18
+ ]
19
+ }
20
+ }
21
+ ]
22
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log - @cityofzion/bs-neo-legacy
2
+
3
+ This log was last generated on Mon, 27 Nov 2023 22:13:46 GMT and should not be manually modified.
4
+
5
+ ## 0.8.0
6
+ Mon, 27 Nov 2023 22:13:46 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Inserted within the TokenPricesResponse type the token hash
11
+
@@ -1,2 +1 @@
1
- Invoking: tsc --project tsconfig.build.json
2
-
1
+ Invoking: tsc --project tsconfig.build.json
@@ -1,24 +1,24 @@
1
- import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, PartialBy, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
2
- export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithExplorerService {
3
- readonly blockchainName: BSCustomName;
4
- readonly feeToken: Token;
5
- readonly claimToken: Token;
6
- readonly burnToken: Token;
7
- readonly derivationPath: string;
8
- blockchainDataService: BlockchainDataService & BDSClaimable;
9
- exchangeDataService: ExchangeDataService;
10
- explorerService: ExplorerService;
11
- tokens: Token[];
12
- network: Network;
13
- legacyNetwork: string;
14
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
15
- setNetwork(param: PartialBy<Network, 'url'>): void;
16
- validateAddress(address: string): boolean;
17
- validateEncrypted(key: string): boolean;
18
- validateKey(key: string): boolean;
19
- generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
20
- generateAccountFromKey(key: string): Account;
21
- decrypt(encryptedKey: string, password: string): Promise<Account>;
22
- transfer({ intent: transferIntent, senderAccount, tipIntent, ...params }: TransferParam): Promise<string>;
23
- claim(account: Account): Promise<string>;
24
- }
1
+ import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, PartialBy, TransferParam, AccountWithDerivationPath, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
2
+ export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService, BSClaimable, BSWithExplorerService {
3
+ readonly blockchainName: BSCustomName;
4
+ readonly feeToken: Token;
5
+ readonly claimToken: Token;
6
+ readonly burnToken: Token;
7
+ readonly derivationPath: string;
8
+ blockchainDataService: BlockchainDataService & BDSClaimable;
9
+ exchangeDataService: ExchangeDataService;
10
+ explorerService: ExplorerService;
11
+ tokens: Token[];
12
+ network: Network;
13
+ legacyNetwork: string;
14
+ constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
15
+ setNetwork(param: PartialBy<Network, 'url'>): void;
16
+ validateAddress(address: string): boolean;
17
+ validateEncrypted(key: string): boolean;
18
+ validateKey(key: string): boolean;
19
+ generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
20
+ generateAccountFromKey(key: string): Account;
21
+ decrypt(encryptedKey: string, password: string): Promise<Account>;
22
+ transfer({ intent: transferIntent, senderAccount, tipIntent, ...params }: TransferParam): Promise<string>;
23
+ claim(account: Account): Promise<string>;
24
+ }
@@ -1,173 +1,173 @@
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 __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.BSNeoLegacy = void 0;
24
- const neon_js_1 = require("@cityofzion/neon-js");
25
- const constants_1 = require("./constants");
26
- const DoraBDSNeoLegacy_1 = require("./DoraBDSNeoLegacy");
27
- const CryptoCompareEDSNeoLegacy_1 = require("./CryptoCompareEDSNeoLegacy");
28
- const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
29
- const DoraESNeoLegacy_1 = require("./DoraESNeoLegacy");
30
- class BSNeoLegacy {
31
- constructor(blockchainName, network) {
32
- if (network.type === 'custom')
33
- throw new Error('Custom network is not supported for NEO Legacy');
34
- this.blockchainName = blockchainName;
35
- this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.type];
36
- this.derivationPath = constants_1.DERIVATION_PATH;
37
- this.tokens = constants_1.TOKENS[network.type];
38
- this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
39
- this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
40
- this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
41
- this.setNetwork(network);
42
- }
43
- setNetwork(param) {
44
- var _a;
45
- if (param.type === 'custom')
46
- throw new Error('Custom network is not supported for NEO Legacy');
47
- const network = {
48
- type: param.type,
49
- url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
50
- };
51
- this.network = network;
52
- this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken);
53
- this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.type);
54
- this.explorerService = new DoraESNeoLegacy_1.DoraESNeoLegacy(network.type);
55
- }
56
- validateAddress(address) {
57
- return neon_js_1.wallet.isAddress(address);
58
- }
59
- validateEncrypted(key) {
60
- return neon_js_1.wallet.isNEP2(key);
61
- }
62
- validateKey(key) {
63
- return neon_js_1.wallet.isWIF(key) || neon_js_1.wallet.isPrivateKey(key);
64
- }
65
- generateAccountFromMnemonic(mnemonic, index) {
66
- bs_asteroid_sdk_1.keychain.importMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic);
67
- const path = this.derivationPath.replace('?', index.toString());
68
- const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', path);
69
- const key = childKey.getWIF();
70
- const { address } = new neon_js_1.wallet.Account(key);
71
- return { address, key, type: 'wif', derivationPath: path };
72
- }
73
- generateAccountFromKey(key) {
74
- const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
75
- if (!type)
76
- throw new Error('Invalid key');
77
- const { address } = new neon_js_1.wallet.Account(key);
78
- return { address, key, type };
79
- }
80
- decrypt(encryptedKey, password) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- let BsReactNativeDecrypt;
83
- try {
84
- const { NativeModules } = require('react-native');
85
- BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
86
- }
87
- catch (_a) {
88
- const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
89
- return this.generateAccountFromKey(key);
90
- }
91
- if (!BsReactNativeDecrypt) {
92
- throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
93
- }
94
- const privateKey = yield BsReactNativeDecrypt.decryptNeoLegacy(encryptedKey, password);
95
- return this.generateAccountFromKey(privateKey);
96
- });
97
- }
98
- transfer(_a) {
99
- var _b, _c;
100
- var { intent: transferIntent, senderAccount, tipIntent } = _a, params = __rest(_a, ["intent", "senderAccount", "tipIntent"]);
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const apiProvider = new neon_js_1.api.neoCli.instance(this.network.url);
103
- const account = new neon_js_1.wallet.Account(senderAccount.key);
104
- const priorityFee = Number((_b = params.priorityFee) !== null && _b !== void 0 ? _b : 0);
105
- const nativeIntents = [];
106
- const nep5ScriptBuilder = new neon_js_1.sc.ScriptBuilder();
107
- const intents = [transferIntent, ...(tipIntent ? [tipIntent] : [])];
108
- for (const intent of intents) {
109
- const tokenHashFixed = intent.tokenHash.replace('0x', '');
110
- const nativeAsset = constants_1.NATIVE_ASSETS.find(asset => asset.hash === tokenHashFixed);
111
- if (nativeAsset) {
112
- nativeIntents.push(...neon_js_1.api.makeIntent({ [nativeAsset.symbol]: Number(intent.amount) }, intent.receiverAddress));
113
- continue;
114
- }
115
- nep5ScriptBuilder.emitAppCall(tokenHashFixed, 'transfer', [
116
- neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(account.address)),
117
- neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(intent.receiverAddress)),
118
- neon_js_1.sc.ContractParam.integer(new neon_js_1.u.Fixed8(intent.amount)
119
- .div(Math.pow(10, 8 - ((_c = intent.tokenDecimals) !== null && _c !== void 0 ? _c : 8)))
120
- .toRawNumber()
121
- .toString()),
122
- ]);
123
- }
124
- let response;
125
- if (nep5ScriptBuilder.isEmpty()) {
126
- response = yield neon_js_1.api.sendAsset({
127
- account,
128
- api: apiProvider,
129
- url: this.network.url,
130
- intents: nativeIntents,
131
- fees: priorityFee,
132
- });
133
- }
134
- else {
135
- response = yield neon_js_1.api.doInvoke({
136
- intents: nativeIntents.length > 0 ? nativeIntents : undefined,
137
- account,
138
- api: apiProvider,
139
- script: nep5ScriptBuilder.str,
140
- url: this.network.url,
141
- fees: priorityFee,
142
- });
143
- }
144
- if (!response.tx)
145
- throw new Error('Failed to send transaction');
146
- return response.tx.hash;
147
- });
148
- }
149
- claim(account) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const neoAccount = new neon_js_1.wallet.Account(account.key);
152
- const balances = yield this.blockchainDataService.getBalance(account.address);
153
- const neoBalance = balances.find(balance => balance.token.symbol === 'NEO');
154
- if (!neoBalance)
155
- throw new Error('It is necessary to have NEO to claim');
156
- const unclaimed = yield this.blockchainDataService.getUnclaimed(account.address);
157
- if (Number(unclaimed) <= 0)
158
- throw new Error(`Doesn't have gas to claim`);
159
- const apiProvider = new neon_js_1.api.neoCli.instance(this.legacyNetwork);
160
- const claims = yield apiProvider.getClaims(account.address);
161
- const response = yield neon_js_1.api.claimGas({
162
- claims,
163
- api: apiProvider,
164
- account: neoAccount,
165
- url: this.network.url,
166
- });
167
- if (!response.tx)
168
- throw new Error('Failed to claim');
169
- return response.tx.hash;
170
- });
171
- }
172
- }
173
- exports.BSNeoLegacy = BSNeoLegacy;
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 __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.BSNeoLegacy = void 0;
24
+ const neon_js_1 = require("@cityofzion/neon-js");
25
+ const constants_1 = require("./constants");
26
+ const DoraBDSNeoLegacy_1 = require("./DoraBDSNeoLegacy");
27
+ const CryptoCompareEDSNeoLegacy_1 = require("./CryptoCompareEDSNeoLegacy");
28
+ const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
29
+ const DoraESNeoLegacy_1 = require("./DoraESNeoLegacy");
30
+ class BSNeoLegacy {
31
+ constructor(blockchainName, network) {
32
+ if (network.type === 'custom')
33
+ throw new Error('Custom network is not supported for NEO Legacy');
34
+ this.blockchainName = blockchainName;
35
+ this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.type];
36
+ this.derivationPath = constants_1.DERIVATION_PATH;
37
+ this.tokens = constants_1.TOKENS[network.type];
38
+ this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
39
+ this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
40
+ this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
41
+ this.setNetwork(network);
42
+ }
43
+ setNetwork(param) {
44
+ var _a;
45
+ if (param.type === 'custom')
46
+ throw new Error('Custom network is not supported for NEO Legacy');
47
+ const network = {
48
+ type: param.type,
49
+ url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
50
+ };
51
+ this.network = network;
52
+ this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken);
53
+ this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.type);
54
+ this.explorerService = new DoraESNeoLegacy_1.DoraESNeoLegacy(network.type);
55
+ }
56
+ validateAddress(address) {
57
+ return neon_js_1.wallet.isAddress(address);
58
+ }
59
+ validateEncrypted(key) {
60
+ return neon_js_1.wallet.isNEP2(key);
61
+ }
62
+ validateKey(key) {
63
+ return neon_js_1.wallet.isWIF(key) || neon_js_1.wallet.isPrivateKey(key);
64
+ }
65
+ generateAccountFromMnemonic(mnemonic, index) {
66
+ bs_asteroid_sdk_1.keychain.importMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic);
67
+ const path = this.derivationPath.replace('?', index.toString());
68
+ const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', path);
69
+ const key = childKey.getWIF();
70
+ const { address } = new neon_js_1.wallet.Account(key);
71
+ return { address, key, type: 'wif', derivationPath: path };
72
+ }
73
+ generateAccountFromKey(key) {
74
+ const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
75
+ if (!type)
76
+ throw new Error('Invalid key');
77
+ const { address } = new neon_js_1.wallet.Account(key);
78
+ return { address, key, type };
79
+ }
80
+ decrypt(encryptedKey, password) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ let BsReactNativeDecrypt;
83
+ try {
84
+ const { NativeModules } = require('react-native');
85
+ BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
86
+ }
87
+ catch (_a) {
88
+ const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
89
+ return this.generateAccountFromKey(key);
90
+ }
91
+ if (!BsReactNativeDecrypt) {
92
+ throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
93
+ }
94
+ const privateKey = yield BsReactNativeDecrypt.decryptNeoLegacy(encryptedKey, password);
95
+ return this.generateAccountFromKey(privateKey);
96
+ });
97
+ }
98
+ transfer(_a) {
99
+ var _b, _c;
100
+ var { intent: transferIntent, senderAccount, tipIntent } = _a, params = __rest(_a, ["intent", "senderAccount", "tipIntent"]);
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const apiProvider = new neon_js_1.api.neoCli.instance(this.network.url);
103
+ const account = new neon_js_1.wallet.Account(senderAccount.key);
104
+ const priorityFee = Number((_b = params.priorityFee) !== null && _b !== void 0 ? _b : 0);
105
+ const nativeIntents = [];
106
+ const nep5ScriptBuilder = new neon_js_1.sc.ScriptBuilder();
107
+ const intents = [transferIntent, ...(tipIntent ? [tipIntent] : [])];
108
+ for (const intent of intents) {
109
+ const tokenHashFixed = intent.tokenHash.replace('0x', '');
110
+ const nativeAsset = constants_1.NATIVE_ASSETS.find(asset => asset.hash === tokenHashFixed);
111
+ if (nativeAsset) {
112
+ nativeIntents.push(...neon_js_1.api.makeIntent({ [nativeAsset.symbol]: Number(intent.amount) }, intent.receiverAddress));
113
+ continue;
114
+ }
115
+ nep5ScriptBuilder.emitAppCall(tokenHashFixed, 'transfer', [
116
+ neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(account.address)),
117
+ neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(intent.receiverAddress)),
118
+ neon_js_1.sc.ContractParam.integer(new neon_js_1.u.Fixed8(intent.amount)
119
+ .div(Math.pow(10, 8 - ((_c = intent.tokenDecimals) !== null && _c !== void 0 ? _c : 8)))
120
+ .toRawNumber()
121
+ .toString()),
122
+ ]);
123
+ }
124
+ let response;
125
+ if (nep5ScriptBuilder.isEmpty()) {
126
+ response = yield neon_js_1.api.sendAsset({
127
+ account,
128
+ api: apiProvider,
129
+ url: this.network.url,
130
+ intents: nativeIntents,
131
+ fees: priorityFee,
132
+ });
133
+ }
134
+ else {
135
+ response = yield neon_js_1.api.doInvoke({
136
+ intents: nativeIntents.length > 0 ? nativeIntents : undefined,
137
+ account,
138
+ api: apiProvider,
139
+ script: nep5ScriptBuilder.str,
140
+ url: this.network.url,
141
+ fees: priorityFee,
142
+ });
143
+ }
144
+ if (!response.tx)
145
+ throw new Error('Failed to send transaction');
146
+ return response.tx.hash;
147
+ });
148
+ }
149
+ claim(account) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ const neoAccount = new neon_js_1.wallet.Account(account.key);
152
+ const balances = yield this.blockchainDataService.getBalance(account.address);
153
+ const neoBalance = balances.find(balance => balance.token.symbol === 'NEO');
154
+ if (!neoBalance)
155
+ throw new Error('It is necessary to have NEO to claim');
156
+ const unclaimed = yield this.blockchainDataService.getUnclaimed(account.address);
157
+ if (Number(unclaimed) <= 0)
158
+ throw new Error(`Doesn't have gas to claim`);
159
+ const apiProvider = new neon_js_1.api.neoCli.instance(this.legacyNetwork);
160
+ const claims = yield apiProvider.getClaims(account.address);
161
+ const response = yield neon_js_1.api.claimGas({
162
+ claims,
163
+ api: apiProvider,
164
+ account: neoAccount,
165
+ url: this.network.url,
166
+ });
167
+ if (!response.tx)
168
+ throw new Error('Failed to claim');
169
+ return response.tx.hash;
170
+ });
171
+ }
172
+ }
173
+ exports.BSNeoLegacy = BSNeoLegacy;
@@ -1,7 +1,7 @@
1
- import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
- export declare class CryptoCompareEDSNeoLegacy implements ExchangeDataService {
3
- networkType: NetworkType;
4
- private axiosInstance;
5
- constructor(network: NetworkType);
6
- getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
- }
1
+ import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
2
+ export declare class CryptoCompareEDSNeoLegacy implements ExchangeDataService {
3
+ networkType: NetworkType;
4
+ private axiosInstance;
5
+ constructor(network: NetworkType);
6
+ getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
+ }
@@ -1,41 +1,51 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CryptoCompareEDSNeoLegacy = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const constants_1 = require("./constants");
18
- class CryptoCompareEDSNeoLegacy {
19
- constructor(network) {
20
- this.networkType = network;
21
- this.axiosInstance = axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' });
22
- }
23
- getTokenPrices(currency) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- if (this.networkType !== 'mainnet')
26
- throw new Error('Exchange is only available on mainnet');
27
- const tokenSymbols = constants_1.TOKENS[this.networkType].map(token => token.symbol);
28
- const { data: prices } = yield this.axiosInstance.get('/data/pricemultifull', {
29
- params: {
30
- fsyms: tokenSymbols.join(','),
31
- tsyms: currency,
32
- },
33
- });
34
- return Object.entries(prices.RAW).map(([symbol, price]) => ({
35
- symbol,
36
- price: price[currency].PRICE,
37
- }));
38
- });
39
- }
40
- }
41
- exports.CryptoCompareEDSNeoLegacy = CryptoCompareEDSNeoLegacy;
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CryptoCompareEDSNeoLegacy = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const constants_1 = require("./constants");
18
+ class CryptoCompareEDSNeoLegacy {
19
+ constructor(network) {
20
+ this.networkType = network;
21
+ this.axiosInstance = axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' });
22
+ }
23
+ getTokenPrices(currency) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ if (this.networkType !== 'mainnet')
26
+ throw new Error('Exchange is only available on mainnet');
27
+ const tokens = constants_1.TOKENS[this.networkType];
28
+ const tokenSymbols = tokens.map(token => token.symbol);
29
+ const { data: prices } = yield this.axiosInstance.get('/data/pricemultifull', {
30
+ params: {
31
+ fsyms: tokenSymbols.join(','),
32
+ tsyms: currency,
33
+ },
34
+ });
35
+ return Object.entries(prices.RAW)
36
+ .map(([symbol, priceObject]) => {
37
+ const price = priceObject[currency].PRICE;
38
+ const token = tokens.find(token => token.symbol === symbol);
39
+ if (!token || !price)
40
+ return;
41
+ return {
42
+ symbol,
43
+ price,
44
+ hash: token === null || token === void 0 ? void 0 : token.hash,
45
+ };
46
+ })
47
+ .filter((price) => price !== undefined);
48
+ });
49
+ }
50
+ }
51
+ exports.CryptoCompareEDSNeoLegacy = CryptoCompareEDSNeoLegacy;
@@ -1,16 +1,16 @@
1
- import { BalanceResponse, BlockchainDataService, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, BDSClaimable, Token, Network } from '@cityofzion/blockchain-service';
2
- export declare class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
3
- readonly network: Network;
4
- private readonly claimToken;
5
- private readonly feeToken;
6
- private readonly tokenCache;
7
- maxTimeToConfirmTransactionInMs: number;
8
- constructor(network: Network, feeToken: Token, claimToken: Token);
9
- getTransaction(hash: string): Promise<TransactionResponse>;
10
- getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
11
- getContract(contractHash: string): Promise<ContractResponse>;
12
- getTokenInfo(tokenHash: string): Promise<Token>;
13
- getBalance(address: string): Promise<BalanceResponse[]>;
14
- getUnclaimed(address: string): Promise<string>;
15
- getBlockHeight(): Promise<number>;
16
- }
1
+ import { BalanceResponse, BlockchainDataService, ContractResponse, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, BDSClaimable, Token, Network } from '@cityofzion/blockchain-service';
2
+ export declare class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
3
+ readonly network: Network;
4
+ private readonly claimToken;
5
+ private readonly feeToken;
6
+ private readonly tokenCache;
7
+ maxTimeToConfirmTransactionInMs: number;
8
+ constructor(network: Network, feeToken: Token, claimToken: Token);
9
+ getTransaction(hash: string): Promise<TransactionResponse>;
10
+ getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
11
+ getContract(contractHash: string): Promise<ContractResponse>;
12
+ getTokenInfo(tokenHash: string): Promise<Token>;
13
+ getBalance(address: string): Promise<BalanceResponse[]>;
14
+ getUnclaimed(address: string): Promise<string>;
15
+ getBlockHeight(): Promise<number>;
16
+ }