UNPKG

client-aftermath-ts-sdk

Version:
754 lines (753 loc) 43.7 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.FarmsApi = void 0; const utils_1 = require("../../../general/utils"); const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers"); const sui_1 = require("../../sui"); const transactions_1 = require("@mysten/sui/transactions"); const __1 = require("../.."); class FarmsApi { // ========================================================================= // Constructor // ========================================================================= constructor(Provider) { this.Provider = Provider; // ========================================================================= // Public Methods // ========================================================================= // ========================================================================= // Objects // ========================================================================= // ========================================================================= // Staking Pool Objects // ========================================================================= this.fetchOwnedStakingPoolOwnerCaps = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; return this.Provider.Objects().fetchCastObjectsOwnedByAddressOfType({ walletAddress, objectType: this.objectTypes.stakingPoolOwnerCap, objectFromSuiObjectResponse: utils_1.Casting.farms.stakingPoolOwnerCapObjectFromSuiObjectResponse, }); }); this.fetchOwnedStakingPoolOneTimeAdminCaps = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; return this.Provider.Objects().fetchCastObjectsOwnedByAddressOfType({ walletAddress, objectType: this.objectTypes.stakingPoolOneTimeAdminCap, objectFromSuiObjectResponse: utils_1.Casting.farms .stakingPoolOneTimeAdminCapObjectFromSuiObjectResponse, }); }); // ========================================================================= // Staked Position Objects // ========================================================================= this.fetchOwnedPartialStakedPositions = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; return this.Provider.Objects().fetchCastObjectsOwnedByAddressOfType({ walletAddress, objectType: this.objectTypes.stakedPosition, objectFromSuiObjectResponse: utils_1.Casting.farms.partialStakedPositionObjectFromSuiObjectResponse, }); }); // ========================================================================= // Events // ========================================================================= // ========================================================================= // Created Vault // ========================================================================= this.fetchCreatedVaultEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.createdVault, }, eventFromEventOnChain: utils_1.Casting.farms.createdVaultEventFromOnChain })); // ========================================================================= // Staking Position Creation // ========================================================================= this.fetchStakedEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.staked, }, eventFromEventOnChain: utils_1.Casting.farms.stakedEventFromOnChain })); this.fetchStakedRelaxedEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.stakedRelaxed, }, eventFromEventOnChain: utils_1.Casting.farms.stakedRelaxedEventFromOnChain })); // ========================================================================= // Staking Position Locking // ========================================================================= this.fetchLockedEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.locked, }, eventFromEventOnChain: utils_1.Casting.farms.lockedEventFromOnChain })); this.fetchUnlockedEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.unlocked, }, eventFromEventOnChain: utils_1.Casting.farms.unlockedEventFromOnChain })); // ========================================================================= // Staking Position Staking // ========================================================================= this.fetchDepositedPrincipalEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.depositedPrincipal, }, eventFromEventOnChain: utils_1.Casting.farms.depositedPrincipalEventFromOnChain })); this.fetchWithdrewPrincipalEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.withdrewPrincipal, }, eventFromEventOnChain: utils_1.Casting.farms.withdrewPrincipalEventFromOnChain })); // ========================================================================= // Staking Position Reward Harvesting // ========================================================================= this.fetchHarvestedRewardsEvents = (inputs) => this.Provider.Events().fetchCastEventsWithCursor(Object.assign(Object.assign({}, inputs), { query: { MoveEventType: this.eventTypes.harvestedRewards, }, eventFromEventOnChain: utils_1.Casting.farms.harvestedRewardsEventFromOnChain })); // ========================================================================= // Transaction Commands // ========================================================================= // ========================================================================= // Staking Transaction Commands // ========================================================================= this.stakeTx = (inputs) => { const { tx, stakeCoinId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "stake"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), typeof stakeCoinId === "string" ? tx.object(stakeCoinId) : stakeCoinId, tx.pure.u64(inputs.lockDurationMs), ], }); }; this.depositPrincipalTx = (inputs) => { const { tx, stakeCoinId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "deposit_principal"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), typeof stakeCoinId === "string" ? tx.object(stakeCoinId) : stakeCoinId, // Coin ], }); }; this.withdrawPrincipalTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "withdraw_principal"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), tx.pure.u64(inputs.withdrawAmount), ], }); }; this.destroyStakedPositionTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "destroy"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock ], }); }; this.updatePositionTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "update_position"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock ], }); }; // ========================================================================= // Locking Transaction Commands // ========================================================================= this.lockTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "lock"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), tx.pure.u64(inputs.lockDurationMs), ], }); }; this.renewLockTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "renew_lock"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock ], }); }; this.unlockTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "unlock"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock ], }); }; // ========================================================================= // Reward Harvesting Transaction Commands // ========================================================================= this.beginHarvestTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "begin_harvest"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakingPoolId), // AfterburnerVault ], }); }; this.harvestRewardsTx = (inputs) => { const { tx, harvestedRewardsEventMetadataId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "harvest_rewards"), typeArguments: [inputs.stakeCoinType, inputs.rewardCoinType], arguments: [ tx.object(inputs.stakedPositionId), tx.object(inputs.stakingPoolId), typeof harvestedRewardsEventMetadataId === "string" ? tx.object(harvestedRewardsEventMetadataId) : harvestedRewardsEventMetadataId, tx.object(sui_1.Sui.constants.addresses.suiClockId), // Clock ], }); }; this.endHarvestTx = (inputs) => { const { tx, harvestedRewardsEventMetadataId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.stakedPosition, "end_harvest"), typeArguments: [], arguments: [ typeof harvestedRewardsEventMetadataId === "string" ? tx.object(harvestedRewardsEventMetadataId) : harvestedRewardsEventMetadataId, // HarvestedRewardsEventMetadata ], }); }; // ========================================================================= // Staking Pool Creation Transaction Commands // ========================================================================= this.newStakingPoolTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "new"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.pure.u64(inputs.lockEnforcement === "Strict" ? 0 : 1), tx.pure.u64(inputs.minLockDurationMs), tx.pure.u64(inputs.maxLockDurationMs), tx.pure.u64(inputs.maxLockMultiplier), tx.pure.u64(inputs.minStakeAmount), ], }); }; this.shareStakingPoolTx = (inputs) => { const { tx, stakingPoolId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "share_vault"), typeArguments: [inputs.stakeCoinType], arguments: [ typeof stakingPoolId === "string" ? tx.object(stakingPoolId) : stakingPoolId, // AfterburnerVault ], }); }; this.transferOwnerCapTx = (inputs) => { const { tx, ownerCapId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "transfer_owner_cap"), typeArguments: [], arguments: [ typeof ownerCapId === "string" ? tx.object(ownerCapId) : ownerCapId, tx.pure.address(inputs.recipientAddress), ], }); }; this.grantOneTimeAdminCapTx = (inputs) => { const { tx, ownerCapId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "grant_one_time_admin_cap"), typeArguments: [inputs.rewardCoinType], arguments: [ typeof ownerCapId === "string" ? tx.object(ownerCapId) : ownerCapId, tx.pure.address(inputs.recipientAddress), ], }); }; // ========================================================================= // Staking Pool Mutation Transaction Commands // ========================================================================= this.initializeStakingPoolRewardTx = (inputs) => { const { tx, rewardCoinId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "initialize_reward" + (FarmsApi.isFarmOneTimeAdminCapId(inputs) ? "_and_consume_admin_cap" : "")), typeArguments: [inputs.stakeCoinType, inputs.rewardCoinType], arguments: [ tx.object(FarmsApi.farmCapId(inputs)), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), typeof rewardCoinId === "string" ? tx.object(rewardCoinId) : rewardCoinId, tx.pure.u64(inputs.emissionScheduleMs), tx.pure.u64(inputs.emissionRate), tx.pure.u64(inputs.emissionDelayTimestampMs), ], }); }; this.topUpStakingPoolRewardTx = (inputs) => { const { tx, rewardCoinId } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "add_reward" + (FarmsApi.isFarmOneTimeAdminCapId(inputs) ? "_and_consume_admin_cap" : "")), typeArguments: [inputs.stakeCoinType, inputs.rewardCoinType], arguments: [ tx.object(FarmsApi.farmCapId(inputs)), tx.object(inputs.stakingPoolId), typeof rewardCoinId === "string" ? tx.object(rewardCoinId) : rewardCoinId, // Coin ], }); }; this.increaseStakingPoolRewardEmissionsTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "update_emissions_for"), typeArguments: [inputs.stakeCoinType, inputs.rewardCoinType], arguments: [ tx.object(inputs.ownerCapId), tx.object(inputs.stakingPoolId), tx.object(sui_1.Sui.constants.addresses.suiClockId), tx.pure.u64(inputs.emissionScheduleMs), tx.pure.u64(inputs.emissionRate), ], }); }; this.setStakingPoolMinStakeAmountTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "set_min_stake_amount"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.ownerCapId), tx.object(inputs.stakingPoolId), tx.pure.u64(inputs.minStakeAmount), ], }); }; // ========================================================================= // Staking Pool Inspection Transaction Commands // ========================================================================= this.isVaultUnlockedTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "is_vault_unlocked"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakingPoolId), // AfterburnerVault ], }); }; this.remainingRewardsTx = (inputs) => { const { tx } = inputs; return tx.moveCall({ target: utils_1.Helpers.transactions.createTxTarget(this.addresses.packages.vaults, FarmsApi.constants.moduleNames.vault, "remaining_rewards"), typeArguments: [inputs.stakeCoinType], arguments: [ tx.object(inputs.stakingPoolId), // AfterburnerVault ], }); }; // ========================================================================= // Transactions // ========================================================================= // ========================================================================= // Staking Transactions // ========================================================================= this.fetchBuildStakeTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, isSponsoredTx } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const stakeCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({ tx, walletAddress, coinType: inputs.stakeCoinType, coinAmount: inputs.stakeAmount, isSponsoredTx, }); const stakedPosition = this.stakeTx(Object.assign(Object.assign({}, inputs), { tx, stakeCoinId })); tx.transferObjects([stakedPosition], walletAddress); return tx; }); this.fetchBuildDepositPrincipalTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, isSponsoredTx } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const stakeCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({ tx, walletAddress, coinType: inputs.stakeCoinType, coinAmount: inputs.depositAmount, isSponsoredTx, }); this.depositPrincipalTx(Object.assign(Object.assign({}, inputs), { tx, stakeCoinId })); return tx; }); this.fetchBuildWithdrawPrincipalTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const withdrawnCoin = this.withdrawPrincipalTx(Object.assign(Object.assign({}, inputs), { tx })); tx.transferObjects([withdrawnCoin], walletAddress); return tx; }); this.fetchBuildUnstakeTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; let tx; if (inputs.rewardCoinTypes.length > 0) { // harvest rewards tx = yield this.fetchBuildHarvestRewardsTx(Object.assign(Object.assign({}, inputs), { stakedPositionIds: [inputs.stakedPositionId] })); } else { // no rewards to harvest tx = new transactions_1.Transaction(); tx.setSender(walletAddress); } // withdraw principal const withdrawnCoin = this.withdrawPrincipalTx(Object.assign(Object.assign({}, inputs), { tx })); tx.transferObjects([withdrawnCoin], walletAddress); // destroy position this.destroyStakedPositionTx(Object.assign(Object.assign({}, inputs), { tx })); return tx; }); this.buildUpdatePositionTx = utils_1.Helpers.transactions.createBuildTxFunc(this.updatePositionTx); // ========================================================================= // Locking Transactions // ========================================================================= this.buildLockTx = utils_1.Helpers.transactions.createBuildTxFunc(this.lockTx); this.buildRenewLockTx = utils_1.Helpers.transactions.createBuildTxFunc(this.renewLockTx); this.buildUnlockTx = utils_1.Helpers.transactions.createBuildTxFunc(this.unlockTx); // ========================================================================= // Reward Harvesting Transactions // ========================================================================= this.fetchBuildHarvestRewardsTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, stakedPositionIds } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const harvestedRewardsEventMetadataId = this.beginHarvestTx(Object.assign(Object.assign({}, inputs), { tx })); let harvestedCoins = {}; for (const stakedPositionId of stakedPositionIds) { for (const rewardCoinType of inputs.rewardCoinTypes) { const harvestedCoin = this.harvestRewardsTx(Object.assign(Object.assign({}, inputs), { tx, stakedPositionId, harvestedRewardsEventMetadataId, rewardCoinType })); if (rewardCoinType in harvestedCoins) { harvestedCoins[rewardCoinType].push(harvestedCoin); } else { harvestedCoins[rewardCoinType] = [harvestedCoin]; } } } this.endHarvestTx({ tx, harvestedRewardsEventMetadataId }); for (const [coinType, harvestedCoinIds] of Object.entries(harvestedCoins)) { const coinToTransfer = harvestedCoinIds[0]; if (harvestedCoinIds.length > 1) tx.mergeCoins(coinToTransfer, harvestedCoinIds.slice(1)); if (inputs.claimSuiAsAfSui && __1.Coin.isCoinObjectType(coinType)) { this.Provider.Staking().stakeTx({ tx, suiCoin: coinToTransfer, withTransfer: true, validatorAddress: this.Provider.Staking().addresses.objects .aftermathValidator, }); } else { tx.transferObjects([coinToTransfer], walletAddress); } } return tx; }); // ========================================================================= // Staking Pool Transactions // ========================================================================= // ========================================================================= // Staking Pool Creation Transactions // ========================================================================= this.fetchBuildCreateStakingPoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const [stakingPoolId, ownerCapId] = this.newStakingPoolTx(Object.assign(Object.assign({}, inputs), { tx })); this.shareStakingPoolTx({ tx, stakingPoolId, stakeCoinType: inputs.stakeCoinType, }); this.transferOwnerCapTx({ tx, ownerCapId, recipientAddress: walletAddress, }); return tx; }); // ========================================================================= // Staking Pool Mutation Transactions // ========================================================================= this.fetchBuildInitializeStakingPoolRewardTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, isSponsoredTx } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); const rewardCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({ tx, walletAddress, coinType: inputs.rewardCoinType, coinAmount: inputs.rewardAmount, isSponsoredTx, }); this.initializeStakingPoolRewardTx(Object.assign(Object.assign({}, inputs), { tx, rewardCoinId })); return tx; }); this.fetchBuildTopUpStakingPoolRewardsTx = (inputs) => __awaiter(this, void 0, void 0, function* () { const { walletAddress, isSponsoredTx } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); for (const reward of inputs.rewards) { const rewardCoinId = yield this.Provider.Coin().fetchCoinWithAmountTx({ tx, walletAddress, coinType: reward.rewardCoinType, coinAmount: reward.rewardAmount, isSponsoredTx, }); this.topUpStakingPoolRewardTx(Object.assign(Object.assign(Object.assign({}, inputs), reward), { tx, rewardCoinId })); } return tx; }); this.fetchIncreaseStakingPoolRewardsEmissionsTx = (inputs) => { const { walletAddress } = inputs; const tx = new transactions_1.Transaction(); tx.setSender(walletAddress); for (const reward of inputs.rewards) { this.increaseStakingPoolRewardEmissionsTx(Object.assign(Object.assign(Object.assign({}, inputs), reward), { tx })); } return tx; }; this.buildSetStakingPoolMinStakeAmountTx = utils_1.Helpers.transactions.createBuildTxFunc(this.setStakingPoolMinStakeAmountTx); this.buildGrantOneTimeAdminCapTx = utils_1.Helpers.transactions.createBuildTxFunc(this.grantOneTimeAdminCapTx); // ========================================================================= // Private Methods // ========================================================================= // ========================================================================= // Event Types // ========================================================================= // ========================================================================= // Vault Creation // ========================================================================= this.createdVaultEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.createdVault); // ========================================================================= // Vault Mutation // ========================================================================= this.initializedRewardEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.initializedReward); this.addedRewardEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.addedReward); this.increasedEmissionsEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.increasedEmissions); // ========================================================================= // Staking Position Creation // ========================================================================= this.stakedEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.staked); this.stakedRelaxedEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.stakedRelaxed); // ========================================================================= // Staking Position Locking // ========================================================================= this.lockedEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.locked); this.unlockedEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.unlocked); // ========================================================================= // Staking Position Staking // ========================================================================= this.depositedPrincipalEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.depositedPrincipal); this.withdrewPrincipalEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.withdrewPrincipal); // ========================================================================= // Staking Position Reward Harvesting // ========================================================================= this.harvestedRewardsEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.packages.vaultsInitial, FarmsApi.constants.moduleNames.events, FarmsApi.constants.eventNames.harvestedRewards); const addresses = this.Provider.addresses.farms; if (!addresses) throw new Error("not all required addresses have been set in provider"); this.addresses = addresses; this.objectTypes = { stakedPosition: `${addresses.packages.vaultsInitial}::${FarmsApi.constants.moduleNames.stakedPosition}::StakedPosition`, stakingPoolOwnerCap: `${addresses.packages.vaultsInitial}::${FarmsApi.constants.moduleNames.vault}::OwnerCap`, stakingPoolOneTimeAdminCap: `${addresses.packages.vaultsInitial}::${FarmsApi.constants.moduleNames.vault}::OneTimeAdminCap`, }; this.eventTypes = { // staking pools // creation createdVault: this.createdVaultEventType(), // mutation initializedReward: this.initializedRewardEventType(), addedReward: this.addedRewardEventType(), increasedEmissions: this.increasedEmissionsEventType(), // staking positions // creation staked: this.stakedEventType(), stakedRelaxed: this.stakedRelaxedEventType(), // locking locked: this.lockedEventType(), unlocked: this.unlockedEventType(), // staking depositedPrincipal: this.depositedPrincipalEventType(), withdrewPrincipal: this.withdrewPrincipalEventType(), // reward harvesting harvestedRewards: this.harvestedRewardsEventType(), }; this.moveErrors = { [this.addresses.packages.vaults]: { [FarmsApi.constants.moduleNames.vault]: { /// A user attempts provides a `Coin` or `u64` with value zero. 0: "Zero", /// A user provides a `StakedPosition` and a `AfterburnerVault` that don't correspond with one /// another. This can only occur if two `AfterburnerVault` with the same underlying `STAKED` generic /// are created. 1: "Invalid Afterburner Vault", /// A user tries to create an `AfterburnerVault` where `min_lock_duration_ms` is strictly greater than /// `max_lock_duration_ms`. 2: "Invalid Min Max Lock Durations", /// The creator of a `AfterburnerVault` tries to update the vault's emission rate or add more rewards /// without first initializing the emissions schedule. 3: "Emissions Not Initialized", /// The creator of a `AfterburnerVault` tries to update the vault's emission schedule/rate but /// provides a schedule/rate pair that will decrease emissions for the specified reward type. 4: "Emissions Not Increasing", 5: "Bad Type", /// A user attempts to stake into a `AfterburnerVault` below the vault's `min_stake_amount` or /// an amount of principal that would bring their position below the vault's `min_stake_amount`. 6: "Invalid Stake Amount", /// A user attempts to create an `AfterburnerVault` and provides a `lock_enforcement` that doesn't /// match one of `STRICT_LOCK_ENFORCEMENT` or `RELAXED_LOCK_ENFORCEMENT`. 7: "Invalid Lock Enforcement", /// A user tries to claim zero rewards 8: "Zero Claim", /// A user provided invalid max lock multiplier (< 1) 9: "Invalid Lock Multiplier", 10: "Invalid Argument", 11: "Deprecated", 12: "Afterburner Vault Still Active", }, [FarmsApi.constants.moduleNames.stakedPosition]: { /// A user attempts provides a `Coin` or `u64` with value zero. 0: "Zero", /// A user attempts to withdraw funds from a `StakedPosition` that is still locked. 1: "Locked", /// A user provides a `StakedPosition` and a `AfterburnerVault` that don't correspond with one another. /// This can only occur if two `AfterburnerVault` with the same underlying `STAKED` generic are created. 2: "Invalid Afterburner Vault", /// A user tries to lock the coins in a `AfterburnerVault` with a `lock_duration_ms` below the vault's /// `min_lock_duration_ms`. 3: "Invalid Lock Duration", /// A user attempts to destroy a `StakedPosition` that still holds rewards that can be harvested. 4: "Harvest Rewards", /// A user attempts to stake into a `AfterburnerVault` below the vault's `min_stake_amount` or /// an amount of principal that would bring their position below the vault's `min_stake_amount`. 5: "Invalid Stake Amount", 6: "Invalid Withdraw Amount", 7: "Invalid Split Amount", 8: "Uninitialized Vault Rewards", 9: "Not Implemented", /// A user requested to harvest zero base rewards. 10: "Zero Rewards", }, }, }; } } exports.FarmsApi = FarmsApi; // ========================================================================= // Constants // ========================================================================= FarmsApi.constants = { moduleNames: { vault: "afterburner_vault", stakedPosition: "staked_position", vaultRegistry: "vault_registry", events: "vents", }, eventNames: { // staking pools // creation createdVault: "CreatedVaultEvent", // mutation initializedReward: "InitializedRewardEvent", addedReward: "AddedRewardEvent", increasedEmissions: "IncreasedEmissionsEvent", // staking positions // creation staked: "StakedEvent", stakedRelaxed: "StakedEventRelaxed", // locking locked: "LockedEvent", unlocked: "UnlockedEvent", // mutation joined: "JoinedEvent", split: "SplitEvent", // staking depositedPrincipal: "DepositedPrincipalEvent", withdrewPrincipal: "WithdrewPrincipalEvent", // reward harvesting harvestedRewards: "HarvestedRewardsEvent", // destruction destroyedStakedPosition: "DestroyedStakedPositionEvent", }, }; // ========================================================================= // Private Static Methods // ========================================================================= // ========================================================================= // Helpers // ========================================================================= FarmsApi.isFarmOwnerCapId = (inputs) => "ownerCapId" in inputs; FarmsApi.isFarmOneTimeAdminCapId = (inputs) => "oneTimeAdminCapId" in inputs; FarmsApi.farmCapId = (inputs) => "ownerCapId" in inputs ? inputs.ownerCapId : inputs.oneTimeAdminCapId;