solana-framework-deno
Version:
solana-framework-deno is solana uni-tools for deno
56 lines • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseSwapInstructions = exports.parseAddressLookupTableAccounts = exports.createJupiterApiClient = void 0;
const web3_js_1 = require("@solana/web3.js");
const sleep_1 = require("../utils/sleep");
const generated_1 = require("./generated");
const generated_2 = require("./generated");
const createJupiterApiClient = (config) => {
return new generated_1.DefaultApi(new generated_2.Configuration(config));
};
exports.createJupiterApiClient = createJupiterApiClient;
const deserializeInstruction = (instruction) => {
return new web3_js_1.TransactionInstruction({
programId: new web3_js_1.PublicKey(instruction.programId),
keys: instruction.accounts.map((key) => ({
pubkey: new web3_js_1.PublicKey(key.pubkey),
isSigner: key.isSigner,
isWritable: key.isWritable,
})),
data: Buffer.from(instruction.data, "base64"),
});
};
const parseAddressLookupTableAccounts = async (connection, keys) => {
while (true) {
try {
const addressLookupTableAccountInfos = await connection.getMultipleAccountsInfo(keys.map((key) => new web3_js_1.PublicKey(key)));
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
const addressLookupTableAddress = keys[index];
if (accountInfo) {
const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
key: new web3_js_1.PublicKey(addressLookupTableAddress),
state: web3_js_1.AddressLookupTableAccount.deserialize(accountInfo.data),
});
acc.push(addressLookupTableAccount);
}
return acc;
}, new Array());
}
catch (e) {
await (0, sleep_1.sleep)(0.2);
}
}
};
exports.parseAddressLookupTableAccounts = parseAddressLookupTableAccounts;
const parseSwapInstructions = (instructions) => {
const { tokenLedgerInstruction, computeBudgetInstructions, setupInstructions, swapInstruction, cleanupInstruction,
// addressLookupTableAddresses,
} = instructions;
const ixs = tokenLedgerInstruction ? [tokenLedgerInstruction] : [];
ixs.push(...computeBudgetInstructions, ...setupInstructions, swapInstruction);
if (cleanupInstruction)
ixs.push(cleanupInstruction);
return ixs.map(deserializeInstruction);
};
exports.parseSwapInstructions = parseSwapInstructions;
//# sourceMappingURL=index.js.map