@orca-so/whirlpool-sdk
Version:
Whirlpool SDK for the Orca protocol.
41 lines (40 loc) • 1.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.deserializeTokenAccount = void 0;
const spl_token_1 = require("@solana/spl-token");
const web3_js_1 = require("@solana/web3.js");
const deserializeTokenAccount = (data) => {
if (!data) {
return null;
}
const accountInfo = spl_token_1.AccountLayout.decode(data);
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
if (accountInfo.delegateOption === 0) {
accountInfo.delegate = null;
accountInfo.delegatedAmount = new spl_token_1.u64(0);
}
else {
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
}
accountInfo.isInitialized = accountInfo.state !== 0;
accountInfo.isFrozen = accountInfo.state === 2;
if (accountInfo.isNativeOption === 1) {
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
accountInfo.isNative = true;
}
else {
accountInfo.rentExemptReserve = null;
accountInfo.isNative = false;
}
if (accountInfo.closeAuthorityOption === 0) {
accountInfo.closeAuthority = null;
}
else {
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
}
return accountInfo;
};
exports.deserializeTokenAccount = deserializeTokenAccount;
;