@debridge-finance/solana-utils 4.1.0 → 4.2.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/LICENSE CHANGED
@@ -1,100 +1,100 @@
1
- Business Source License 1.1
2
-
3
- License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
- "Business Source License" is a trademark of MariaDB Corporation Ab.
5
-
6
- -----------------------------------------------------------------------------
7
-
8
- Parameters
9
-
10
- Licensor: DxTech Inc. (Company No.155728732)
11
-
12
- Licensed Work: deBridge V1
13
- The Licensed Work is (c) 2021 DxTech Inc.
14
-
15
- Additional Use Grant: Any uses listed and defined at
16
- v1-license-grants.dbr.eth
17
-
18
- Change Date: The earlier of 31 December 2025 or a date specified at
19
- v1-license-date.dbr.eth
20
-
21
- Change License: GNU General Public License v2.0 or later
22
-
23
- -----------------------------------------------------------------------------
24
-
25
- Terms
26
-
27
- The Licensor hereby grants you the right to copy, modify, create derivative
28
- works, redistribute, and make non-production use of the Licensed Work. The
29
- Licensor may make an Additional Use Grant, above, permitting limited
30
- production use.
31
-
32
- Effective on the Change Date, or the fourth anniversary of the first publicly
33
- available distribution of a specific version of the Licensed Work under this
34
- License, whichever comes first, the Licensor hereby grants you rights under
35
- the terms of the Change License, and the rights granted in the paragraph
36
- above terminate.
37
-
38
- If your use of the Licensed Work does not comply with the requirements
39
- currently in effect as described in this License, you must purchase a
40
- commercial license from the Licensor, its affiliated entities, or authorized
41
- resellers, or you must refrain from using the Licensed Work.
42
-
43
- All copies of the original and modified Licensed Work, and derivative works
44
- of the Licensed Work, are subject to this License. This License applies
45
- separately for each version of the Licensed Work and the Change Date may vary
46
- for each version of the Licensed Work released by Licensor.
47
-
48
- You must conspicuously display this License on each original or modified copy
49
- of the Licensed Work. If you receive the Licensed Work in original or
50
- modified form from a third party, the terms and conditions set forth in this
51
- License apply to your use of that work.
52
-
53
- Any use of the Licensed Work in violation of this License will automatically
54
- terminate your rights under this License for the current and all other
55
- versions of the Licensed Work.
56
-
57
- This License does not grant you any right in any trademark or logo of
58
- Licensor or its affiliates (provided that you may use a trademark or logo of
59
- Licensor as expressly required by this License).
60
-
61
- TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
62
- AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
63
- EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
64
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
65
- TITLE.
66
-
67
- MariaDB hereby grants you permission to use this License’s text to license
68
- your works, and to refer to it using the trademark "Business Source License",
69
- as long as you comply with the Covenants of Licensor below.
70
-
71
- -----------------------------------------------------------------------------
72
-
73
- Covenants of Licensor
74
-
75
- In consideration of the right to use this License’s text and the "Business
76
- Source License" name and trademark, Licensor covenants to MariaDB, and to all
77
- other recipients of the licensed work to be provided by Licensor:
78
-
79
- 1. To specify as the Change License the GPL Version 2.0 or any later version,
80
- or a license that is compatible with GPL Version 2.0 or a later version,
81
- where "compatible" means that software provided under the Change License can
82
- be included in a program with software provided under GPL Version 2.0 or a
83
- later version. Licensor may specify additional Change Licenses without
84
- limitation.
85
-
86
- 2. To either: (a) specify an additional grant of rights to use that does not
87
- impose any additional restriction on the right granted in this License, as
88
- the Additional Use Grant; or (b) insert the text "None".
89
-
90
- 3. To specify a Change Date.
91
-
92
- 4. Not to modify this License in any other way.
93
-
94
- -----------------------------------------------------------------------------
95
-
96
- Notice
97
-
98
- The Business Source License (this document, or the "License") is not an Open
99
- Source license. However, the Licensed Work will eventually be made available
100
- under an Open Source License, as stated in this License.
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: DxTech Inc. (Company No.155728732)
11
+
12
+ Licensed Work: deBridge V1
13
+ The Licensed Work is (c) 2021 DxTech Inc.
14
+
15
+ Additional Use Grant: Any uses listed and defined at
16
+ v1-license-grants.dbr.eth
17
+
18
+ Change Date: The earlier of 31 December 2025 or a date specified at
19
+ v1-license-date.dbr.eth
20
+
21
+ Change License: GNU General Public License v2.0 or later
22
+
23
+ -----------------------------------------------------------------------------
24
+
25
+ Terms
26
+
27
+ The Licensor hereby grants you the right to copy, modify, create derivative
28
+ works, redistribute, and make non-production use of the Licensed Work. The
29
+ Licensor may make an Additional Use Grant, above, permitting limited
30
+ production use.
31
+
32
+ Effective on the Change Date, or the fourth anniversary of the first publicly
33
+ available distribution of a specific version of the Licensed Work under this
34
+ License, whichever comes first, the Licensor hereby grants you rights under
35
+ the terms of the Change License, and the rights granted in the paragraph
36
+ above terminate.
37
+
38
+ If your use of the Licensed Work does not comply with the requirements
39
+ currently in effect as described in this License, you must purchase a
40
+ commercial license from the Licensor, its affiliated entities, or authorized
41
+ resellers, or you must refrain from using the Licensed Work.
42
+
43
+ All copies of the original and modified Licensed Work, and derivative works
44
+ of the Licensed Work, are subject to this License. This License applies
45
+ separately for each version of the Licensed Work and the Change Date may vary
46
+ for each version of the Licensed Work released by Licensor.
47
+
48
+ You must conspicuously display this License on each original or modified copy
49
+ of the Licensed Work. If you receive the Licensed Work in original or
50
+ modified form from a third party, the terms and conditions set forth in this
51
+ License apply to your use of that work.
52
+
53
+ Any use of the Licensed Work in violation of this License will automatically
54
+ terminate your rights under this License for the current and all other
55
+ versions of the Licensed Work.
56
+
57
+ This License does not grant you any right in any trademark or logo of
58
+ Licensor or its affiliates (provided that you may use a trademark or logo of
59
+ Licensor as expressly required by this License).
60
+
61
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
62
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
63
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
65
+ TITLE.
66
+
67
+ MariaDB hereby grants you permission to use this License’s text to license
68
+ your works, and to refer to it using the trademark "Business Source License",
69
+ as long as you comply with the Covenants of Licensor below.
70
+
71
+ -----------------------------------------------------------------------------
72
+
73
+ Covenants of Licensor
74
+
75
+ In consideration of the right to use this License’s text and the "Business
76
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
77
+ other recipients of the licensed work to be provided by Licensor:
78
+
79
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
80
+ or a license that is compatible with GPL Version 2.0 or a later version,
81
+ where "compatible" means that software provided under the Change License can
82
+ be included in a program with software provided under GPL Version 2.0 or a
83
+ later version. Licensor may specify additional Change Licenses without
84
+ limitation.
85
+
86
+ 2. To either: (a) specify an additional grant of rights to use that does not
87
+ impose any additional restriction on the right granted in this License, as
88
+ the Additional Use Grant; or (b) insert the text "None".
89
+
90
+ 3. To specify a Change Date.
91
+
92
+ 4. Not to modify this License in any other way.
93
+
94
+ -----------------------------------------------------------------------------
95
+
96
+ Notice
97
+
98
+ The Business Source License (this document, or the "License") is not an Open
99
+ Source license. However, the Licensed Work will eventually be made available
100
+ under an Open Source License, as stated in this License.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # `solana-utils` by deBridge
2
-
1
+ # `solana-utils` by deBridge
2
+
3
3
  Common utils package to power communication with Solana contracts at [deBridge](https://debridge.finance).
@@ -6414,7 +6414,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
6414
6414
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6415
6415
  step((generator = generator.apply(thisArg, _arguments || [])).next());
6416
6416
  });
