@debridge-finance/solana-utils 6.2.4 → 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 +45 -48
- 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/cjs/spl.js +1 -20
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/helpers.js +42 -1
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/spl.js +2 -22
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/helpers.d.ts +5 -0
- package/dist/types/helpers.d.ts.map +1 -1
- package/dist/types/spl.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) {
|
|
@@ -10861,20 +10903,6 @@ const MetadataPointerLayout = struct$1([
|
|
|
10861
10903
|
publicKey$5('metadataAddress'),
|
|
10862
10904
|
]);
|
|
10863
10905
|
MetadataPointerLayout.span;
|
|
10864
|
-
function getMetadataPointerState(mint) {
|
|
10865
|
-
const extensionData = getExtensionData(ExtensionType.MetadataPointer, mint.tlvData);
|
|
10866
|
-
if (extensionData !== null) {
|
|
10867
|
-
const { authority, metadataAddress } = MetadataPointerLayout.decode(extensionData);
|
|
10868
|
-
// Explicitly set None/Zero keys to null
|
|
10869
|
-
return {
|
|
10870
|
-
authority: authority.equals(PublicKey.default) ? null : authority,
|
|
10871
|
-
metadataAddress: metadataAddress.equals(PublicKey.default) ? null : metadataAddress,
|
|
10872
|
-
};
|
|
10873
|
-
}
|
|
10874
|
-
else {
|
|
10875
|
-
return null;
|
|
10876
|
-
}
|
|
10877
|
-
}
|
|
10878
10906
|
|
|
10879
10907
|
/** Buffer layout for de/serializing a mint */
|
|
10880
10908
|
const MintCloseAuthorityLayout = struct$1([publicKey$5('closeAuthority')]);
|
|
@@ -11169,17 +11197,6 @@ function getExtensionData(extension, tlvData) {
|
|
|
11169
11197
|
}
|
|
11170
11198
|
return null;
|
|
11171
11199
|
}
|
|
11172
|
-
function getExtensionTypes(tlvData) {
|
|
11173
|
-
const extensionTypes = [];
|
|
11174
|
-
let extensionTypeIndex = 0;
|
|
11175
|
-
while (extensionTypeIndex < tlvData.length) {
|
|
11176
|
-
const entryType = tlvData.readUInt16LE(extensionTypeIndex);
|
|
11177
|
-
extensionTypes.push(entryType);
|
|
11178
|
-
const entryLength = tlvData.readUInt16LE(extensionTypeIndex + TYPE_SIZE);
|
|
11179
|
-
extensionTypeIndex += addTypeAndLengthToLen(entryLength);
|
|
11180
|
-
}
|
|
11181
|
-
return extensionTypes;
|
|
11182
|
-
}
|
|
11183
11200
|
|
|
11184
11201
|
/** Buffer layout for de/serializing a mint */
|
|
11185
11202
|
const MintLayout = struct$1([
|
|
@@ -13219,15 +13236,13 @@ function getTokenInfo(connection_1, tokenAddress_1) {
|
|
|
13219
13236
|
}
|
|
13220
13237
|
// fetcher encapsulates the actual work and is stored in cache when useCache is true
|
|
13221
13238
|
const fetcher = (() => __awaiter(this, void 0, void 0, function* () {
|
|
13222
|
-
var _a;
|
|
13223
13239
|
const [pda] = getTokenMetadataAddress(tokenAddress, TOKEN_METADATA_PROGRAM_ID);
|
|
13224
13240
|
const [tokenAccount, pdaAccount] = yield connection.getMultipleAccountsInfo([tokenAddress, pda]);
|
|
13225
13241
|
if (!tokenAccount || (tokenAccount === null || tokenAccount === void 0 ? void 0 : tokenAccount.lamports) === 0) {
|
|
13226
13242
|
return null;
|
|
13227
13243
|
}
|
|
13228
13244
|
const mint2022 = unpackMint(tokenAddress, tokenAccount, tokenAccount.owner);
|
|
13229
|
-
const
|
|
13230
|
-
const tokenMetaBuf = extTypes.includes(ExtensionType.TokenMetadata)
|
|
13245
|
+
const tokenMetaBuf = mint2022.tlvData.length
|
|
13231
13246
|
? getExtensionData(ExtensionType.TokenMetadata, mint2022.tlvData)
|
|
13232
13247
|
: null;
|
|
13233
13248
|
if (tokenMetaBuf) {
|
|
@@ -13241,24 +13256,6 @@ function getTokenInfo(connection_1, tokenAddress_1) {
|
|
|
13241
13256
|
tokenProgram: tokenAccount.owner,
|
|
13242
13257
|
};
|
|
13243
13258
|
}
|
|
13244
|
-
if (extTypes.includes(ExtensionType.MetadataPointer)) {
|
|
13245
|
-
const mpState = getMetadataPointerState(mint2022);
|
|
13246
|
-
if ((mpState === null || mpState === void 0 ? void 0 : mpState.metadataAddress) &&
|
|
13247
|
-
mpState.metadataAddress.equals(tokenAddress)) {
|
|
13248
|
-
const inlineMetaBuf = getExtensionData(ExtensionType.TokenMetadata, mint2022.tlvData);
|
|
13249
|
-
if (inlineMetaBuf) {
|
|
13250
|
-
const meta = unpack(inlineMetaBuf);
|
|
13251
|
-
return {
|
|
13252
|
-
address: tokenAddress,
|
|
13253
|
-
decimals: mint2022.decimals,
|
|
13254
|
-
name: meta.name,
|
|
13255
|
-
symbol: meta.symbol,
|
|
13256
|
-
json: meta.uri,
|
|
13257
|
-
tokenProgram: tokenAccount.owner,
|
|
13258
|
-
};
|
|
13259
|
-
}
|
|
13260
|
-
}
|
|
13261
|
-
}
|
|
13262
13259
|
// parse token account
|
|
13263
13260
|
// mint_authority - coption(pubkey) = 36
|
|
13264
13261
|
// supply - u64 = 8
|