@cityofzion/bs-ethereum 0.8.2 → 0.9.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.
- package/.rush/temp/operation/build/all.log +1 -1
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +6 -4
- package/.rush/temp/shrinkwrap-deps.json +1 -2
- package/CHANGELOG.json +27 -0
- package/CHANGELOG.md +15 -0
- package/bs-ethereum.build.log +1 -1
- package/dist/BSEthereum.d.ts +24 -23
- package/dist/BSEthereum.js +184 -178
- package/dist/BitqueryBDSEthereum.d.ts +14 -14
- package/dist/BitqueryBDSEthereum.js +197 -197
- package/dist/BitqueryEDSEthereum.d.ts +8 -8
- package/dist/BitqueryEDSEthereum.js +73 -73
- package/dist/GhostMarketNDSEthereum.d.ts +10 -10
- package/dist/GhostMarketNDSEthereum.js +77 -77
- package/dist/RpcBDSEthereum.d.ts +12 -12
- package/dist/RpcBDSEthereum.js +89 -89
- package/dist/assets/tokens/common.json +8 -8
- package/dist/constants.d.ts +16 -16
- package/dist/constants.js +33 -33
- package/dist/graphql.d.ts +124 -124
- package/dist/graphql.js +163 -163
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/jest.config.ts +13 -13
- package/jest.setup.ts +1 -1
- package/package.json +34 -34
- package/src/BSEthereum.ts +189 -184
- package/src/BitqueryBDSEthereum.ts +230 -230
- package/src/BitqueryEDSEthereum.ts +67 -67
- package/src/GhostMarketNDSEthereum.ts +122 -122
- package/src/RpcBDSEthereum.ts +88 -88
- package/src/__tests__/BDSEthereum.spec.ts +123 -123
- package/src/__tests__/BSEthereum.spec.ts +129 -123
- package/src/__tests__/BitqueryEDSEthereum.spec.ts +49 -49
- package/src/__tests__/GhostMarketNDSEthereum.spec.ts +45 -45
- package/src/assets/tokens/common.json +7 -7
- package/src/constants.ts +37 -37
- package/src/graphql.ts +291 -291
- package/src/index.ts +6 -6
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
Invoking: tsc --project tsconfig.build.json
|
|
1
|
+
Invoking: tsc --project tsconfig.build.json
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
"files": {
|
|
3
3
|
"packages/bs-ethereum/jest.config.ts": "d944475db93cbe41a9339187fd94b9962e411c43",
|
|
4
4
|
"packages/bs-ethereum/jest.setup.ts": "9a1976a32050616d4d2ee95b1aa21041bc4daca3",
|
|
5
|
-
"packages/bs-ethereum/package.json": "
|
|
6
|
-
"packages/bs-ethereum/src/BSEthereum.ts": "
|
|
5
|
+
"packages/bs-ethereum/package.json": "bc15e92f1ff181d7980796f13f82b812095c9b67",
|
|
6
|
+
"packages/bs-ethereum/src/BSEthereum.ts": "fcc78bb58de41ac86e2ebadea1ad16dc9ca0b018",
|
|
7
7
|
"packages/bs-ethereum/src/BitqueryBDSEthereum.ts": "44fdbe7e3d03e33d5ed0e10fe68570e592fb8a4c",
|
|
8
8
|
"packages/bs-ethereum/src/BitqueryEDSEthereum.ts": "1636b062144b517e0e5cee4f4b548378538b9270",
|
|
9
9
|
"packages/bs-ethereum/src/GhostMarketNDSEthereum.ts": "145273284b3c27494eea0e80c0c1de8001b11c57",
|
|
10
10
|
"packages/bs-ethereum/src/RpcBDSEthereum.ts": "6cbca256420b09cef7182cbc485eb4799ff9b614",
|
|
11
11
|
"packages/bs-ethereum/src/__tests__/BDSEthereum.spec.ts": "8b66ba80d8457601fac69819cc1fae4d7bc7b08a",
|
|
12
|
-
"packages/bs-ethereum/src/__tests__/BSEthereum.spec.ts": "
|
|
12
|
+
"packages/bs-ethereum/src/__tests__/BSEthereum.spec.ts": "5e7a12e675e06eae397d2e36a16adccfd5127aef",
|
|
13
13
|
"packages/bs-ethereum/src/__tests__/BitqueryEDSEthereum.spec.ts": "502e58b5d93a7e2e1ed5b48cf0e87601ae4ab736",
|
|
14
14
|
"packages/bs-ethereum/src/__tests__/GhostMarketNDSEthereum.spec.ts": "f5c9ba8f6c866b97bcf647d105bfa2d5f140180d",
|
|
15
15
|
"packages/bs-ethereum/src/assets/tokens/common.json": "4dbbf3a3b38422e743cf631ffb6c39231777b88d",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"packages/bs-ethereum/src/index.ts": "69ca9c23acdd0afd70f7eaa0a840b07b62bdb07a",
|
|
19
19
|
"packages/bs-ethereum/tsconfig.build.json": "4dc23fb9c4c5e4d19a9bc3947a47c523f4bd967c",
|
|
20
20
|
"packages/bs-ethereum/tsconfig.json": "93e09769572b58e642d4990e9552c70a8b85e142",
|
|
21
|
-
"packages/bs-ethereum/.rush/temp/shrinkwrap-deps.json": "
|
|
21
|
+
"packages/bs-ethereum/.rush/temp/shrinkwrap-deps.json": "41662314b899796f96fedf7c8c117e94e082dd75",
|
|
22
|
+
"packages/bs-ethereum/CHANGELOG.json": "bc05084b119d85be642f7847e74e710adc2adfbf",
|
|
23
|
+
"packages/bs-ethereum/CHANGELOG.md": "5d1dfb79f709ac611027c5eea494aa3a48a403f4"
|
|
22
24
|
},
|
|
23
25
|
"arguments": "tsc --project tsconfig.build.json "
|
|
24
26
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"../../packages/bs-ethereum": "../../packages/bs-ethereum:
|
|
2
|
+
"../../packages/bs-ethereum": "../../packages/bs-ethereum:ardtHko8xY1GTiqxHJP8hRdtjYZ8BJykBzGRdkUmDw0=:",
|
|
3
3
|
"/@0no-co/graphql.web@1.0.4(graphql@16.8.1)": "sha512-W3ezhHGfO0MS1PtGloaTpg0PbaT8aZSmmaerL7idtU5F7oCI+uu25k+MsMS31BVFlp4aMkHSrNRxiD72IlK8TA==",
|
|
4
4
|
"/@ampproject/remapping@2.2.1": "sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==",
|
|
5
5
|
"/@babel/code-frame@7.23.4": "sha512-r1IONyb6Ia+jYR2vvIDhdWdlTGhqbBoFqLTQidzZ4kepUFH15ejXvFHxCVbtl7BOXIudsIubf4E81xeA3h3IXA==",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"/@babel/traverse@7.23.4": "sha512-IYM8wSUwunWTB6tFC2dkKZhxbIjHoWemdK+3f8/wq8aKhbUscxD5MX72ubd90fxvFknaLPeGw5ycU84V1obHJg==",
|
|
40
40
|
"/@babel/types@7.23.4": "sha512-7uIFwVYpoplT5jp/kVv6EF93VaJ8H+Yn5IczYiaAi98ajzjfoZfslet/e0sLh+wVBjb2qqIut1b0S26VSafsSQ==",
|
|
41
41
|
"/@bcoe/v8-coverage@0.2.3": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
|
|
42
|
-
"/@cityofzion/blockchain-service@0.8.0": "sha512-8OaX0hXTK/vqV1QYbPeZoVjB9AM8YPbnzKMx4kdmm7zKHXppfFeUnMMXbjnx/4GuvOLs4IjAw+6Q78J9FDHe9A==",
|
|
43
42
|
"/@cspotcode/source-map-support@0.8.1": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
|
|
44
43
|
"/@ethersproject/abi@5.7.0": "sha512-351ktp42TiRcYB3H1OP8yajPeAQstMW/yCFokj/AthP9bLHzQFPlOrxOcwYEDkUAICmOHljvN4K39OMTMUa9RA==",
|
|
45
44
|
"/@ethersproject/abstract-provider@5.7.0": "sha512-R41c9UkchKCpAqStMYUpdunjo3pkEvZC3FAwZn5S5MGbXoMQOHIdHItezTETxAO5bevtMApSyEhn9+CHcDsWBw==",
|
package/CHANGELOG.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cityofzion/bs-ethereum",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.9.0",
|
|
6
|
+
"tag": "@cityofzion/bs-ethereum_v0.9.0",
|
|
7
|
+
"date": "Tue, 05 Dec 2023 18:42:10 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Inserted within the TokenPricesResponse type the token hash"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"patch": [
|
|
15
|
+
{
|
|
16
|
+
"comment": "Fixed issue with the getBalance method that returned negative numbers and the wrong ETH value"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"dependency": [
|
|
20
|
+
{
|
|
21
|
+
"comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.9.0`"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Change Log - @cityofzion/bs-ethereum
|
|
2
|
+
|
|
3
|
+
This log was last generated on Tue, 05 Dec 2023 18:42:10 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.9.0
|
|
6
|
+
Tue, 05 Dec 2023 18:42:10 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Inserted within the TokenPricesResponse type the token hash
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- Fixed issue with the getBalance method that returned negative numbers and the wrong ETH value
|
|
15
|
+
|
package/bs-ethereum.build.log
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Invoking: tsc --project tsconfig.build.json
|
|
1
|
+
Invoking: tsc --project tsconfig.build.json
|
package/dist/BSEthereum.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, Token, TransferParam } from '@cityofzion/blockchain-service';
|
|
2
|
-
export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee {
|
|
3
|
-
readonly blockchainName: BSCustomName;
|
|
4
|
-
readonly feeToken: Token;
|
|
5
|
-
readonly derivationPath: string;
|
|
6
|
-
blockchainDataService: BlockchainDataService;
|
|
7
|
-
exchangeDataService: ExchangeDataService;
|
|
8
|
-
tokens: Token[];
|
|
9
|
-
nftDataService: NftDataService;
|
|
10
|
-
network: Network;
|
|
11
|
-
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
12
|
-
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
13
|
-
validateAddress(address: string): boolean;
|
|
14
|
-
validateEncrypted(json: string): boolean;
|
|
15
|
-
validateKey(key: string): boolean;
|
|
16
|
-
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
17
|
-
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
18
|
-
generateAccountFromKey(key: string): Account;
|
|
19
|
-
decrypt(json: string, password: string): Promise<Account>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { Account, AccountWithDerivationPath, BSCalculableFee, BSWithNameService, BSWithNft, BlockchainDataService, BlockchainService, ExchangeDataService, Network, NftDataService, PartialBy, Token, TransferParam } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare class BSEthereum<BSCustomName extends string = string> implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee {
|
|
3
|
+
readonly blockchainName: BSCustomName;
|
|
4
|
+
readonly feeToken: Token;
|
|
5
|
+
readonly derivationPath: string;
|
|
6
|
+
blockchainDataService: BlockchainDataService;
|
|
7
|
+
exchangeDataService: ExchangeDataService;
|
|
8
|
+
tokens: Token[];
|
|
9
|
+
nftDataService: NftDataService;
|
|
10
|
+
network: Network;
|
|
11
|
+
constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>);
|
|
12
|
+
setNetwork(param: PartialBy<Network, 'url'>): void;
|
|
13
|
+
validateAddress(address: string): boolean;
|
|
14
|
+
validateEncrypted(json: string): boolean;
|
|
15
|
+
validateKey(key: string): boolean;
|
|
16
|
+
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
17
|
+
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
|
|
18
|
+
generateAccountFromKey(key: string): Account;
|
|
19
|
+
decrypt(json: string, password: string): Promise<Account>;
|
|
20
|
+
encrypt(key: string, password: string): Promise<string>;
|
|
21
|
+
transfer({ senderAccount, intent }: TransferParam): Promise<string>;
|
|
22
|
+
calculateTransferFee({ senderAccount, intent }: TransferParam, details?: boolean | undefined): Promise<string>;
|
|
23
|
+
resolveNameServiceDomain(domainName: string): Promise<string>;
|
|
24
|
+
}
|
package/dist/BSEthereum.js
CHANGED
|
@@ -1,178 +1,184 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.BSEthereum = void 0;
|
|
36
|
-
const ethers_1 = require("ethers");
|
|
37
|
-
const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
|
|
38
|
-
const ethersBytes = __importStar(require("@ethersproject/bytes"));
|
|
39
|
-
const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
|
|
40
|
-
const constants_1 = require("./constants");
|
|
41
|
-
const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
|
|
42
|
-
const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
|
|
43
|
-
const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
|
|
44
|
-
const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
|
|
45
|
-
class BSEthereum {
|
|
46
|
-
constructor(blockchainName, network) {
|
|
47
|
-
this.blockchainName = blockchainName;
|
|
48
|
-
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
49
|
-
this.tokens = constants_1.TOKENS[network.type];
|
|
50
|
-
this.feeToken = this.tokens.find(token => token.symbol === 'ETH');
|
|
51
|
-
this.setNetwork(network);
|
|
52
|
-
}
|
|
53
|
-
setNetwork(param) {
|
|
54
|
-
var _a;
|
|
55
|
-
const network = {
|
|
56
|
-
type: param.type,
|
|
57
|
-
url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
|
|
58
|
-
};
|
|
59
|
-
this.network = network;
|
|
60
|
-
if (network.type === 'custom') {
|
|
61
|
-
this.blockchainDataService = new RpcBDSEthereum_1.RpcBDSEthereum(network);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network);
|
|
65
|
-
}
|
|
66
|
-
this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type);
|
|
67
|
-
this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network.type);
|
|
68
|
-
}
|
|
69
|
-
validateAddress(address) {
|
|
70
|
-
return ethers_1.ethers.utils.isAddress(address);
|
|
71
|
-
}
|
|
72
|
-
validateEncrypted(json) {
|
|
73
|
-
return ethersJsonWallets.isCrowdsaleWallet(json) || ethersJsonWallets.isKeystoreWallet(json);
|
|
74
|
-
}
|
|
75
|
-
validateKey(key) {
|
|
76
|
-
try {
|
|
77
|
-
if (!key.startsWith('0x')) {
|
|
78
|
-
key = '0x' + key;
|
|
79
|
-
}
|
|
80
|
-
if (ethersBytes.hexDataLength(key) !== 32)
|
|
81
|
-
return false;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
validateNameServiceDomainFormat(domainName) {
|
|
89
|
-
if (!domainName.endsWith('.eth'))
|
|
90
|
-
return false;
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
generateAccountFromMnemonic(mnemonic, index) {
|
|
94
|
-
const path = this.derivationPath.replace('?', index.toString());
|
|
95
|
-
const wallet = ethers_1.ethers.Wallet.fromMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic, path);
|
|
96
|
-
return {
|
|
97
|
-
address: wallet.address,
|
|
98
|
-
key: wallet.privateKey,
|
|
99
|
-
type: 'privateKey',
|
|
100
|
-
derivationPath: path,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
generateAccountFromKey(key) {
|
|
104
|
-
const wallet = new ethers_1.ethers.Wallet(key);
|
|
105
|
-
return {
|
|
106
|
-
address: wallet.address,
|
|
107
|
-
key,
|
|
108
|
-
type: 'privateKey',
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
decrypt(json, password) {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const wallet = yield ethers_1.ethers.Wallet.fromEncryptedJson(json, password);
|
|
114
|
-
return {
|
|
115
|
-
address: wallet.address,
|
|
116
|
-
key: wallet.privateKey,
|
|
117
|
-
type: 'privateKey',
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.BSEthereum = void 0;
|
|
36
|
+
const ethers_1 = require("ethers");
|
|
37
|
+
const ethersJsonWallets = __importStar(require("@ethersproject/json-wallets"));
|
|
38
|
+
const ethersBytes = __importStar(require("@ethersproject/bytes"));
|
|
39
|
+
const ethersBigNumber = __importStar(require("@ethersproject/bignumber"));
|
|
40
|
+
const constants_1 = require("./constants");
|
|
41
|
+
const BitqueryEDSEthereum_1 = require("./BitqueryEDSEthereum");
|
|
42
|
+
const GhostMarketNDSEthereum_1 = require("./GhostMarketNDSEthereum");
|
|
43
|
+
const RpcBDSEthereum_1 = require("./RpcBDSEthereum");
|
|
44
|
+
const BitqueryBDSEthereum_1 = require("./BitqueryBDSEthereum");
|
|
45
|
+
class BSEthereum {
|
|
46
|
+
constructor(blockchainName, network) {
|
|
47
|
+
this.blockchainName = blockchainName;
|
|
48
|
+
this.derivationPath = constants_1.DERIVATION_PATH;
|
|
49
|
+
this.tokens = constants_1.TOKENS[network.type];
|
|
50
|
+
this.feeToken = this.tokens.find(token => token.symbol === 'ETH');
|
|
51
|
+
this.setNetwork(network);
|
|
52
|
+
}
|
|
53
|
+
setNetwork(param) {
|
|
54
|
+
var _a;
|
|
55
|
+
const network = {
|
|
56
|
+
type: param.type,
|
|
57
|
+
url: (_a = param.url) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_URL_BY_NETWORK_TYPE[param.type],
|
|
58
|
+
};
|
|
59
|
+
this.network = network;
|
|
60
|
+
if (network.type === 'custom') {
|
|
61
|
+
this.blockchainDataService = new RpcBDSEthereum_1.RpcBDSEthereum(network);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network);
|
|
65
|
+
}
|
|
66
|
+
this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type);
|
|
67
|
+
this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network.type);
|
|
68
|
+
}
|
|
69
|
+
validateAddress(address) {
|
|
70
|
+
return ethers_1.ethers.utils.isAddress(address);
|
|
71
|
+
}
|
|
72
|
+
validateEncrypted(json) {
|
|
73
|
+
return ethersJsonWallets.isCrowdsaleWallet(json) || ethersJsonWallets.isKeystoreWallet(json);
|
|
74
|
+
}
|
|
75
|
+
validateKey(key) {
|
|
76
|
+
try {
|
|
77
|
+
if (!key.startsWith('0x')) {
|
|
78
|
+
key = '0x' + key;
|
|
79
|
+
}
|
|
80
|
+
if (ethersBytes.hexDataLength(key) !== 32)
|
|
81
|
+
return false;
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
validateNameServiceDomainFormat(domainName) {
|
|
89
|
+
if (!domainName.endsWith('.eth'))
|
|
90
|
+
return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
generateAccountFromMnemonic(mnemonic, index) {
|
|
94
|
+
const path = this.derivationPath.replace('?', index.toString());
|
|
95
|
+
const wallet = ethers_1.ethers.Wallet.fromMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic, path);
|
|
96
|
+
return {
|
|
97
|
+
address: wallet.address,
|
|
98
|
+
key: wallet.privateKey,
|
|
99
|
+
type: 'privateKey',
|
|
100
|
+
derivationPath: path,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
generateAccountFromKey(key) {
|
|
104
|
+
const wallet = new ethers_1.ethers.Wallet(key);
|
|
105
|
+
return {
|
|
106
|
+
address: wallet.address,
|
|
107
|
+
key,
|
|
108
|
+
type: 'privateKey',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
decrypt(json, password) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const wallet = yield ethers_1.ethers.Wallet.fromEncryptedJson(json, password);
|
|
114
|
+
return {
|
|
115
|
+
address: wallet.address,
|
|
116
|
+
key: wallet.privateKey,
|
|
117
|
+
type: 'privateKey',
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
encrypt(key, password) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const wallet = new ethers_1.ethers.Wallet(key);
|
|
124
|
+
return wallet.encrypt(password);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
transfer({ senderAccount, intent }) {
|
|
128
|
+
var _a;
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
131
|
+
const wallet = new ethers_1.ethers.Wallet(senderAccount.key, provider);
|
|
132
|
+
let transaction;
|
|
133
|
+
const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
134
|
+
const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
|
|
135
|
+
const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash);
|
|
136
|
+
if (!isNative) {
|
|
137
|
+
const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], wallet);
|
|
138
|
+
transaction = yield contract.transfer(intent.receiverAddress, amount);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
transaction = yield wallet.sendTransaction({
|
|
142
|
+
to: intent.receiverAddress,
|
|
143
|
+
value: amount,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const transactionMined = yield transaction.wait();
|
|
147
|
+
if (!transactionMined)
|
|
148
|
+
throw new Error('Transaction not mined');
|
|
149
|
+
return transactionMined.transactionHash;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
calculateTransferFee({ senderAccount, intent }, details) {
|
|
153
|
+
var _a;
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
156
|
+
const wallet = new ethers_1.ethers.Wallet(senderAccount.key, provider);
|
|
157
|
+
let estimated;
|
|
158
|
+
const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash);
|
|
159
|
+
const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
160
|
+
const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
|
|
161
|
+
if (!isNative) {
|
|
162
|
+
const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], wallet);
|
|
163
|
+
estimated = yield contract.estimateGas.transfer(intent.receiverAddress, amount);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
estimated = yield wallet.estimateGas({
|
|
167
|
+
to: intent.receiverAddress,
|
|
168
|
+
value: amount,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return ethers_1.ethers.utils.formatEther(estimated);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
resolveNameServiceDomain(domainName) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
177
|
+
const address = yield provider.resolveName(domainName);
|
|
178
|
+
if (!address)
|
|
179
|
+
throw new Error('No address found for domain name');
|
|
180
|
+
return address;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.BSEthereum = BSEthereum;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
|
|
2
|
-
import { RpcBDSEthereum } from './RpcBDSEthereum';
|
|
3
|
-
export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
|
|
4
|
-
private readonly client;
|
|
5
|
-
private readonly networkType;
|
|
6
|
-
maxTimeToConfirmTransactionInMs: number;
|
|
7
|
-
constructor(network: Network);
|
|
8
|
-
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
9
|
-
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
10
|
-
getContract(): Promise<ContractResponse>;
|
|
11
|
-
getTokenInfo(hash: string): Promise<Token>;
|
|
12
|
-
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
13
|
-
private parseTransactionTransfer;
|
|
14
|
-
}
|
|
1
|
+
import { BalanceResponse, ContractResponse, Token, TransactionsByAddressParams, TransactionsByAddressResponse, TransactionResponse, Network } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { RpcBDSEthereum } from './RpcBDSEthereum';
|
|
3
|
+
export declare class BitqueryBDSEthereum extends RpcBDSEthereum {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly networkType;
|
|
6
|
+
maxTimeToConfirmTransactionInMs: number;
|
|
7
|
+
constructor(network: Network);
|
|
8
|
+
getTransaction(hash: string): Promise<TransactionResponse>;
|
|
9
|
+
getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
|
|
10
|
+
getContract(): Promise<ContractResponse>;
|
|
11
|
+
getTokenInfo(hash: string): Promise<Token>;
|
|
12
|
+
getBalance(address: string): Promise<BalanceResponse[]>;
|
|
13
|
+
private parseTransactionTransfer;
|
|
14
|
+
}
|