UNPKG

blub-sdk

Version:

A modular SDK for interacting with the BLUB ecosystem on the Sui blockchain.

192 lines (191 loc) 9.82 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _StakingModule_config; Object.defineProperty(exports, "__esModule", { value: true }); exports.StakingModule = void 0; const utils_1 = require("@mysten/sui/utils"); /** * StakingModule class for managing Staking operations. */ class StakingModule { /** * @param {StakingConfig} config Configuration for DeepBookContract */ constructor(config) { _StakingModule_config.set(this, void 0); __classPrivateFieldSet(this, _StakingModule_config, config, "f"); } /** * @description Register a reward * @param {RegisterRewardParams} params Parameters for registering a reward * @param {Transaction} tx Transaction object */ registerRewardMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const adminCap = params.adminCap ?? __classPrivateFieldGet(this, _StakingModule_config, "f").ADMIN_CAP_ID; tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::register_reward`, arguments: [ tx.object(adminCap), tx.object(protocolConfig), tx.object(rewardManager), tx.pure.u64(params.emissionRate), tx.pure.u64(params.startTime), tx.pure.u64(params.endTime), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [params.rewardCoinType], }); } /** * @description Create a stake position * @param {CreateStakePositionParams} params Parameters for creating a stake position * @param {Transaction} tx Transaction object */ createStakePositonMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const position = tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::create_stake_position`, arguments: [tx.object(protocolConfig), tx.object(rewardManager)], typeArguments: [], }); return position; } /** * @description Stake a coin * @param {StakeParams} params Parameters for staking a coin * @param {Transaction} tx Transaction object */ stakeMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const vault = params.vault ?? __classPrivateFieldGet(this, _StakingModule_config, "f").VAULT_ID; tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::stake`, arguments: [ tx.object(protocolConfig), tx.object(vault), tx.object(rewardManager), tx.object(params.position), params.coin, tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [], }); } /** * @description Create a stake position and stake a coin * @param {CreateStakePositionAndStakeParams} params Parameters for creating a stake position and staking a coin * @param {Transaction} tx Transaction object */ createStakePositionAndStakeMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const vault = params.vault ?? __classPrivateFieldGet(this, _StakingModule_config, "f").VAULT_ID; const position = tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::create_stake_position_and_stake`, arguments: [ tx.object(protocolConfig), tx.object(rewardManager), tx.object(vault), params.coin, tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [], }); return position; } /** * @description Unstake a coin * @param {UnStakeParams} params Parameters for unstaking a coin * @param {Transaction} tx Transaction object */ unstakeMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const vault = params.vault ?? __classPrivateFieldGet(this, _StakingModule_config, "f").VAULT_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const coin = tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::unstake`, arguments: [ tx.object(protocolConfig), tx.object(vault), tx.object(rewardManager), tx.object(params.position), tx.pure.u64(params.amount), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [], }); return coin; } /** * @description Claim reward * @param {ClaimRewardParams} params Parameters for claiming a reward * @param {Transaction} tx Transaction object */ claimRewardMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const vault = params.vault ?? __classPrivateFieldGet(this, _StakingModule_config, "f").VAULT_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const coin = tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::claim_reward`, arguments: [ tx.object(protocolConfig), tx.object(vault), tx.object(rewardManager), tx.object(params.position), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [params.coinType], }); return coin; } /** * @description Close a stake position * @param {CloseStakePositionParams} params Parameters for closing a stake position * @param {Transaction} tx Transaction object */ closeStakePositionMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const position = params.position; tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::close_stake_position`, arguments: [ tx.object(protocolConfig), tx.object(rewardManager), tx.object(position), ], typeArguments: [], }); } calculatePendingRewardMoveCall(params, tx) { const protocolConfig = params.protocolConfig ?? __classPrivateFieldGet(this, _StakingModule_config, "f").PROTOCOL_CONFIG_ID; const rewardManager = params.rewardManager ?? __classPrivateFieldGet(this, _StakingModule_config, "f").REWARD_MANAGER_ID; const position = params.position; tx.moveCall({ target: `${__classPrivateFieldGet(this, _StakingModule_config, "f").BLUB_STAKING_PACKAGE_ID}::staking::calculate_pending_reward`, arguments: [ tx.object(protocolConfig), tx.object(rewardManager), tx.object(position), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], typeArguments: [params.coinType], }); } } exports.StakingModule = StakingModule; _StakingModule_config = new WeakMap();