@cityofzion/bs-solana 2.0.11 → 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 +3 -1
- package/dist/BSSolana.js +18 -38
- package/dist/constants/BSSolanaConstants.d.ts +1 -0
- package/dist/constants/BSSolanaConstants.js +6 -2
- package/dist/helpers/BSSolanaHelper.d.ts +0 -2
- package/dist/helpers/BSSolanaHelper.js +0 -6
- 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/ledger/Web3LedgerServiceSolana.js +2 -3
- 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 +8 -7
- package/dist/services/blockchain-data/TatumRpcBDSSolana.d.ts +0 -18
- package/dist/services/blockchain-data/TatumRpcBDSSolana.js +0 -364
- 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> {
|
|
@@ -16,10 +17,11 @@ export declare class BSSolana<N extends string = string> implements IBSSolana<N>
|
|
|
16
17
|
readonly defaultNetwork: TBSNetwork<TBSSolanaNetworkId>;
|
|
17
18
|
ledgerService: Web3LedgerServiceSolana<N>;
|
|
18
19
|
exchangeDataService: IExchangeDataService;
|
|
19
|
-
blockchainDataService: IBlockchainDataService
|
|
20
|
+
blockchainDataService: IBlockchainDataService<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 {
|
|
@@ -181,28 +171,20 @@ class BSSolana {
|
|
|
181
171
|
}
|
|
182
172
|
transfer(param) {
|
|
183
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
const { transaction
|
|
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
|
|
187
|
-
const status = yield __classPrivateFieldGet(this, _BSSolana_connection, "f").confirmTransaction({
|
|
188
|
-
blockhash: latestBlockhash.blockhash,
|
|
189
|
-
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
|
|
190
|
-
signature,
|
|
191
|
-
});
|
|
192
|
-
if (status.value.err) {
|
|
193
|
-
throw new Error('Transaction failed: ' + status.value.err);
|
|
194
|
-
}
|
|
176
|
+
const signature = yield this.connection.sendRawTransaction(signedTransaction);
|
|
195
177
|
return [signature];
|
|
196
178
|
});
|
|
197
179
|
}
|
|
198
180
|
calculateTransferFee(param) {
|
|
199
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
182
|
const { senderPublicKey, transaction } = yield __classPrivateFieldGet(this, _BSSolana_instances, "m", _BSSolana_buildTransferParams).call(this, param);
|
|
201
|
-
const { blockhash } = yield
|
|
183
|
+
const { blockhash } = yield this.connection.getLatestBlockhash();
|
|
202
184
|
transaction.recentBlockhash = blockhash;
|
|
203
185
|
transaction.feePayer = senderPublicKey;
|
|
204
186
|
const message = transaction.compileMessage();
|
|
205
|
-
const fee = yield
|
|
187
|
+
const fee = yield this.connection.getFeeForMessage(message);
|
|
206
188
|
if (!fee.value) {
|
|
207
189
|
throw new Error('Failed to calculate fee');
|
|
208
190
|
}
|
|
@@ -212,7 +194,7 @@ class BSSolana {
|
|
|
212
194
|
}
|
|
213
195
|
resolveNameServiceDomain(domainName) {
|
|
214
196
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
const address = yield spl_name_service_1.default.resolve(
|
|
197
|
+
const address = yield spl_name_service_1.default.resolve(this.connection, domainName);
|
|
216
198
|
return address.toBase58();
|
|
217
199
|
});
|
|
218
200
|
}
|
|
@@ -221,7 +203,7 @@ class BSSolana {
|
|
|
221
203
|
}
|
|
222
204
|
}
|
|
223
205
|
exports.BSSolana = BSSolana;
|
|
224
|
-
|
|
206
|
+
_BSSolana_instances = new WeakSet(), _BSSolana_generateKeyPairFromKey = function _BSSolana_generateKeyPairFromKey(key) {
|
|
225
207
|
let keyBuffer;
|
|
226
208
|
try {
|
|
227
209
|
keyBuffer = bs58_1.default.decode(key);
|
|
@@ -245,8 +227,7 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
245
227
|
});
|
|
246
228
|
}, _BSSolana_buildTransferParams = function _BSSolana_buildTransferParams(param) {
|
|
247
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
-
|
|
249
|
-
const latestBlockhash = yield __classPrivateFieldGet(this, _BSSolana_connection, "f").getLatestBlockhash();
|
|
230
|
+
const latestBlockhash = yield this.connection.getLatestBlockhash();
|
|
250
231
|
const senderPublicKey = new web3_js_1.default.PublicKey(param.senderAccount.address);
|
|
251
232
|
const transaction = new web3_js_1.default.Transaction();
|
|
252
233
|
transaction.feePayer = senderPublicKey;
|
|
@@ -254,9 +235,9 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
254
235
|
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
255
236
|
for (const intent of param.intents) {
|
|
256
237
|
const amountBn = blockchain_service_1.BSBigNumberHelper.fromNumber(intent.amount);
|
|
257
|
-
const amount = Number(blockchain_service_1.BSBigNumberHelper.toDecimals(amountBn,
|
|
238
|
+
const amount = Number(blockchain_service_1.BSBigNumberHelper.toDecimals(amountBn, intent.token.decimals));
|
|
258
239
|
const receiverPublicKey = new web3_js_1.default.PublicKey(intent.receiverAddress);
|
|
259
|
-
const normalizedTokenHash = this.tokenService.normalizeHash(intent.
|
|
240
|
+
const normalizedTokenHash = this.tokenService.normalizeHash(intent.token.hash);
|
|
260
241
|
const isNative = normalizedTokenHash === this.tokenService.normalizeHash(BSSolanaConstants_1.BSSolanaConstants.NATIVE_TOKEN.hash);
|
|
261
242
|
if (isNative) {
|
|
262
243
|
transaction.add(web3_js_1.default.SystemProgram.transfer({
|
|
@@ -270,7 +251,7 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
270
251
|
const senderTokenAddress = yield solanaSplSDK.getAssociatedTokenAddress(tokenMintPublicKey, senderPublicKey);
|
|
271
252
|
const receiverTokenAddress = yield solanaSplSDK.getAssociatedTokenAddress(tokenMintPublicKey, receiverPublicKey);
|
|
272
253
|
try {
|
|
273
|
-
yield solanaSplSDK.getAccount(
|
|
254
|
+
yield solanaSplSDK.getAccount(this.connection, receiverTokenAddress);
|
|
274
255
|
}
|
|
275
256
|
catch (error) {
|
|
276
257
|
if (error instanceof solanaSplSDK.TokenAccountNotFoundError ||
|
|
@@ -286,7 +267,6 @@ _BSSolana_connection = new WeakMap(), _BSSolana_instances = new WeakSet(), _BSSo
|
|
|
286
267
|
return {
|
|
287
268
|
transaction,
|
|
288
269
|
senderPublicKey,
|
|
289
|
-
latestBlockhash,
|
|
290
270
|
};
|
|
291
271
|
});
|
|
292
272
|
};
|
|
@@ -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',
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TBSNetwork } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { TBSSolanaNetworkId } from '../types';
|
|
3
3
|
export declare class BSSolanaHelper {
|
|
4
|
-
static fixBip44Path(bip44Path: string): string;
|
|
5
|
-
static getBip44Path(path: string, index: number): string;
|
|
6
4
|
static isMainnetNetwork(network: TBSNetwork<TBSSolanaNetworkId>): boolean;
|
|
7
5
|
}
|
|
@@ -3,12 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BSSolanaHelper = void 0;
|
|
4
4
|
const BSSolanaConstants_1 = require("../constants/BSSolanaConstants");
|
|
5
5
|
class BSSolanaHelper {
|
|
6
|
-
static fixBip44Path(bip44Path) {
|
|
7
|
-
return bip44Path.replace('m/', '');
|
|
8
|
-
}
|
|
9
|
-
static getBip44Path(path, index) {
|
|
10
|
-
return this.fixBip44Path(path.replace('?', index.toString()));
|
|
11
|
-
}
|
|
12
6
|
static isMainnetNetwork(network) {
|
|
13
7
|
return BSSolanaConstants_1.BSSolanaConstants.MAINNET_NETWORK.id === network.id && network.type === 'mainnet';
|
|
14
8
|
}
|
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
|
+
}
|