aftermath-ts-sdk
Version:
Aftermath TypeScript SDK
46 lines (45 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isUnstakePosition = exports.isStakePosition = exports.isUnstakeEvent = exports.isStakeEvent = exports.isSuiDelegatedStake = void 0;
/**
* A type guard utility function to check if a position is a native Sui delegated stake
* (`SuiDelegatedStake`) rather than an Aftermath-specific `StakingPosition`.
*
* @param stake - An object that could be either a `StakingPosition` or a `SuiDelegatedStake`.
* @returns True if the object matches the shape of `SuiDelegatedStake`; otherwise, false.
*/
const isSuiDelegatedStake = (stake) => {
return ("stakeRequestEpoch" in stake &&
"stakeActiveEpoch" in stake &&
"principal" in stake &&
"stakingPool" in stake);
};
exports.isSuiDelegatedStake = isSuiDelegatedStake;
/**
* Type guard to check if an event is a `StakedEvent`.
*/
const isStakeEvent = (event) => {
return "staker" in event;
};
exports.isStakeEvent = isStakeEvent;
/**
* Type guard to check if an event is an `UnstakeEvent`.
*/
const isUnstakeEvent = (event) => {
return !(0, exports.isStakeEvent)(event);
};
exports.isUnstakeEvent = isUnstakeEvent;
/**
* Type guard that checks whether a given `StakingPosition` is a stake position.
*/
const isStakePosition = (position) => {
return "stakedSuiId" in position;
};
exports.isStakePosition = isStakePosition;
/**
* Type guard that checks whether a given `StakingPosition` is an unstake position.
*/
const isUnstakePosition = (position) => {
return !(0, exports.isStakePosition)(position);
};
exports.isUnstakePosition = isUnstakePosition;