import {
fetchKaminoVaultPriceContext,
buildKaminoVaultReserveRefreshInstructions,
} from "@exponent-labs/exponent-sdk";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
const priceContext = await fetchKaminoVaultPriceContext(connection, kaminoVault);
const reserveRefreshes = buildKaminoVaultReserveRefreshInstructions(priceContext.reserves);
const prices = await vault.fetcher.fetchExponentPrices();
const matchingPrices = prices.prices.flatMap((entry) => entry &&
entry.priceMint.equals(sharesMint) && entry.underlyingMint.equals(depositMint) &&
entry.interfaceAccounts.length === priceContext.interfaceAccounts.length &&
entry.interfaceAccounts.every((key, i) => key.equals(priceContext.interfaceAccounts[i]))
? [entry] : []);
if (matchingPrices.length !== 1) throw new Error("Expected one configured Kamino Vault share price");
const sharePrice = matchingPrices[0];
const shareMintAccount = await connection.getAccountInfo(sharesMint);
if (!shareMintAccount) throw new Error("Missing shares mint");
const sharesAta = getAssociatedTokenAddressSync(
sharesMint, vault.state.squadsVault, true, shareMintAccount.owner,
);
const registerShares = vault.ixWrapperManagerUpdatePosition({
manager: manager.publicKey,
update: {
__kind: "TrackKaminoVaultShares",
sharesMint,
depositTokenMint: depositMint,
sharesTokenAccount: sharesAta,
priceInterfaceAccounts: sharePrice.priceInterfaceAccounts,
},
remainingAccounts: await vault.getResolvedAumRemainingAccountMetas(
[sharesAta, sharePrice.priceInterfaceAccounts, ...priceContext.interfaceAccounts]
.map((pubkey) => ({ pubkey, isSigner: false, isWritable: false })),
),
});