@rainfi/sdk
Version:
This package is used to interact with Rain.fi protocol on Solana
350 lines • 14.6 kB
JavaScript
"use strict";
/**
* This code was GENERATED using the solita package.
* Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality.
*
* See: https://github.com/metaplex-foundation/solita
*/
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.nftSwapPairBeet = exports.NftSwapPair = void 0;
const beet = __importStar(require("@metaplex-foundation/beet"));
const beetSolana = __importStar(require("@metaplex-foundation/beet-solana"));
const PairType_1 = require("../types/PairType");
const PairState_1 = require("../types/PairState");
const PairAuthorityType_1 = require("../types/PairAuthorityType");
const BondingCurve_1 = require("../types/BondingCurve");
const nftSwapPairDiscriminator = [135, 107, 253, 45, 248, 141, 233, 126];
/**
* Holds the data for the {@link NftSwapPair} Account and provides de/serialization
* functionality for that data
*
* @category Accounts
* @category generated
*/
class NftSwapPair {
constructor(hadoMarket, pairType, pairState, pairAuthorityType, pairAuthorityAdapterProgram, lpTokensMint, lpTokensInCirculation, bondingCurve, baseSpotPrice, fee, mathCounter, currentSpotPrice, feeTokenAccount, feeVaultSeed, solOrTokenFeeAmount, fundsTokenAccount, fundsSolVaultSeed, fundsSolOrTokenBalance, initialFundsSolOrTokenBalance, buyOrdersQuantity, nftsSeed, nftsCount, lastTransactedAt, concentrationIndex, assetReceiver) {
this.hadoMarket = hadoMarket;
this.pairType = pairType;
this.pairState = pairState;
this.pairAuthorityType = pairAuthorityType;
this.pairAuthorityAdapterProgram = pairAuthorityAdapterProgram;
this.lpTokensMint = lpTokensMint;
this.lpTokensInCirculation = lpTokensInCirculation;
this.bondingCurve = bondingCurve;
this.baseSpotPrice = baseSpotPrice;
this.fee = fee;
this.mathCounter = mathCounter;
this.currentSpotPrice = currentSpotPrice;
this.feeTokenAccount = feeTokenAccount;
this.feeVaultSeed = feeVaultSeed;
this.solOrTokenFeeAmount = solOrTokenFeeAmount;
this.fundsTokenAccount = fundsTokenAccount;
this.fundsSolVaultSeed = fundsSolVaultSeed;
this.fundsSolOrTokenBalance = fundsSolOrTokenBalance;
this.initialFundsSolOrTokenBalance = initialFundsSolOrTokenBalance;
this.buyOrdersQuantity = buyOrdersQuantity;
this.nftsSeed = nftsSeed;
this.nftsCount = nftsCount;
this.lastTransactedAt = lastTransactedAt;
this.concentrationIndex = concentrationIndex;
this.assetReceiver = assetReceiver;
}
/**
* Creates a {@link NftSwapPair} instance from the provided args.
*/
static fromArgs(args) {
return new NftSwapPair(args.hadoMarket, args.pairType, args.pairState, args.pairAuthorityType, args.pairAuthorityAdapterProgram, args.lpTokensMint, args.lpTokensInCirculation, args.bondingCurve, args.baseSpotPrice, args.fee, args.mathCounter, args.currentSpotPrice, args.feeTokenAccount, args.feeVaultSeed, args.solOrTokenFeeAmount, args.fundsTokenAccount, args.fundsSolVaultSeed, args.fundsSolOrTokenBalance, args.initialFundsSolOrTokenBalance, args.buyOrdersQuantity, args.nftsSeed, args.nftsCount, args.lastTransactedAt, args.concentrationIndex, args.assetReceiver);
}
/**
* Deserializes the {@link NftSwapPair} from the data of the provided {@link web3.AccountInfo}.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
static fromAccountInfo(accountInfo, offset = 0) {
return NftSwapPair.deserialize(accountInfo.data, offset);
}
/**
* Retrieves the account info from the provided address and deserializes
* the {@link NftSwapPair} from its data.
*
* @throws Error if no account info is found at the address or if deserialization fails
*/
static fromAccountAddress(connection, address) {
return __awaiter(this, void 0, void 0, function* () {
const accountInfo = yield connection.getAccountInfo(address);
if (accountInfo == null) {
throw new Error(`Unable to find NftSwapPair account at ${address}`);
}
return NftSwapPair.fromAccountInfo(accountInfo, 0)[0];
});
}
/**
* Deserializes the {@link NftSwapPair} from the provided data Buffer.
* @returns a tuple of the account data and the offset up to which the buffer was read to obtain it.
*/
static deserialize(buf, offset = 0) {
return exports.nftSwapPairBeet.deserialize(buf, offset);
}
/**
* Serializes the {@link NftSwapPair} into a Buffer.
* @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it.
*/
serialize() {
return exports.nftSwapPairBeet.serialize(Object.assign({ accountDiscriminator: nftSwapPairDiscriminator }, this));
}
/**
* Returns the byteSize of a {@link Buffer} holding the serialized data of
* {@link NftSwapPair}
*/
static get byteSize() {
return exports.nftSwapPairBeet.byteSize;
}
/**
* Fetches the minimum balance needed to exempt an account holding
* {@link NftSwapPair} data from rent
*
* @param connection used to retrieve the rent exemption information
*/
static getMinimumBalanceForRentExemption(connection, commitment) {
return __awaiter(this, void 0, void 0, function* () {
return connection.getMinimumBalanceForRentExemption(NftSwapPair.byteSize, commitment);
});
}
/**
* Determines if the provided {@link Buffer} has the correct byte size to
* hold {@link NftSwapPair} data.
*/
static hasCorrectByteSize(buf, offset = 0) {
return buf.byteLength - offset === NftSwapPair.byteSize;
}
/**
* Returns a readable version of {@link NftSwapPair} properties
* and can be used to convert to JSON and/or logging
*/
pretty() {
return {
hadoMarket: this.hadoMarket.toBase58(),
pairType: 'PairType.' + PairType_1.PairType[this.pairType],
pairState: 'PairState.' + PairState_1.PairState[this.pairState],
pairAuthorityType: 'PairAuthorityType.' + PairAuthorityType_1.PairAuthorityType[this.pairAuthorityType],
pairAuthorityAdapterProgram: this.pairAuthorityAdapterProgram.toBase58(),
lpTokensMint: this.lpTokensMint.toBase58(),
lpTokensInCirculation: (() => {
const x = this.lpTokensInCirculation;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
bondingCurve: this.bondingCurve,
baseSpotPrice: (() => {
const x = this.baseSpotPrice;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
fee: (() => {
const x = this.fee;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
mathCounter: (() => {
const x = this.mathCounter;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
currentSpotPrice: (() => {
const x = this.currentSpotPrice;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
feeTokenAccount: this.feeTokenAccount.toBase58(),
feeVaultSeed: this.feeVaultSeed,
solOrTokenFeeAmount: (() => {
const x = this.solOrTokenFeeAmount;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
fundsTokenAccount: this.fundsTokenAccount.toBase58(),
fundsSolVaultSeed: this.fundsSolVaultSeed,
fundsSolOrTokenBalance: (() => {
const x = this.fundsSolOrTokenBalance;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
initialFundsSolOrTokenBalance: (() => {
const x = this.initialFundsSolOrTokenBalance;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
buyOrdersQuantity: (() => {
const x = this.buyOrdersQuantity;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
nftsSeed: this.nftsSeed,
nftsCount: (() => {
const x = this.nftsCount;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
lastTransactedAt: (() => {
const x = this.lastTransactedAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
concentrationIndex: (() => {
const x = this.concentrationIndex;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
assetReceiver: this.assetReceiver.toBase58(),
};
}
}
exports.NftSwapPair = NftSwapPair;
/**
* @category Accounts
* @category generated
*/
exports.nftSwapPairBeet = new beet.BeetStruct([
['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
['hadoMarket', beetSolana.publicKey],
['pairType', PairType_1.pairTypeBeet],
['pairState', PairState_1.pairStateBeet],
['pairAuthorityType', PairAuthorityType_1.pairAuthorityTypeBeet],
['pairAuthorityAdapterProgram', beetSolana.publicKey],
['lpTokensMint', beetSolana.publicKey],
['lpTokensInCirculation', beet.u64],
['bondingCurve', BondingCurve_1.bondingCurveBeet],
['baseSpotPrice', beet.u64],
['fee', beet.u64],
['mathCounter', beet.i64],
['currentSpotPrice', beet.u64],
['feeTokenAccount', beetSolana.publicKey],
['feeVaultSeed', beet.u8],
['solOrTokenFeeAmount', beet.u64],
['fundsTokenAccount', beetSolana.publicKey],
['fundsSolVaultSeed', beet.u8],
['fundsSolOrTokenBalance', beet.u64],
['initialFundsSolOrTokenBalance', beet.u64],
['buyOrdersQuantity', beet.u64],
['nftsSeed', beet.u8],
['nftsCount', beet.u64],
['lastTransactedAt', beet.u64],
['concentrationIndex', beet.u64],
['assetReceiver', beetSolana.publicKey],
], NftSwapPair.fromArgs, 'NftSwapPair');
//# sourceMappingURL=nftSwapPair.js.map