UNPKG

aftermath-ts-sdk

Version:
70 lines (69 loc) 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeveragedStakingApiCasting = void 0; const utils_1 = require("../../../general/utils"); class LeveragedStakingApiCasting { } exports.LeveragedStakingApiCasting = LeveragedStakingApiCasting; // ========================================================================= // Objects // ========================================================================= LeveragedStakingApiCasting.leveragedAfSuiPositionFromSuiObjectResponse = (data) => { const objectType = utils_1.Helpers.getObjectType(data); const fields = utils_1.Helpers.getObjectFields(data); return { objectType, objectId: utils_1.Helpers.getObjectId(data), obligationId: utils_1.Helpers.addLeadingZeroesToType(fields.obligation_key.fields.ownership.fields.of), obligationKeyId: utils_1.Helpers.addLeadingZeroesToType(fields.obligation_key.fields.id.id), baseAfSuiCollateral: BigInt(fields.base_afsui_collateral), afSuiCollateral: BigInt(fields.total_afsui_collateral), suiDebt: BigInt(fields.total_sui_debt), }; }; LeveragedStakingApiCasting.leveragedAfSuiStateFromSuiObjectResponse = (data) => { const objectType = utils_1.Helpers.getObjectType(data); const fields = utils_1.Helpers.getObjectFields(data); return { objectType, objectId: utils_1.Helpers.getObjectId(data), totalAfSuiCollateral: BigInt(fields.total_afsui_collateral), totalSuiDebt: BigInt(fields.total_sui_debt), protocolVersion: BigInt(fields.protocol_version), }; }; // ========================================================================= // Events // ========================================================================= LeveragedStakingApiCasting.leveragedStakedEventFromOnChain = (eventOnChain) => { const fields = eventOnChain.parsedJson; return { userAddress: utils_1.Helpers.addLeadingZeroesToType(fields.user), leverage: utils_1.Casting.Fixed.directCast(BigInt(fields.leverage)), newAfSuiCollateral: BigInt(fields.new_afsui_collateral), timestamp: eventOnChain.timestampMs, txnDigest: eventOnChain.id.txDigest, type: eventOnChain.type, }; }; LeveragedStakingApiCasting.leveragedUnstakedEventFromOnChain = (eventOnChain) => { const fields = eventOnChain.parsedJson; return { userAddress: utils_1.Helpers.addLeadingZeroesToType(fields.user), afsuiCollateral: BigInt(fields.afsui_collateral), timestamp: eventOnChain.timestampMs, txnDigest: eventOnChain.id.txDigest, type: eventOnChain.type, }; }; LeveragedStakingApiCasting.leveragedStakeChangedEventFromOnChain = (eventOnChain) => { const fields = eventOnChain.parsedJson; return { userAddress: utils_1.Helpers.addLeadingZeroesToType(fields.user), newLeverage: utils_1.Casting.Fixed.directCast(BigInt(fields.new_leverage)), initialLeverage: utils_1.Casting.Fixed.directCast(BigInt(fields.initial_leverage)), timestamp: eventOnChain.timestampMs, txnDigest: eventOnChain.id.txDigest, type: eventOnChain.type, }; };