@cityofzion/bs-solana 3.0.0 → 3.0.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/BSSolana.d.ts +2 -0
- package/dist/BSSolana.js +15 -25
- package/dist/constants/BSSolanaConstants.d.ts +1 -0
- package/dist/constants/BSSolanaConstants.js +6 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/services/blockchain-data/RpcBDSSolana.d.ts +13 -0
- package/dist/services/blockchain-data/RpcBDSSolana.js +493 -0
- package/dist/services/nft-data/{TatumRpcNDSSolana.d.ts → RpcNDSSolana.d.ts} +2 -1
- package/dist/services/nft-data/RpcNDSSolana.js +158 -0
- package/dist/types.d.ts +76 -1
- package/package.json +2 -2
- package/dist/services/blockchain-data/TatumRpcBDSSolana.d.ts +0 -16
- package/dist/services/blockchain-data/TatumRpcBDSSolana.js +0 -413
- package/dist/services/nft-data/TatumRpcNDSSolana.js +0 -129
package/dist/BSSolana.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TBSAccount, TGetLedgerTransport, IBlockchainDataService, IExchangeDataService, IExplorerService, INftDataService, ITokenService, TBSNetwork, TBSToken, TTransferParam, TPingNetworkResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import solanaSDK from '@solana/web3.js';
|
|
2
3
|
import { Web3LedgerServiceSolana } from './services/ledger/Web3LedgerServiceSolana';
|
|
3
4
|
import { IBSSolana, TBSSolanaNetworkId } from './types';
|
|
4
5
|
export declare class BSSolana<N extends string = string> implements IBSSolana<N> {
|
|
@@ -20,6 +21,7 @@ export declare class BSSolana<N extends string = string> implements IBSSolana<N>
|
|
|
20
21
|
nftDataService: INftDataService;
|
|
21
22
|
explorerService: IExplorerService;
|
|
22
23
|
tokenService: ITokenService;
|
|
24
|
+
connection: solanaSDK.Connection;
|
|
23
25
|
constructor(name: N, network?: TBSNetwork<TBSSolanaNetworkId>, getLedgerTransport?: TGetLedgerTransport<N>);
|
|
24
26
|
setNetwork(network: TBSNetwork<TBSSolanaNetworkId>): void;
|
|
25
27
|
pingNode(url: string): Promise<TPingNetworkResponse>;
|
package/dist/BSSolana.js
CHANGED
|
@@ -46,29 +46,21 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
46
46
|
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");
|
|
47
47
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
48
48
|
};
|
|
49
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
50
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
51
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
52
|
-
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");
|
|
53
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
54
|
-
};
|
|
55
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
56
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
57
51
|
};
|
|
58
|
-
var _BSSolana_instances,
|
|
52
|
+
var _BSSolana_instances, _BSSolana_generateKeyPairFromKey, _BSSolana_signTransaction, _BSSolana_buildTransferParams;
|
|
59
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
54
|
exports.BSSolana = void 0;
|
|
61
55
|
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
62
56
|
const web3_js_1 = __importDefault(require("@solana/web3.js"));
|
|
63
57
|
const solanaSplSDK = __importStar(require("@solana/spl-token"));
|
|
64
|
-
const bip39 = __importStar(require("bip39"));
|
|
65
58
|
const spl_name_service_1 = __importDefault(require("@bonfida/spl-name-service"));
|
|
66
|
-
const slip10_js_1 = __importDefault(require("micro-key-producer/slip10.js"));
|
|
67
59
|
const BSSolanaConstants_1 = require("./constants/BSSolanaConstants");
|
|
68
60
|
const bs58_1 = __importDefault(require("bs58"));
|
|
69
61
|
const Web3LedgerServiceSolana_1 = require("./services/ledger/Web3LedgerServiceSolana");
|
|
70
|
-
const
|
|
71
|
-
const
|
|
62
|
+
const RpcBDSSolana_1 = require("./services/blockchain-data/RpcBDSSolana");
|
|
63
|
+
const RpcNDSSolana_1 = require("./services/nft-data/RpcNDSSolana");
|
|
72
64
|
const SolScanESSolana_1 = require("./services/explorer/SolScanESSolana");
|
|
73
65
|
const MoralisEDSSolana_1 = require("./services/exchange/MoralisEDSSolana");
|
|
74
66
|
const TokenServiceSolana_1 = require("./services/token/TokenServiceSolana");
|
|
@@ -79,7 +71,6 @@ class BSSolana {
|
|
|
79
71
|
_BSSolana_instances.add(this);
|
|
80
72
|
this.isMultiTransferSupported = true;
|
|
81
73
|
this.isCustomNetworkSupported = false;
|
|
82
|
-
_BSSolana_connection.set(this, void 0);
|
|
83
74
|
this.name = name;
|
|
84
75
|
this.bip44DerivationPath = BSSolanaConstants_1.BSSolanaConstants.DEFAULT_BIP44_DERIVATION_PATH;
|
|
85
76
|
this.ledgerService = new Web3LedgerServiceSolana_1.Web3LedgerServiceSolana(this, getLedgerTransport);
|
|
@@ -99,11 +90,11 @@ class BSSolana {
|
|
|
99
90
|
this.network = network;
|
|
100
91
|
this.rpcNetworkUrls = rpcNetworkUrls;
|
|
101
92
|
this.tokenService = new TokenServiceSolana_1.TokenServiceSolana();
|
|
102
|
-
this.blockchainDataService = new
|
|
103
|
-
this.nftDataService = new
|
|
93
|
+
this.blockchainDataService = new RpcBDSSolana_1.RpcBDSSolana(this);
|
|
94
|
+
this.nftDataService = new RpcNDSSolana_1.RpcNDSSolana(this);
|
|
104
95
|
this.explorerService = new SolScanESSolana_1.SolScanESSolana(this);
|
|
105
96
|
this.exchangeDataService = new MoralisEDSSolana_1.MoralisEDSSolana(this);
|
|
106
|
-
|
|
97
|
+
this.connection = new web3_js_1.default.Connection(this.network.url);
|
|
107
98
|
}
|
|
108
99
|
// This method is done manually because we need to ensure that the request is aborted after timeout
|
|
109
100
|
pingNode(url) {
|
|
@@ -147,9 +138,8 @@ class BSSolana {
|
|
|
147
138
|
}
|
|
148
139
|
generateAccountFromMnemonic(mnemonic, index) {
|
|
149
140
|
const bip44Path = this.bip44DerivationPath.replace('?', index.toString());
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
const keypair = web3_js_1.default.Keypair.fromSeed(hd.derive(bip44Path).privateKey);
|
|
141
|
+
const keyBuffer = blockchain_service_1.BSKeychainHelper.generateEd25519KeyFromMnemonic(mnemonic, bip44Path);
|
|
142
|
+
const keypair = web3_js_1.default.Keypair.fromSeed(keyBuffer);
|
|
153
143
|
const key = bs58_1.default.encode(keypair.secretKey);
|
|
154
144
|
const address = keypair.publicKey.toBase58();
|
|
155
145
|
return {
|
|
@@ -183,18 +173,18 @@ class BSSolana {
|
|
|
183
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
174
|
const { transaction } = yield __classPrivateFieldGet(this, _BSSolana_instances, "m", _BSSolana_buildTransferParams).call(this, param);
|
|
185
175
|
const signedTransaction = yield __classPrivateFieldGet(this, _BSSolana_instances, "m", _BSSolana_signTransaction).call(this, transaction, param.senderAccount);
|
|
186
|
-
const signature = yield
|
|
176
|
+
const signature = yield this.connection.sendRawTransaction(signedTransaction);
|
|
187
177
|
return [signature];
|
|
188
178
|
});
|
|
189
179
|
}
|
|
190
180
|
calculateTransferFee(param) {
|
|
191
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
182
|
const { senderPublicKey, transaction } = yield __classPrivateFieldGet(this, _BSSolana_instances, "m", _BSSolana_buildTransferParams).call(this, param);
|
|
193
|
-
const { blockhash } = yield
|
|
183
|
+
const { blockhash } = yield this.connection.getLatestBlockhash();
|
|
194
184
|
transaction.recentBlockhash = blockhash;
|
|
195
185
|
transaction.feePayer = senderPublicKey;
|
|
196
186
|
const message = transaction.compileMessage();
|
|
197
|
-
const fee = yield
|
|
187
|
+
const fee = yield this.connection.getFeeForMessage(message);
|
|
198
188
|
if (!fee.value) {
|
|
199
189
|
throw new Error('Failed to calculate fee');
|
|
200
190
|
}
|
|
@@ -204,7 +194,7 @@ class BSSolana {
|
|
|
204
194
|
}
|
|
205
195
|
resolveNameServiceDomain(domainName) {
|
|
206
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
const address = yield spl_name_service_1.default.resolve(
|
|
197
|
+
const address = yield spl_name_service_1.default.resolve(this.connection, domainName);
|
|
208
198
|
return address.toBase58();
|
|
209
199
|
});
|
|
210
200
|
}
|
|
@@ -213,7 +203,7 @@ class BSSolana {
|
|
|
213
203
|
}
|
|
214
204
|
}
|
|
215
205
|
exports.BSSolana = BSSolana;
|
|
216
|
-
|
|
206
|
+
_BSSolana_instances = new WeakSet(), _BSSolana_generateKeyPairFromKey = function _BSSolana_generateKeyPairFromKey(key) {
|
|
217
207
|
let keyBuffer;
|
|
218
208
|
try {
|
|
219
209
|
keyBuffer = bs58_1.default.decode(key);
|
|
@@ -237,7 +227,7 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
237
227
|
});
|
|
238
228
|
}, _BSSolana_buildTransferParams = function _BSSolana_buildTransferParams(param) {
|
|
239
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
-
const latestBlockhash = yield
|
|
230
|
+
const latestBlockhash = yield this.connection.getLatestBlockhash();
|
|
241
231
|
const senderPublicKey = new web3_js_1.default.PublicKey(param.senderAccount.address);
|
|
242
232
|
const transaction = new web3_js_1.default.Transaction();
|
|
243
233
|
transaction.feePayer = senderPublicKey;
|
|
@@ -261,7 +251,7 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
261
251
|
const senderTokenAddress = yield solanaSplSDK.getAssociatedTokenAddress(tokenMintPublicKey, senderPublicKey);
|
|
262
252
|
const receiverTokenAddress = yield solanaSplSDK.getAssociatedTokenAddress(tokenMintPublicKey, receiverPublicKey);
|
|
263
253
|
try {
|
|
264
|
-
yield solanaSplSDK.getAccount(
|
|
254
|
+
yield solanaSplSDK.getAccount(this.connection, receiverTokenAddress);
|
|
265
255
|
}
|
|
266
256
|
catch (error) {
|
|
267
257
|
if (error instanceof solanaSplSDK.TokenAccountNotFoundError ||
|
|
@@ -4,6 +4,7 @@ export declare class BSSolanaConstants {
|
|
|
4
4
|
static readonly DEFAULT_BIP44_DERIVATION_PATH = "m/44'/501'/?'/0'";
|
|
5
5
|
static readonly NATIVE_TOKEN: TBSToken;
|
|
6
6
|
static readonly NATIVE_WRAPPED_HASH = "So11111111111111111111111111111111111111112";
|
|
7
|
+
static readonly PUBLIC_RPC_LIST_BY_NETWORK_ID: Record<TBSSolanaNetworkId, string>;
|
|
7
8
|
static readonly RPC_LIST_BY_NETWORK_ID: Record<TBSSolanaNetworkId, string[]>;
|
|
8
9
|
static readonly MAINNET_NETWORK: TBSNetwork<TBSSolanaNetworkId>;
|
|
9
10
|
static readonly TESTNET_NETWORK: TBSNetwork<TBSSolanaNetworkId>;
|
|
@@ -9,9 +9,13 @@ _a = BSSolanaConstants;
|
|
|
9
9
|
BSSolanaConstants.DEFAULT_BIP44_DERIVATION_PATH = "m/44'/501'/?'/0'";
|
|
10
10
|
BSSolanaConstants.NATIVE_TOKEN = { symbol: 'SOL', name: 'SOL', decimals: 9, hash: '-' };
|
|
11
11
|
BSSolanaConstants.NATIVE_WRAPPED_HASH = 'So11111111111111111111111111111111111111112';
|
|
12
|
+
BSSolanaConstants.PUBLIC_RPC_LIST_BY_NETWORK_ID = {
|
|
13
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com',
|
|
14
|
+
devnet: 'https://api.devnet.solana.com',
|
|
15
|
+
};
|
|
12
16
|
BSSolanaConstants.RPC_LIST_BY_NETWORK_ID = {
|
|
13
|
-
'mainnet-beta': ['https://api.
|
|
14
|
-
devnet: ['https://api.
|
|
17
|
+
'mainnet-beta': ['https://api.coz.io/api/v2/solana/meta/mainnet'],
|
|
18
|
+
devnet: ['https://api.coz.io/api/v2/solana/meta/devnet'],
|
|
15
19
|
};
|
|
16
20
|
BSSolanaConstants.MAINNET_NETWORK = {
|
|
17
21
|
id: 'mainnet-beta',
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export * from './constants/BSSolanaConstants';
|
|
2
|
-
export * from './helpers/BSSolanaCachedMethodsHelper';
|
|
3
2
|
export * from './helpers/BSSolanaHelper';
|
|
4
|
-
export * from './services/blockchain-data/
|
|
3
|
+
export * from './services/blockchain-data/RpcBDSSolana';
|
|
5
4
|
export * from './services/exchange/MoralisEDSSolana';
|
|
6
5
|
export * from './services/explorer/SolScanESSolana';
|
|
7
6
|
export * from './services/ledger/Web3LedgerServiceSolana';
|
|
8
|
-
export * from './services/nft-data/
|
|
7
|
+
export * from './services/nft-data/RpcNDSSolana';
|
|
9
8
|
export * from './services/token/TokenServiceSolana';
|
|
10
9
|
export * from './BSSolana';
|
|
11
10
|
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -15,13 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants/BSSolanaConstants"), exports);
|
|
18
|
-
__exportStar(require("./helpers/BSSolanaCachedMethodsHelper"), exports);
|
|
19
18
|
__exportStar(require("./helpers/BSSolanaHelper"), exports);
|
|
20
|
-
__exportStar(require("./services/blockchain-data/
|
|
19
|
+
__exportStar(require("./services/blockchain-data/RpcBDSSolana"), exports);
|
|
21
20
|
__exportStar(require("./services/exchange/MoralisEDSSolana"), exports);
|
|
22
21
|
__exportStar(require("./services/explorer/SolScanESSolana"), exports);
|
|
23
22
|
__exportStar(require("./services/ledger/Web3LedgerServiceSolana"), exports);
|
|
24
|
-
__exportStar(require("./services/nft-data/
|
|
23
|
+
__exportStar(require("./services/nft-data/RpcNDSSolana"), exports);
|
|
25
24
|
__exportStar(require("./services/token/TokenServiceSolana"), exports);
|
|
26
25
|
__exportStar(require("./BSSolana"), exports);
|
|
27
26
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TBalanceResponse, IBlockchainDataService, TBSToken, type TContractResponse, type TTransaction, type TGetTransactionsByAddressParams, type TGetTransactionsByAddressResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { IBSSolana } from '../../types';
|
|
3
|
+
export declare class RpcBDSSolana<N extends string> implements IBlockchainDataService<N> {
|
|
4
|
+
#private;
|
|
5
|
+
readonly maxTimeToConfirmTransactionInMs: number;
|
|
6
|
+
constructor(service: IBSSolana<N>);
|
|
7
|
+
getTransaction(txid: string): Promise<TTransaction<N>>;
|
|
8
|
+
getTransactionsByAddress(params: TGetTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse<N>>;
|
|
9
|
+
getContract(_contractHash: string): Promise<TContractResponse>;
|
|
10
|
+
getTokenInfo(tokenHash: string): Promise<TBSToken>;
|
|
11
|
+
getBalance(address: string): Promise<TBalanceResponse[]>;
|
|
12
|
+
getBlockHeight(): Promise<number>;
|
|
13
|
+
}
|