@sol-synth-engine/js-client
Version:
JavaScript client for Sol Synth Engine
33 lines (32 loc) • 2.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MARKET_TREASURY_ACCOUNT_SEED = exports.MARKET_UNDERLYING_TOKEN_ACCOUNT_SEED = exports.MARKET_SEED = exports.PROTOCOL_CONFIG_SEED = exports.deriveAddress = void 0;
exports.deriveProtocolConfigAddress = deriveProtocolConfigAddress;
exports.deriveMarketAddress = deriveMarketAddress;
exports.deriveMarketUnderlyingTokenAccountAddress = deriveMarketUnderlyingTokenAccountAddress;
exports.deriveMarketTreasuryAccountAddress = deriveMarketTreasuryAccountAddress;
const web3_js_1 = require("@solana/web3.js");
const bn_js_1 = __importDefault(require("bn.js"));
const deriveAddress = (seeds, programId) => {
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
};
exports.deriveAddress = deriveAddress;
exports.PROTOCOL_CONFIG_SEED = Buffer.from("config");
exports.MARKET_SEED = Buffer.from("market");
exports.MARKET_UNDERLYING_TOKEN_ACCOUNT_SEED = Buffer.from("market_underlying_token_account");
exports.MARKET_TREASURY_ACCOUNT_SEED = Buffer.from("market_treasury_account");
function deriveProtocolConfigAddress(configIndex, programId) {
return (0, exports.deriveAddress)([exports.PROTOCOL_CONFIG_SEED, new bn_js_1.default(configIndex).toArrayLike(Buffer, "le", 2)], programId);
}
function deriveMarketAddress(protocolConfig, marketIndex, programId) {
return (0, exports.deriveAddress)([exports.MARKET_SEED, protocolConfig.toBuffer(), new bn_js_1.default(marketIndex).toArrayLike(Buffer, "le", 2)], programId);
}
function deriveMarketUnderlyingTokenAccountAddress(market, underlyingToken, programId) {
return (0, exports.deriveAddress)([exports.MARKET_UNDERLYING_TOKEN_ACCOUNT_SEED, market.toBuffer(), underlyingToken.toBuffer()], programId);
}
function deriveMarketTreasuryAccountAddress(market, treasuryMint, programId) {
return (0, exports.deriveAddress)([exports.MARKET_TREASURY_ACCOUNT_SEED, market.toBuffer(), treasuryMint.toBuffer()], programId);
}