@cityofzion/bs-neo-legacy 0.7.0 → 0.7.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/.rush/temp/package-deps_build.json +21 -0
- package/bs-neo-legacy.build.log +1 -5
- package/dist/BSNeoLegacy.d.ts +20 -33
- package/dist/BSNeoLegacy.js +122 -168
- package/dist/CryptoCompareEDSNeoLegacy.d.ts +7 -0
- package/dist/CryptoCompareEDSNeoLegacy.js +41 -0
- package/dist/DoraBDSNeoLegacy.d.ts +15 -0
- package/dist/DoraBDSNeoLegacy.js +162 -0
- package/dist/assets/tokens/common.json +18 -0
- package/dist/assets/tokens/mainnet.json +620 -0
- package/dist/constants.d.ts +8 -5
- package/dist/constants.js +20 -17
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/package.json +3 -3
- package/bs-neo-legacy.build.error.log +0 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
"packages/bs-neo-legacy/jest.config.ts": "d944475db93cbe41a9339187fd94b9962e411c43",
|
|
4
|
+
"packages/bs-neo-legacy/jest.setup.ts": "9a1976a32050616d4d2ee95b1aa21041bc4daca3",
|
|
5
|
+
"packages/bs-neo-legacy/package.json": "c0b7d3d28174c6ce4652a442ad6b9485ee49f45c",
|
|
6
|
+
"packages/bs-neo-legacy/src/BSNeoLegacy.ts": "ce59dc999823497ba0f79ec31afb81aec1d29351",
|
|
7
|
+
"packages/bs-neo-legacy/src/CryptoCompareEDSNeoLegacy.ts": "7cbe7bf0e39f100edd329a9211006c3c1994a1c2",
|
|
8
|
+
"packages/bs-neo-legacy/src/DoraBDSNeoLegacy.ts": "3ac617c879987ae8106cb212c36523909fffe79d",
|
|
9
|
+
"packages/bs-neo-legacy/src/__tests__/BDSNeoLegacy.spec.ts": "04210ed3cc8b8afbc824417be87eac06d1f875fd",
|
|
10
|
+
"packages/bs-neo-legacy/src/__tests__/BSNeoLegacy.spec.ts": "b2cff48a43db986fc02fdefbfd66a5cd4d70a5d9",
|
|
11
|
+
"packages/bs-neo-legacy/src/__tests__/CryptoCompareExchange.spec.ts": "0aeb2e77cf1d3eabc7534d2b9cbc26e93240852d",
|
|
12
|
+
"packages/bs-neo-legacy/src/assets/tokens/common.json": "81b0a9bb3e6c1b5bb41f57e6b1fc403ce1ac1489",
|
|
13
|
+
"packages/bs-neo-legacy/src/assets/tokens/mainnet.json": "e1194b98d7a91a8494760d597a90c02e00880972",
|
|
14
|
+
"packages/bs-neo-legacy/src/constants.ts": "82e36146cf6cf3c16bc7b7ec4fd3e4089c745bd5",
|
|
15
|
+
"packages/bs-neo-legacy/src/index.ts": "247e7d072502350e685e11497aeedc89b7c921d5",
|
|
16
|
+
"packages/bs-neo-legacy/tsconfig.build.json": "4dc23fb9c4c5e4d19a9bc3947a47c523f4bd967c",
|
|
17
|
+
"packages/bs-neo-legacy/tsconfig.json": "77cf2b789e9c665b62792f9992cc81ae86296ef7",
|
|
18
|
+
"common/config/rush/npm-shrinkwrap.json": "4994dce94cedd11a678400d92e08741ac7bc9d3f"
|
|
19
|
+
},
|
|
20
|
+
"arguments": "tsc --project tsconfig.build.json "
|
|
21
|
+
}
|
package/bs-neo-legacy.build.log
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
Invoking: tsc
|
|
2
|
-
./src/BSNeoLegacy.ts:87:8 - warning TransactionIntentResponse is referenced by BSNeoLegacy.setTypeIntents.setTypeIntents but not included in the documentation.
|
|
1
|
+
Invoking: tsc --project tsconfig.build.json
|
|
3
2
|
|
|
4
|
-
87 type TransactionIntentResponse = IntentTransactionParam & { type: 'native' | 'nep5' }
|
|
5
|
-
|
|
6
|
-
Documentation generated at ./docs
|
package/dist/BSNeoLegacy.d.ts
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
import { Account, BDSClaimable, BlockchainDataService, BlockchainService,
|
|
2
|
-
export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
exchange: Exchange;
|
|
12
|
-
tokenClaim: {
|
|
13
|
-
hash: string;
|
|
14
|
-
symbol: string;
|
|
15
|
-
decimals: number;
|
|
16
|
-
};
|
|
1
|
+
import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, PartialBy, TransferParam, AccountWithDerivationPath } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare class BSNeoLegacy<BSCustomName extends string = string> implements BlockchainService, BSClaimable {
|
|
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;
|
|
17
10
|
tokens: Token[];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
constructor(blockchainName: BSCustomName);
|
|
21
|
-
|
|
22
|
-
private buildNativeTransaction;
|
|
23
|
-
private buildNep5Transaction;
|
|
24
|
-
private setTypeIntents;
|
|
25
|
-
private isNativeTransaction;
|
|
26
|
-
generateMnemonic(): string;
|
|
27
|
-
generateWif(mnemonic: string, index: number): string;
|
|
28
|
-
generateAccount(mnemonic: string, index: number): Account;
|
|
29
|
-
generateAccountFromWif(wif: string): string;
|
|
30
|
-
decryptKey(encryptedKey: string, password: string): Promise<Account>;
|
|
11
|
+
network: Network;
|
|
12
|
+
legacyNetwork: string;
|
|
13
|
+
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
14
|
+
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
31
15
|
validateAddress(address: string): boolean;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
validateEncrypted(key: string): boolean;
|
|
17
|
+
validateKey(key: string): boolean;
|
|
18
|
+
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
19
|
+
generateAccountFromKey(key: string): Account;
|
|
20
|
+
decrypt(encryptedKey: string, password: string): Promise<Account>;
|
|
21
|
+
transfer({ intent: transferIntent, senderAccount, tipIntent, ...params }: TransferParam): Promise<string>;
|
|
22
|
+
claim(account: Account): Promise<string>;
|
|
36
23
|
}
|
package/dist/BSNeoLegacy.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -42,175 +19,152 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
42
19
|
}
|
|
43
20
|
return t;
|
|
44
21
|
};
|
|
45
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
-
};
|
|
48
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
23
|
exports.BSNeoLegacy = void 0;
|
|
50
|
-
const AsteroidSDK = __importStar(require("@moonlight-io/asteroid-sdk-js"));
|
|
51
24
|
const neon_js_1 = require("@cityofzion/neon-js");
|
|
52
|
-
const explorer_1 = require("./explorer");
|
|
53
25
|
const constants_1 = require("./constants");
|
|
54
|
-
const
|
|
55
|
-
const
|
|
26
|
+
const DoraBDSNeoLegacy_1 = require("./DoraBDSNeoLegacy");
|
|
27
|
+
const CryptoCompareEDSNeoLegacy_1 = require("./CryptoCompareEDSNeoLegacy");
|
|
28
|
+
const bs_asteroid_sdk_1 = require("@cityofzion/bs-asteroid-sdk");
|
|
56
29
|
class BSNeoLegacy {
|
|
57
|
-
constructor(blockchainName) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.tokenClaim = neoToken;
|
|
61
|
-
this.tokens = tokens_json_1.default;
|
|
62
|
-
this.keychain = new AsteroidSDK.Keychain();
|
|
63
|
-
this.nativeAssets = constants_1.nativeAssetsNeoLegacy;
|
|
30
|
+
constructor(blockchainName, network) {
|
|
31
|
+
if (network.type === 'custom')
|
|
32
|
+
throw new Error('Custom network is not supported for NEO Legacy');
|
|
64
33
|
this.blockchainName = blockchainName;
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
this.legacyNetwork = constants_1.LEGACY_NETWORK_BY_NETWORK_TYPE[network.type];
|
|
35
|
+
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
36
|
+
this.tokens = constants_1.TOKENS[network.type];
|
|
37
|
+
this.claimToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
38
|
+
this.burnToken = this.tokens.find(token => token.symbol === 'NEO');
|
|
39
|
+
this.feeToken = this.tokens.find(token => token.symbol === 'GAS');
|
|
40
|
+
this.setNetwork(network);
|
|
41
|
+
}
|
|
42
|
+
setNetwork(param) {
|
|
67
43
|
var _a;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if ((gasBalance === null || gasBalance === void 0 ? void 0 : gasBalance.amount) < priorityFee)
|
|
78
|
-
throw new Error("Don't have funds to pay the transaction");
|
|
79
|
-
const transactionOperations = {
|
|
80
|
-
native: () => {
|
|
81
|
-
return neon_js_1.api.sendAsset({
|
|
82
|
-
account,
|
|
83
|
-
api: apiProvider,
|
|
84
|
-
url,
|
|
85
|
-
intents: this.buildNativeTransaction(param.transactionIntents),
|
|
86
|
-
fees: priorityFee
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
nep5: () => {
|
|
90
|
-
const extraIntentsNep5 = intentsWithTye.filter(it => it.type === 'native').map(it => {
|
|
91
|
-
const { type } = it, rest = __rest(it, ["type"]);
|
|
92
|
-
return rest;
|
|
93
|
-
});
|
|
94
|
-
return neon_js_1.api.doInvoke({
|
|
95
|
-
intents: extraIntentsNep5.length > 0 ? this.buildNativeTransaction(extraIntentsNep5) : undefined,
|
|
96
|
-
account,
|
|
97
|
-
api: apiProvider,
|
|
98
|
-
script: this.buildNep5Transaction(param.transactionIntents, param.senderAccount).str,
|
|
99
|
-
url,
|
|
100
|
-
fees: priorityFee
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const result = isNativeTransaction ? yield transactionOperations.native() : yield transactionOperations.nep5();
|
|
105
|
-
if (!result.tx)
|
|
106
|
-
throw new Error("Failed to send transaction");
|
|
107
|
-
return result.tx.hash;
|
|
108
|
-
});
|
|
44
|
+
if (param.type === 'custom')
|
|
45
|
+
throw new Error('Custom network is not supported for NEO Legacy');
|
|
46
|
+
const network = {
|
|
47
|
+
type: param.type,
|
|
48
|
+
url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
|
|
49
|
+
};
|
|
50
|
+
this.network = network;
|
|
51
|
+
this.blockchainDataService = new DoraBDSNeoLegacy_1.DoraBDSNeoLegacy(network, this.feeToken, this.claimToken);
|
|
52
|
+
this.exchangeDataService = new CryptoCompareEDSNeoLegacy_1.CryptoCompareEDSNeoLegacy(network.type);
|
|
109
53
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
transactionIntents.forEach(transaction => {
|
|
113
|
-
const nativeAsset = this.nativeAssets.find(asset => asset.hash === transaction.tokenHash);
|
|
114
|
-
if (nativeAsset) {
|
|
115
|
-
intents = [...intents, ...neon_js_1.api.makeIntent({ [nativeAsset.symbol]: transaction.amount }, transaction.receiverAddress)];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return intents;
|
|
119
|
-
}
|
|
120
|
-
buildNep5Transaction(transactionIntents, senderAccount) {
|
|
121
|
-
const sb = new neon_js_1.sc.ScriptBuilder();
|
|
122
|
-
transactionIntents.forEach(transaction => {
|
|
123
|
-
if (!this.isNativeTransaction(transaction)) {
|
|
124
|
-
const senderHash = neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(senderAccount.address));
|
|
125
|
-
const receiveHash = neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(transaction.receiverAddress));
|
|
126
|
-
const adjustedAmount = new neon_js_1.u.Fixed8(transaction.amount).toRawNumber();
|
|
127
|
-
sb.emitAppCall(transaction.tokenHash.replace('0x', ''), "transfer", [
|
|
128
|
-
senderHash,
|
|
129
|
-
receiveHash,
|
|
130
|
-
neon_js_1.sc.ContractParam.integer(adjustedAmount.toString())
|
|
131
|
-
]);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return sb;
|
|
135
|
-
}
|
|
136
|
-
setTypeIntents(transactionIntents) {
|
|
137
|
-
const intents = transactionIntents.map(transaction => {
|
|
138
|
-
return Object.assign(Object.assign({}, transaction), { type: this.isNativeTransaction(transaction) ? 'native' : 'nep5' });
|
|
139
|
-
});
|
|
140
|
-
return intents;
|
|
141
|
-
}
|
|
142
|
-
isNativeTransaction(transactionParam) {
|
|
143
|
-
return this.nativeAssets.some(asset => asset.hash === transactionParam.tokenHash);
|
|
54
|
+
validateAddress(address) {
|
|
55
|
+
return neon_js_1.wallet.isAddress(address);
|
|
144
56
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.keychain.generateMnemonic(128);
|
|
148
|
-
const list = (_a = this.keychain.mnemonic) === null || _a === void 0 ? void 0 : _a.toString();
|
|
149
|
-
if (!list)
|
|
150
|
-
throw new Error("Failed to generate mnemonic");
|
|
151
|
-
return list;
|
|
57
|
+
validateEncrypted(key) {
|
|
58
|
+
return neon_js_1.wallet.isNEP2(key);
|
|
152
59
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const childKey = this.keychain.generateChildKey('neo', this.derivationPath.replace('?', index.toString()));
|
|
156
|
-
return childKey.getWIF();
|
|
60
|
+
validateKey(key) {
|
|
61
|
+
return neon_js_1.wallet.isWIF(key) || neon_js_1.wallet.isPrivateKey(key);
|
|
157
62
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
|
|
63
|
+
generateAccountFromMnemonic(mnemonic, index) {
|
|
64
|
+
bs_asteroid_sdk_1.keychain.importMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic);
|
|
65
|
+
const path = this.derivationPath.replace('?', index.toString());
|
|
66
|
+
const childKey = bs_asteroid_sdk_1.keychain.generateChildKey('neo', path);
|
|
67
|
+
const key = childKey.getWIF();
|
|
68
|
+
const { address } = new neon_js_1.wallet.Account(key);
|
|
69
|
+
return { address, key, type: 'wif', derivationPath: path };
|
|
163
70
|
}
|
|
164
|
-
|
|
165
|
-
|
|
71
|
+
generateAccountFromKey(key) {
|
|
72
|
+
const type = neon_js_1.wallet.isWIF(key) ? 'wif' : neon_js_1.wallet.isPrivateKey(key) ? 'privateKey' : undefined;
|
|
73
|
+
if (!type)
|
|
74
|
+
throw new Error('Invalid key');
|
|
75
|
+
const { address } = new neon_js_1.wallet.Account(key);
|
|
76
|
+
return { address, key, type };
|
|
166
77
|
}
|
|
167
|
-
|
|
78
|
+
decrypt(encryptedKey, password) {
|
|
168
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
80
|
+
let BsReactNativeDecrypt;
|
|
81
|
+
try {
|
|
82
|
+
const { NativeModules } = require('react-native');
|
|
83
|
+
BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt;
|
|
84
|
+
}
|
|
85
|
+
catch (_a) {
|
|
86
|
+
const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
|
|
87
|
+
return this.generateAccountFromKey(key);
|
|
88
|
+
}
|
|
89
|
+
if (!BsReactNativeDecrypt) {
|
|
90
|
+
throw new Error('@CityOfZion/bs-react-native-decrypt is not installed');
|
|
91
|
+
}
|
|
92
|
+
const privateKey = yield BsReactNativeDecrypt.decryptNeoLegacy(encryptedKey, password);
|
|
93
|
+
return this.generateAccountFromKey(privateKey);
|
|
173
94
|
});
|
|
174
95
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
96
|
+
transfer(_a) {
|
|
97
|
+
var _b, _c;
|
|
98
|
+
var { intent: transferIntent, senderAccount, tipIntent } = _a, params = __rest(_a, ["intent", "senderAccount", "tipIntent"]);
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const apiProvider = new neon_js_1.api.neoCli.instance(this.network.url);
|
|
101
|
+
const account = new neon_js_1.wallet.Account(senderAccount.key);
|
|
102
|
+
const priorityFee = Number((_b = params.priorityFee) !== null && _b !== void 0 ? _b : 0);
|
|
103
|
+
const nativeIntents = [];
|
|
104
|
+
const nep5ScriptBuilder = new neon_js_1.sc.ScriptBuilder();
|
|
105
|
+
const intents = [transferIntent, ...(tipIntent ? [tipIntent] : [])];
|
|
106
|
+
for (const intent of intents) {
|
|
107
|
+
const tokenHashFixed = intent.tokenHash.replace('0x', '');
|
|
108
|
+
const nativeAsset = constants_1.NATIVE_ASSETS.find(asset => asset.hash === tokenHashFixed);
|
|
109
|
+
if (nativeAsset) {
|
|
110
|
+
nativeIntents.push(...neon_js_1.api.makeIntent({ [nativeAsset.symbol]: Number(intent.amount) }, intent.receiverAddress));
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
nep5ScriptBuilder.emitAppCall(tokenHashFixed, 'transfer', [
|
|
114
|
+
neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(account.address)),
|
|
115
|
+
neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(intent.receiverAddress)),
|
|
116
|
+
neon_js_1.sc.ContractParam.integer(new neon_js_1.u.Fixed8(intent.amount)
|
|
117
|
+
.div(Math.pow(10, 8 - ((_c = intent.tokenDecimals) !== null && _c !== void 0 ? _c : 8)))
|
|
118
|
+
.toRawNumber()
|
|
119
|
+
.toString()),
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
let response;
|
|
123
|
+
if (nep5ScriptBuilder.isEmpty()) {
|
|
124
|
+
response = yield neon_js_1.api.sendAsset({
|
|
125
|
+
account,
|
|
126
|
+
api: apiProvider,
|
|
127
|
+
url: this.network.url,
|
|
128
|
+
intents: nativeIntents,
|
|
129
|
+
fees: priorityFee,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
response = yield neon_js_1.api.doInvoke({
|
|
134
|
+
intents: nativeIntents.length > 0 ? nativeIntents : undefined,
|
|
135
|
+
account,
|
|
136
|
+
api: apiProvider,
|
|
137
|
+
script: nep5ScriptBuilder.str,
|
|
138
|
+
url: this.network.url,
|
|
139
|
+
fees: priorityFee,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (!response.tx)
|
|
143
|
+
throw new Error('Failed to send transaction');
|
|
144
|
+
return response.tx.hash;
|
|
145
|
+
});
|
|
186
146
|
}
|
|
187
|
-
//Implementation Claim interface
|
|
188
147
|
claim(account) {
|
|
189
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
const neoAccount = new neon_js_1.wallet.Account(account.
|
|
191
|
-
const balances = yield this.
|
|
192
|
-
const neoBalance = balances.find(balance => balance.symbol === 'NEO');
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const hasClaim = yield this.dataService.getUnclaimed(account.address);
|
|
198
|
-
if (hasClaim.unclaimed <= 0)
|
|
149
|
+
const neoAccount = new neon_js_1.wallet.Account(account.key);
|
|
150
|
+
const balances = yield this.blockchainDataService.getBalance(account.address);
|
|
151
|
+
const neoBalance = balances.find(balance => balance.token.symbol === 'NEO');
|
|
152
|
+
if (!neoBalance)
|
|
153
|
+
throw new Error('It is necessary to have NEO to claim');
|
|
154
|
+
const unclaimed = yield this.blockchainDataService.getUnclaimed(account.address);
|
|
155
|
+
if (Number(unclaimed) <= 0)
|
|
199
156
|
throw new Error(`Doesn't have gas to claim`);
|
|
200
|
-
const
|
|
201
|
-
const claims = yield
|
|
202
|
-
const
|
|
157
|
+
const apiProvider = new neon_js_1.api.neoCli.instance(this.legacyNetwork);
|
|
158
|
+
const claims = yield apiProvider.getClaims(account.address);
|
|
159
|
+
const response = yield neon_js_1.api.claimGas({
|
|
203
160
|
claims,
|
|
204
161
|
api: apiProvider,
|
|
205
162
|
account: neoAccount,
|
|
206
|
-
url
|
|
163
|
+
url: this.network.url,
|
|
207
164
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
symbol: constants_1.unclaimedTokenNeoLegacy.symbol
|
|
212
|
-
};
|
|
213
|
-
return result;
|
|
165
|
+
if (!response.tx)
|
|
166
|
+
throw new Error('Failed to claim');
|
|
167
|
+
return response.tx.hash;
|
|
214
168
|
});
|
|
215
169
|
}
|
|
216
170
|
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
constructor(network: Network, feeToken: Token, claimToken: Token);
|
|
8
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
9
|
+
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
10
|
+
getContract(contractHash: string): Promise<ContractResponse>;
|
|
11
|
+
getTokenInfo(tokenHash: string): Promise<Token>;
|
|
12
|
+
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
13
|
+
getUnclaimed(address: string): Promise<string>;
|
|
14
|
+
getBlockHeight(): Promise<number>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DoraBDSNeoLegacy = void 0;
|
|
13
|
+
const dora_ts_1 = require("@cityofzion/dora-ts");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const neon_js_1 = require("@cityofzion/neon-js");
|
|
16
|
+
class DoraBDSNeoLegacy {
|
|
17
|
+
constructor(network, feeToken, claimToken) {
|
|
18
|
+
this.tokenCache = new Map();
|
|
19
|
+
if (network.type === 'custom')
|
|
20
|
+
throw new Error('Custom network is not supported for NEO Legacy');
|
|
21
|
+
this.network = network;
|
|
22
|
+
this.claimToken = claimToken;
|
|
23
|
+
this.feeToken = feeToken;
|
|
24
|
+
}
|
|
25
|
+
getTransaction(hash) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const data = yield dora_ts_1.api.NeoLegacyREST.transaction(hash, this.network.type);
|
|
29
|
+
if (!data || 'error' in data)
|
|
30
|
+
throw new Error(`Transaction ${hash} not found`);
|
|
31
|
+
const vout = (_a = data.vout) !== null && _a !== void 0 ? _a : [];
|
|
32
|
+
const promises = vout.map((transfer, _index, array) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
var _d;
|
|
34
|
+
const token = yield this.getTokenInfo(transfer.asset);
|
|
35
|
+
return {
|
|
36
|
+
amount: String(transfer.value),
|
|
37
|
+
from: (_d = array[array.length - 1]) === null || _d === void 0 ? void 0 : _d.address,
|
|
38
|
+
contractHash: transfer.asset,
|
|
39
|
+
to: transfer.address,
|
|
40
|
+
type: 'token',
|
|
41
|
+
token,
|
|
42
|
+
};
|
|
43
|
+
}));
|
|
44
|
+
const transfers = yield Promise.all(promises);
|
|
45
|
+
return {
|
|
46
|
+
hash: data.txid,
|
|
47
|
+
block: data.block,
|
|
48
|
+
fee: (Number((_b = data.sys_fee) !== null && _b !== void 0 ? _b : 0) + Number((_c = data.net_fee) !== null && _c !== void 0 ? _c : 0)).toFixed(this.feeToken.decimals),
|
|
49
|
+
time: Number(data.time),
|
|
50
|
+
notifications: [],
|
|
51
|
+
transfers,
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getTransactionsByAddress({ address, page = 1, }) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const data = yield dora_ts_1.api.NeoLegacyREST.getAddressAbstracts(address, page, this.network.type);
|
|
58
|
+
const transactions = new Map();
|
|
59
|
+
const promises = data.entries.map((entry) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
if (entry.address_from !== address && entry.address_to !== address)
|
|
62
|
+
return;
|
|
63
|
+
const token = yield this.getTokenInfo(entry.asset);
|
|
64
|
+
const transfer = {
|
|
65
|
+
amount: String(entry.amount),
|
|
66
|
+
from: (_a = entry.address_from) !== null && _a !== void 0 ? _a : 'Mint',
|
|
67
|
+
to: (_b = entry.address_to) !== null && _b !== void 0 ? _b : 'Burn',
|
|
68
|
+
type: 'token',
|
|
69
|
+
contractHash: entry.asset,
|
|
70
|
+
token,
|
|
71
|
+
};
|
|
72
|
+
const existingTransaction = transactions.get(entry.txid);
|
|
73
|
+
if (existingTransaction) {
|
|
74
|
+
existingTransaction.transfers.push(transfer);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
transactions.set(entry.txid, {
|
|
78
|
+
block: entry.block_height,
|
|
79
|
+
hash: entry.txid,
|
|
80
|
+
time: entry.time,
|
|
81
|
+
transfers: [transfer],
|
|
82
|
+
notifications: [],
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
85
|
+
yield Promise.all(promises);
|
|
86
|
+
return {
|
|
87
|
+
totalCount: data.total_entries,
|
|
88
|
+
limit: data.page_size,
|
|
89
|
+
transactions: Array.from(transactions.values()),
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
getContract(contractHash) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const response = yield dora_ts_1.api.NeoLegacyREST.contract(contractHash, this.network.type);
|
|
96
|
+
if (!response || 'error' in response)
|
|
97
|
+
throw new Error(`Contract ${contractHash} not found`);
|
|
98
|
+
return {
|
|
99
|
+
hash: response.hash,
|
|
100
|
+
name: response.name,
|
|
101
|
+
methods: [],
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
getTokenInfo(tokenHash) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const localToken = constants_1.TOKENS[this.network.type].find(token => token.hash === tokenHash);
|
|
108
|
+
if (localToken)
|
|
109
|
+
return localToken;
|
|
110
|
+
if (this.tokenCache.has(tokenHash)) {
|
|
111
|
+
return this.tokenCache.get(tokenHash);
|
|
112
|
+
}
|
|
113
|
+
const data = yield dora_ts_1.api.NeoLegacyREST.asset(tokenHash, this.network.type);
|
|
114
|
+
if (!data || 'error' in data)
|
|
115
|
+
throw new Error(`Token ${tokenHash} not found`);
|
|
116
|
+
const token = {
|
|
117
|
+
decimals: data.decimals,
|
|
118
|
+
symbol: data.symbol,
|
|
119
|
+
hash: data.scripthash,
|
|
120
|
+
name: data.name,
|
|
121
|
+
};
|
|
122
|
+
this.tokenCache.set(tokenHash, token);
|
|
123
|
+
return token;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
getBalance(address) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const data = yield dora_ts_1.api.NeoLegacyREST.balance(address, this.network.type);
|
|
129
|
+
const promises = data.map((balance) => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
let token = {
|
|
131
|
+
hash: balance.asset,
|
|
132
|
+
name: balance.asset_name,
|
|
133
|
+
symbol: balance.symbol,
|
|
134
|
+
decimals: 8,
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
token = yield this.getTokenInfo(balance.asset);
|
|
138
|
+
}
|
|
139
|
+
catch (_a) { }
|
|
140
|
+
return {
|
|
141
|
+
amount: (Number(balance.balance) / Math.pow(10, token.decimals)).toFixed(token.decimals),
|
|
142
|
+
token,
|
|
143
|
+
};
|
|
144
|
+
}));
|
|
145
|
+
const result = yield Promise.all(promises);
|
|
146
|
+
return result;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getUnclaimed(address) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const { unclaimed } = yield dora_ts_1.api.NeoLegacyREST.getUnclaimed(address, this.network.type);
|
|
152
|
+
return (unclaimed / Math.pow(10, this.claimToken.decimals)).toFixed(this.claimToken.decimals);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
getBlockHeight() {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const rpcClient = new neon_js_1.rpc.RPCClient(this.network.url);
|
|
158
|
+
return yield rpcClient.getBlockCount();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.DoraBDSNeoLegacy = DoraBDSNeoLegacy;
|