@debridge-finance/solana-utils 4.5.2 → 4.5.3
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 +128 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/spl.js +119 -1
- package/dist/cjs/spl.js.map +1 -1
- package/dist/esm/spl.js +123 -1
- package/dist/esm/spl.js.map +1 -1
- package/dist/types/spl.d.ts +27 -1
- package/dist/types/spl.d.ts.map +1 -1
- package/package.json +6 -3
package/dist/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageV0, VersionedTransaction, Transaction, PublicKey, TransactionInstruction, SystemProgram, Keypair } from '@solana/web3.js';
|
|
1
|
+
import { MessageV0, VersionedTransaction, Transaction, PublicKey, TransactionInstruction, SystemProgram, AddressLookupTableAccount, Keypair } from '@solana/web3.js';
|
|
2
2
|
|
|
3
3
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
4
|
|
|
@@ -10262,6 +10262,128 @@ function checkIfAssociatedWalletExists(connection, mintAccount, originalWallet)
|
|
|
10262
10262
|
return accountData !== null;
|
|
10263
10263
|
});
|
|
10264
10264
|
}
|
|
10265
|
+
function getTransactionAccountsForSimulationDiff(connection, tx) {
|
|
10266
|
+
var _a, _b;
|
|
10267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10268
|
+
const result = new Set();
|
|
10269
|
+
if ("version" in tx) {
|
|
10270
|
+
const ALTs = tx.message.addressTableLookups.map((alt) => alt.accountKey);
|
|
10271
|
+
const fetchedALTs = yield connection.getMultipleAccountsInfo(ALTs);
|
|
10272
|
+
const parsedALTs = fetchedALTs
|
|
10273
|
+
.map((fetched, i) => fetched
|
|
10274
|
+
? new AddressLookupTableAccount({
|
|
10275
|
+
state: AddressLookupTableAccount.deserialize(fetched.data),
|
|
10276
|
+
key: ALTs[i],
|
|
10277
|
+
})
|
|
10278
|
+
: null)
|
|
10279
|
+
.filter((x) => x != null);
|
|
10280
|
+
const accGetter = tx.message.getAccountKeys({
|
|
10281
|
+
addressLookupTableAccounts: parsedALTs,
|
|
10282
|
+
});
|
|
10283
|
+
for (const acc of [
|
|
10284
|
+
...accGetter.staticAccountKeys,
|
|
10285
|
+
...((_b = (_a = accGetter.accountKeysFromLookups) === null || _a === void 0 ? void 0 : _a.writable) !== null && _b !== void 0 ? _b : []),
|
|
10286
|
+
]) {
|
|
10287
|
+
result.add(acc.toBase58());
|
|
10288
|
+
}
|
|
10289
|
+
}
|
|
10290
|
+
else {
|
|
10291
|
+
for (const ix of tx.instructions) {
|
|
10292
|
+
// we don't need read-only accounts and instruction.programId since they won't change
|
|
10293
|
+
ix.keys
|
|
10294
|
+
.filter((meta) => meta.isSigner || meta.isWritable)
|
|
10295
|
+
.map((meta) => result.add(meta.pubkey.toBase58()));
|
|
10296
|
+
}
|
|
10297
|
+
}
|
|
10298
|
+
return Array.from(result);
|
|
10299
|
+
});
|
|
10300
|
+
}
|
|
10301
|
+
function parseMultipleAccounts(accounts) {
|
|
10302
|
+
return accounts.map((account) => {
|
|
10303
|
+
var _a, _b;
|
|
10304
|
+
let parsedSplAccount;
|
|
10305
|
+
if (account) {
|
|
10306
|
+
const owner = new PublicKey(account.owner);
|
|
10307
|
+
if (owner.equals(TOKEN_PROGRAM_ID)) {
|
|
10308
|
+
if (account.data instanceof buffer.Buffer) {
|
|
10309
|
+
parsedSplAccount = parseSplAccount(account.data);
|
|
10310
|
+
}
|
|
10311
|
+
else if (account.data instanceof Array) {
|
|
10312
|
+
parsedSplAccount = parseSplAccount(buffer.Buffer.from(account.data[0], account.data[1]));
|
|
10313
|
+
}
|
|
10314
|
+
}
|
|
10315
|
+
}
|
|
10316
|
+
const parsedAccount = {
|
|
10317
|
+
balance: (_a = account === null || account === void 0 ? void 0 : account.lamports) !== null && _a !== void 0 ? _a : 0,
|
|
10318
|
+
};
|
|
10319
|
+
if (parsedSplAccount) {
|
|
10320
|
+
parsedAccount.spl = {
|
|
10321
|
+
mint: parsedSplAccount.mint,
|
|
10322
|
+
owner: parsedSplAccount.owner,
|
|
10323
|
+
balance: Number((_b = parsedSplAccount.amount) !== null && _b !== void 0 ? _b : 0),
|
|
10324
|
+
};
|
|
10325
|
+
}
|
|
10326
|
+
return parsedAccount;
|
|
10327
|
+
});
|
|
10328
|
+
}
|
|
10329
|
+
function getSplDiff(pre, post) {
|
|
10330
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10331
|
+
const preBalance = (_a = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _a !== void 0 ? _a : 0;
|
|
10332
|
+
const postBalance = (_b = post === null || post === void 0 ? void 0 : post.balance) !== null && _b !== void 0 ? _b : 0;
|
|
10333
|
+
return {
|
|
10334
|
+
mint: (_c = pre === null || pre === void 0 ? void 0 : pre.mint) !== null && _c !== void 0 ? _c : post === null || post === void 0 ? void 0 : post.mint,
|
|
10335
|
+
owner: (_d = pre === null || pre === void 0 ? void 0 : pre.owner) !== null && _d !== void 0 ? _d : post === null || post === void 0 ? void 0 : post.owner,
|
|
10336
|
+
preBalance: (_e = pre === null || pre === void 0 ? void 0 : pre.balance) !== null && _e !== void 0 ? _e : 0,
|
|
10337
|
+
postBalance: (_f = post === null || post === void 0 ? void 0 : post.balance) !== null && _f !== void 0 ? _f : 0,
|
|
10338
|
+
diff: postBalance - preBalance,
|
|
10339
|
+
};
|
|
10340
|
+
}
|
|
10341
|
+
function getTransactionDiff(connection, tx, txAccounts) {
|
|
10342
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10343
|
+
const accountsStrings = txAccounts
|
|
10344
|
+
? txAccounts.map((acc) => acc.toBase58())
|
|
10345
|
+
: yield getTransactionAccountsForSimulationDiff(connection, tx);
|
|
10346
|
+
const accountsPubKeys = txAccounts !== null && txAccounts !== void 0 ? txAccounts : accountsStrings.map((key) => new PublicKey(key));
|
|
10347
|
+
let [accountsInfo, simulatedTx] = yield Promise.all([
|
|
10348
|
+
connection.getMultipleAccountsInfo(accountsPubKeys),
|
|
10349
|
+
connection.simulateTransaction(tx, {
|
|
10350
|
+
replaceRecentBlockhash: true,
|
|
10351
|
+
accounts: {
|
|
10352
|
+
encoding: "base64",
|
|
10353
|
+
addresses: accountsStrings,
|
|
10354
|
+
},
|
|
10355
|
+
}),
|
|
10356
|
+
]);
|
|
10357
|
+
const simulatesInfo = simulatedTx.value.accounts;
|
|
10358
|
+
const preBalances = parseMultipleAccounts(accountsInfo);
|
|
10359
|
+
const postBalances = parseMultipleAccounts(simulatesInfo);
|
|
10360
|
+
const balancesDiff = accountsPubKeys.reduce((map, pubKey, i) => {
|
|
10361
|
+
var _a;
|
|
10362
|
+
if ((_a = accountsInfo[i]) === null || _a === void 0 ? void 0 : _a.executable) {
|
|
10363
|
+
return map;
|
|
10364
|
+
}
|
|
10365
|
+
const preBalance = preBalances[i];
|
|
10366
|
+
const postBalance = postBalances[i];
|
|
10367
|
+
const diff = {
|
|
10368
|
+
pubKey: pubKey,
|
|
10369
|
+
preBalance: preBalance.balance,
|
|
10370
|
+
postBalance: postBalance.balance,
|
|
10371
|
+
diff: postBalance.balance - preBalance.balance,
|
|
10372
|
+
};
|
|
10373
|
+
if (preBalance.spl || postBalance.spl) {
|
|
10374
|
+
const splDiff = getSplDiff(preBalance.spl, postBalance.spl);
|
|
10375
|
+
if (splDiff.diff) {
|
|
10376
|
+
diff.spl = splDiff;
|
|
10377
|
+
}
|
|
10378
|
+
}
|
|
10379
|
+
if (diff.diff || diff.spl) {
|
|
10380
|
+
map.set(pubKey.toString(), diff);
|
|
10381
|
+
}
|
|
10382
|
+
return map;
|
|
10383
|
+
}, new Map());
|
|
10384
|
+
return balancesDiff;
|
|
10385
|
+
});
|
|
10386
|
+
}
|
|
10265
10387
|
|
|
10266
10388
|
var spl = /*#__PURE__*/Object.freeze({
|
|
10267
10389
|
__proto__: null,
|
|
@@ -10278,7 +10400,11 @@ var spl = /*#__PURE__*/Object.freeze({
|
|
|
10278
10400
|
getTokenAccountsWithBalance: getTokenAccountsWithBalance,
|
|
10279
10401
|
buildReplenishWsolBalanceTransaction: buildReplenishWsolBalanceTransaction,
|
|
10280
10402
|
updateWsolBalance: updateWsolBalance,
|
|
10281
|
-
checkIfAssociatedWalletExists: checkIfAssociatedWalletExists
|
|
10403
|
+
checkIfAssociatedWalletExists: checkIfAssociatedWalletExists,
|
|
10404
|
+
getTransactionAccountsForSimulationDiff: getTransactionAccountsForSimulationDiff,
|
|
10405
|
+
parseMultipleAccounts: parseMultipleAccounts,
|
|
10406
|
+
getSplDiff: getSplDiff,
|
|
10407
|
+
getTransactionDiff: getTransactionDiff
|
|
10282
10408
|
});
|
|
10283
10409
|
|
|
10284
10410
|
const deBridge = "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh";
|