UNPKG

aftermath-ts-sdk

Version:
91 lines (90 loc) 4.53 kB
"use strict"; 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.StakedSuiFren = void 0; const suiFren_1 = require("./suiFren"); const caller_1 = require("../../general/utils/caller"); class StakedSuiFren extends caller_1.Caller { // ========================================================================= // Constructor // ========================================================================= constructor(info, config, isOwned = false, Provider) { super(config, "sui-frens"); this.info = info; this.isOwned = isOwned; this.Provider = Provider; // ========================================================================= // Private Helpers // ========================================================================= this.useProvider = () => { var _a; const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.SuiFrens(); if (!provider) throw new Error("missing AftermathApi Provider"); return provider; }; this.suiFren = new suiFren_1.SuiFren(info.suiFren, this.config, true, isOwned); } // ========================================================================= // Getters // ========================================================================= mixFee() { return this.info.metadata.mixFee; } suiFrenId() { return this.suiFren.suiFren.objectId; } clone() { return new StakedSuiFren(this.info, this.config, this.isOwned, this.Provider); } // ========================================================================= // Objects // ========================================================================= getAccessories() { return __awaiter(this, void 0, void 0, function* () { return this.suiFren.getAccessories(); }); } // ========================================================================= // Transactions // ========================================================================= getUnstakeTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { if (!this.info.position) throw new Error("no position found on suiFren"); return this.useProvider().fetchUnstakeTx(Object.assign(Object.assign({}, inputs), { suiFrenType: this.suiFren.suiFrenType(), stakedPositionId: this.info.position.objectId })); }); } getHarvestFeesTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { if (!this.info.position) throw new Error("no position found on suiFren"); if (!this.isOwned) throw new Error("unable to remove accessory from suiFren that is not owned by caller"); return this.useProvider().fetchBuildHarvestFeesTx(Object.assign(Object.assign({}, inputs), { stakedPositionIds: [this.info.position.objectId] })); }); } getAddAccessoryTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.suiFren.getAddAccessoryTransaction(inputs); }); } getRemoveAccessoryTransaction(inputs) { return __awaiter(this, void 0, void 0, function* () { if (!this.info.position) throw new Error("no position found on suiFren"); if (!this.isOwned) throw new Error("unable to remove accessory from suiFren that is not owned by caller"); return this.useProvider().fetchBuildRemoveAccessoryTx(Object.assign(Object.assign({}, inputs), { suiFrenType: this.suiFren.suiFrenType(), stakedPositionId: this.info.position.objectId })); }); } } exports.StakedSuiFren = StakedSuiFren;