6417
- }
6417
+ }
6418
+
6419
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
6420
+ var e = new Error(message);
6421
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
6422
+ };
6418
6423
 
6419
6424
  const BPS_DENOMINATOR = 10000;
6420
6425
  const SOLANA_CHAIN_ID = 7565164;
@@ -6632,9 +6637,9 @@ function setBlockhash(transaction, blockhash) {
6632
6637
  * @returns
6633
6638
  */
6634
6639
  function sendAll(connection, wallet, transactions, options) {
6635
- var _a, _b;
6640
+ var _a, _b, _c;
6636
6641
  return __awaiter(this, void 0, void 0, function* () {
6637
- const blockhashCommitment = (options === null || options === void 0 ? void 0 : options.blockhashCommitment) === undefined ? "finalized" : options.blockhashCommitment;
6642
+ const blockhashCommitment = (options === null || options === void 0 ? void 0 : options.blockhashCommitment) === undefined ? (_a = connection.commitment) !== null && _a !== void 0 ? _a : "confirmed" : options.blockhashCommitment;
6638
6643
  const convertIntoTxV0 = (options === null || options === void 0 ? void 0 : options.convertIntoTxV0) === undefined ? true : options.convertIntoTxV0;
6639
6644
  (options === null || options === void 0 ? void 0 : options.debug) === undefined ? false : options.debug;
6640
6645
  const skipPreflight = (options === null || options === void 0 ? void 0 : options.skipPreflight) === undefined ? false : options.skipPreflight;
@@ -6647,7 +6652,7 @@ function sendAll(connection, wallet, transactions, options) {
6647
6652
  let txIds = [];
6648
6653
  if ((options === null || options === void 0 ? void 0 : options.waitBetweenSend) === undefined || options.waitBetweenSend === 0) {
6649
6654
  yield Promise.all(transactions.map((tx) => __awaiter(this, void 0, void 0, function* () {
6650
- var _c;
6655
+ var _d;
6651
6656
  let txV0;
6652
6657
  if (isVersionedTx(tx)) {
6653
6658
  tx.message.recentBlockhash = FAKE_BLOCKHASH;
@@ -6667,10 +6672,10 @@ function sendAll(connection, wallet, transactions, options) {
6667
6672
  const simulationResult = yield connection.simulateTransaction(txV0, {
6668
6673
  sigVerify: false,
6669
6674
  replaceRecentBlockhash: true,
6670
- commitment: "confirmed",
6675
+ commitment: blockhashCommitment,
6671
6676
  });
6672
6677
  if (simulationResult.value.err !== null) {
6673
- throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_c = simulationResult.value.logs) === null || _c === void 0 ? void 0 : _c.join("\n")}`);
6678
+ throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_d = simulationResult.value.logs) === null || _d === void 0 ? void 0 : _d.join("\n")}`);
6674
6679
  }
6675
6680
  }
6676
6681
  })));
@@ -6713,11 +6718,11 @@ function sendAll(connection, wallet, transactions, options) {
6713
6718
  commitment: "confirmed",
6714
6719
  });
6715
6720
  if (simulationResult.value.err !== null) {
6716
- throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_a = simulationResult.value.logs) === null || _a === void 0 ? void 0 : _a.join("\n")}`);
6721
+ throw new Error(`Tx simulation Error! Transaction message dump: ${buffer.Buffer.from(txV0.serialize()).toString("base64")}\n Error: ${JSON.stringify(simulationResult.value.err)}, logs:\n ${(_b = simulationResult.value.logs) === null || _b === void 0 ? void 0 : _b.join("\n")}`);
6717
6722
  }
6718
6723
  }
6719
6724
  const serialized = buffer.Buffer.from(signed.serialize());
6720
- (_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.call(options, `Sending tx: ${serialized.toString("base64")}`);
6725
+ (_c = options === null || options === void 0 ? void 0 : options.logger) === null || _c === void 0 ? void 0 : _c.call(options, `Sending tx: ${serialized.toString("base64")}`);
6721
6726
  txIds.push(yield sendWithRetries(connection, serialized, lastValidBlockHeight, rpcCalls, blockhashCommitment));
6722
6727
  yield sleep(options.waitBetweenSend);
6723
6728
  }
@@ -9512,6 +9517,49 @@ var AccountType;
9512
9517
  AccountType[AccountType["Unknown"] = 3] = "Unknown";
9513
9518
  AccountType[AccountType["NotExists"] = 4] = "NotExists";
9514
9519
  })(AccountType || (AccountType = {}));
9520
+ /**
9521
+ * Get name, symbol and decimals for provided token
9522
+ * @param connection solana web3 connection
9523
+ * @param tokenAddress address to get metaplex info for
9524
+ * @returns
9525
+ */
9526
+ function getTokenInfo(connection, tokenAddress) {
9527
+ return __awaiter(this, void 0, void 0, function* () {
9528
+ const tokenMetaProgramId = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
9529
+ const findMetaplexMetadataPda = (tokenMint) => PublicKey.findProgramAddressSync([buffer.Buffer.from('metadata', 'utf-8'), tokenMetaProgramId.toBuffer(), tokenMint.toBuffer()], tokenMetaProgramId)[0];
9530
+ const decodeMetaplexMetadataPartial = (data) => {
9531
+ const rawName = data.subarray(65 + 4, 65 + 36); // omit first 4 bytes, size is already hardcoded
9532
+ const rawSymbol = data.subarray(101 + 4, 115); // omit first 4 bytes, size is already hardcoded
9533
+ const rawUri = data.subarray(115 + 4, 204); // omit first 4 bytes, size is already hardcoded
9534
+ return {
9535
+ uri: rawUri.toString("utf-8").replace(/\u0000/g, ""),
9536
+ symbol: rawSymbol.toString("utf-8").replace(/\u0000/g, ""),
9537
+ name: rawName.toString("utf-8").replace(/\u0000/g, ""),
9538
+ };
9539
+ };
9540
+ const pda = findMetaplexMetadataPda(tokenAddress);
9541
+ const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([tokenAddress, pda]);
9542
+ if (tokenAccount === null || pdaAccount === null || (pdaAccount === null || pdaAccount === void 0 ? void 0 : pdaAccount.lamports) === 0) {
9543
+ return null;
9544
+ }
9545
+ // parse token account
9546
+ // mint_authority - coption(pubkey) = 4 or 36
9547
+ // supply - u64 = 8
9548
+ // decimals - u8
9549
+ let decimalsOffset = 12;
9550
+ if (tokenAccount.data[0] === 1)
9551
+ decimalsOffset += 32;
9552
+ const decimals = tokenAccount.data[decimalsOffset];
9553
+ const { name, symbol, uri } = decodeMetaplexMetadataPartial(pdaAccount.data);
9554
+ return {
9555
+ address: tokenAddress,
9556
+ decimals,
9557
+ name,
9558
+ symbol,
9559
+ json: uri,
9560
+ };
9561
+ });
9562
+ }
9515
9563
  /**
9516
9564
  * Builds instruction for creation of associated wallet for specified token
9517
9565
  * @param tokenMint mint account of SPL-token
@@ -9746,6 +9794,7 @@ function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet)
9746
9794
  var spl = /*#__PURE__*/Object.freeze({
9747
9795
  __proto__: null,
9748
9796
  get AccountType () { return AccountType; },
9797
+ getTokenInfo: getTokenInfo,
9749
9798
  createAssociatedWalletInstruction: createAssociatedWalletInstruction,
9750
9799
  parseSplAccount: parseSplAccount,
9751
9800
  isWalletCorrectATA: isWalletCorrectATA,