UNPKG

@marinade.finance/kamino-sdk

Version:
195 lines 8.63 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Whirlpool = void 0; const web3_js_1 = require("@solana/web3.js"); const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars const borsh = __importStar(require("@project-serum/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars const programId_1 = require("../programId"); class Whirlpool { whirlpoolsConfig; whirlpoolBump; tickSpacing; tickSpacingSeed; feeRate; protocolFeeRate; liquidity; sqrtPrice; tickCurrentIndex; protocolFeeOwedA; protocolFeeOwedB; tokenMintA; tokenVaultA; feeGrowthGlobalA; tokenMintB; tokenVaultB; feeGrowthGlobalB; rewardLastUpdatedTimestamp; rewardInfos; static discriminator = Buffer.from([63, 149, 209, 12, 225, 128, 99, 9]); static layout = borsh.struct([ borsh.publicKey('whirlpoolsConfig'), borsh.array(borsh.u8(), 1, 'whirlpoolBump'), borsh.u16('tickSpacing'), borsh.array(borsh.u8(), 2, 'tickSpacingSeed'), borsh.u16('feeRate'), borsh.u16('protocolFeeRate'), borsh.u128('liquidity'), borsh.u128('sqrtPrice'), borsh.i32('tickCurrentIndex'), borsh.u64('protocolFeeOwedA'), borsh.u64('protocolFeeOwedB'), borsh.publicKey('tokenMintA'), borsh.publicKey('tokenVaultA'), borsh.u128('feeGrowthGlobalA'), borsh.publicKey('tokenMintB'), borsh.publicKey('tokenVaultB'), borsh.u128('feeGrowthGlobalB'), borsh.u64('rewardLastUpdatedTimestamp'), borsh.array(types.WhirlpoolRewardInfo.layout(), 3, 'rewardInfos'), ]); constructor(fields) { this.whirlpoolsConfig = fields.whirlpoolsConfig; this.whirlpoolBump = fields.whirlpoolBump; this.tickSpacing = fields.tickSpacing; this.tickSpacingSeed = fields.tickSpacingSeed; this.feeRate = fields.feeRate; this.protocolFeeRate = fields.protocolFeeRate; this.liquidity = fields.liquidity; this.sqrtPrice = fields.sqrtPrice; this.tickCurrentIndex = fields.tickCurrentIndex; this.protocolFeeOwedA = fields.protocolFeeOwedA; this.protocolFeeOwedB = fields.protocolFeeOwedB; this.tokenMintA = fields.tokenMintA; this.tokenVaultA = fields.tokenVaultA; this.feeGrowthGlobalA = fields.feeGrowthGlobalA; this.tokenMintB = fields.tokenMintB; this.tokenVaultB = fields.tokenVaultB; this.feeGrowthGlobalB = fields.feeGrowthGlobalB; this.rewardLastUpdatedTimestamp = fields.rewardLastUpdatedTimestamp; this.rewardInfos = fields.rewardInfos.map((item) => new types.WhirlpoolRewardInfo({ ...item })); } static async fetch(c, address) { const info = await c.getAccountInfo(address); if (info === null) { return null; } if (!info.owner.equals(programId_1.WHIRLPOOL_PROGRAM_ID)) { throw new Error("account doesn't belong to this program"); } return this.decode(info.data); } static async fetchMultiple(c, addresses) { const infos = await c.getMultipleAccountsInfo(addresses); return infos.map((info) => { if (info === null) { return null; } if (!info.owner.equals(programId_1.WHIRLPOOL_PROGRAM_ID)) { throw new Error("account doesn't belong to this program"); } return this.decode(info.data); }); } static decode(data) { if (!data.slice(0, 8).equals(Whirlpool.discriminator)) { throw new Error('invalid account discriminator'); } const dec = Whirlpool.layout.decode(data.slice(8)); return new Whirlpool({ whirlpoolsConfig: dec.whirlpoolsConfig, whirlpoolBump: dec.whirlpoolBump, tickSpacing: dec.tickSpacing, tickSpacingSeed: dec.tickSpacingSeed, feeRate: dec.feeRate, protocolFeeRate: dec.protocolFeeRate, liquidity: dec.liquidity, sqrtPrice: dec.sqrtPrice, tickCurrentIndex: dec.tickCurrentIndex, protocolFeeOwedA: dec.protocolFeeOwedA, protocolFeeOwedB: dec.protocolFeeOwedB, tokenMintA: dec.tokenMintA, tokenVaultA: dec.tokenVaultA, feeGrowthGlobalA: dec.feeGrowthGlobalA, tokenMintB: dec.tokenMintB, tokenVaultB: dec.tokenVaultB, feeGrowthGlobalB: dec.feeGrowthGlobalB, rewardLastUpdatedTimestamp: dec.rewardLastUpdatedTimestamp, rewardInfos: dec.rewardInfos.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => types.WhirlpoolRewardInfo.fromDecoded(item)), }); } toJSON() { return { whirlpoolsConfig: this.whirlpoolsConfig.toString(), whirlpoolBump: this.whirlpoolBump, tickSpacing: this.tickSpacing, tickSpacingSeed: this.tickSpacingSeed, feeRate: this.feeRate, protocolFeeRate: this.protocolFeeRate, liquidity: this.liquidity.toString(), sqrtPrice: this.sqrtPrice.toString(), tickCurrentIndex: this.tickCurrentIndex, protocolFeeOwedA: this.protocolFeeOwedA.toString(), protocolFeeOwedB: this.protocolFeeOwedB.toString(), tokenMintA: this.tokenMintA.toString(), tokenVaultA: this.tokenVaultA.toString(), feeGrowthGlobalA: this.feeGrowthGlobalA.toString(), tokenMintB: this.tokenMintB.toString(), tokenVaultB: this.tokenVaultB.toString(), feeGrowthGlobalB: this.feeGrowthGlobalB.toString(), rewardLastUpdatedTimestamp: this.rewardLastUpdatedTimestamp.toString(), rewardInfos: this.rewardInfos.map((item) => item.toJSON()), }; } static fromJSON(obj) { return new Whirlpool({ whirlpoolsConfig: new web3_js_1.PublicKey(obj.whirlpoolsConfig), whirlpoolBump: obj.whirlpoolBump, tickSpacing: obj.tickSpacing, tickSpacingSeed: obj.tickSpacingSeed, feeRate: obj.feeRate, protocolFeeRate: obj.protocolFeeRate, liquidity: new bn_js_1.default(obj.liquidity), sqrtPrice: new bn_js_1.default(obj.sqrtPrice), tickCurrentIndex: obj.tickCurrentIndex, protocolFeeOwedA: new bn_js_1.default(obj.protocolFeeOwedA), protocolFeeOwedB: new bn_js_1.default(obj.protocolFeeOwedB), tokenMintA: new web3_js_1.PublicKey(obj.tokenMintA), tokenVaultA: new web3_js_1.PublicKey(obj.tokenVaultA), feeGrowthGlobalA: new bn_js_1.default(obj.feeGrowthGlobalA), tokenMintB: new web3_js_1.PublicKey(obj.tokenMintB), tokenVaultB: new web3_js_1.PublicKey(obj.tokenVaultB), feeGrowthGlobalB: new bn_js_1.default(obj.feeGrowthGlobalB), rewardLastUpdatedTimestamp: new bn_js_1.default(obj.rewardLastUpdatedTimestamp), rewardInfos: obj.rewardInfos.map((item) => types.WhirlpoolRewardInfo.fromJSON(item)), }); } } exports.Whirlpool = Whirlpool; //# sourceMappingURL=Whirlpool.js.map