@debridge-finance/solana-utils 6.2.5 → 6.3.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/dist/browser/index.js +44 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/helpers.js +40 -0
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/esm/helpers.js +42 -1
- package/dist/esm/helpers.js.map +1 -1
- package/dist/types/helpers.d.ts +5 -0
- package/dist/types/helpers.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import require$$1, { PublicKey, TransactionInstruction, SystemProgram, SYSVAR_CLOCK_PUBKEY, MessageV0, VersionedTransaction, Transaction, AddressLookupTableAccount, Keypair } from '@solana/web3.js';
|
|
1
|
+
import require$$1, { PublicKey, TransactionInstruction, SystemProgram, SYSVAR_CLOCK_PUBKEY, MessageV0, VersionedTransaction, Transaction, SYSVAR_RENT_PUBKEY, AddressLookupTableAccount, Keypair } from '@solana/web3.js';
|
|
2
2
|
|
|
3
3
|
var commonjsGlobal$1 = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
4
|
|
|
@@ -6801,6 +6801,47 @@ function sendAll(connection, wallet, transactions, options) {
|
|
|
6801
6801
|
return txIds;
|
|
6802
6802
|
});
|
|
6803
6803
|
}
|
|
6804
|
+
const DEFAULT_RENT_SYSVAR_TTL_MS = 60 * 60 * 1000;
|
|
6805
|
+
// Solana runtime ACCOUNT_STORAGE_OVERHEAD: bytes charged for account metadata on top of data size
|
|
6806
|
+
const ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
6807
|
+
let rentSysvarCache = null;
|
|
6808
|
+
function decodeRentSysvar(data) {
|
|
6809
|
+
return {
|
|
6810
|
+
lamportsPerByteYear: data.readBigUInt64LE(0),
|
|
6811
|
+
exemptionThreshold: data.readDoubleLE(8),
|
|
6812
|
+
burnPercent: data.readUInt8(16),
|
|
6813
|
+
};
|
|
6814
|
+
}
|
|
6815
|
+
/**
|
|
6816
|
+
* Returns Rent sysvar, cached for `ttlMs` (1 hour by default)
|
|
6817
|
+
*/
|
|
6818
|
+
function getRentSysvar(connection, ttlMs = DEFAULT_RENT_SYSVAR_TTL_MS) {
|
|
6819
|
+
if (rentSysvarCache && Date.now() - rentSysvarCache.fetchedAt < ttlMs)
|
|
6820
|
+
return rentSysvarCache.rent;
|
|
6821
|
+
const rent = getAccountInfo(connection, SYSVAR_RENT_PUBKEY).then((info) => {
|
|
6822
|
+
if (!info)
|
|
6823
|
+
throw new Error("Failed to fetch Rent sysvar");
|
|
6824
|
+
return decodeRentSysvar(buffer.Buffer.from(info.data));
|
|
6825
|
+
});
|
|
6826
|
+
rentSysvarCache = { rent, fetchedAt: Date.now() };
|
|
6827
|
+
rent.catch(() => {
|
|
6828
|
+
if ((rentSysvarCache === null || rentSysvarCache === void 0 ? void 0 : rentSysvarCache.rent) === rent)
|
|
6829
|
+
rentSysvarCache = null;
|
|
6830
|
+
});
|
|
6831
|
+
return rent;
|
|
6832
|
+
}
|
|
6833
|
+
/**
|
|
6834
|
+
* Calculates minimum lamports balance for an account with `dataSize` bytes of data to be rent exempt.
|
|
6835
|
+
* Same result as `connection.getMinimumBalanceForRentExemption`, but Rent sysvar is cached for `ttlMs` (1 hour by default)
|
|
6836
|
+
*/
|
|
6837
|
+
function getRentExemptBalance(connection_1, dataSize_1) {
|
|
6838
|
+
return __awaiter(this, arguments, void 0, function* (connection, dataSize, ttlMs = DEFAULT_RENT_SYSVAR_TTL_MS) {
|
|
6839
|
+
const { lamportsPerByteYear, exemptionThreshold } = yield getRentSysvar(connection, ttlMs);
|
|
6840
|
+
return Math.floor((ACCOUNT_STORAGE_OVERHEAD + dataSize) *
|
|
6841
|
+
Number(lamportsPerByteYear) *
|
|
6842
|
+
exemptionThreshold);
|
|
6843
|
+
});
|
|
6844
|
+
}
|
|
6804
6845
|
|
|
6805
6846
|
var helpers = /*#__PURE__*/Object.freeze({
|
|
6806
6847
|
__proto__: null,
|
|
@@ -6812,7 +6853,8 @@ var helpers = /*#__PURE__*/Object.freeze({
|
|
|
6812
6853
|
bufferToHex: bufferToHex,
|
|
6813
6854
|
sleep: sleep,
|
|
6814
6855
|
Wallet: Wallet,
|
|
6815
|
-
sendAll: sendAll
|
|
6856
|
+
sendAll: sendAll,
|
|
6857
|
+
getRentExemptBalance: getRentExemptBalance
|
|
6816
6858
|
});
|
|
6817
6859
|
|
|
6818
6860
|
function isBuffer(arg) {
|