UNPKG

@cheqd/sdk

Version:

A TypeScript SDK built with CosmJS to interact with the cheqd network ledger

798 lines 44.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OracleModule = exports.setupOracleExtension = exports.MovingAverages = exports.WMAStrategies = exports.typeUrlMsgGovCancelUpdateParamPlanResponse = exports.typeUrlMsgGovCancelUpdateParamPlan = exports.typeUrlMsgGovRemoveCurrencyDeviationThresholdsResponse = exports.typeUrlMsgGovRemoveCurrencyDeviationThresholds = exports.typeUrlMsgGovRemoveCurrencyPairProvidersResponse = exports.typeUrlMsgGovRemoveCurrencyPairProviders = exports.typeUrlMsgGovAddDenomsResponse = exports.typeUrlMsgGovAddDenoms = exports.typeUrlMsgGovUpdateParamsResponse = exports.typeUrlMsgGovUpdateParams = exports.typeUrlMsgLegacyGovUpdateParamsResponse = exports.typeUrlMsgLegacyGovUpdateParams = exports.typeUrlMsgDelegateFeedConsentResponse = exports.typeUrlMsgDelegateFeedConsent = exports.typeUrlMsgAggregateExchangeRateVoteResponse = exports.typeUrlMsgAggregateExchangeRateVote = exports.typeUrlMsgAggregateExchangeRatePrevoteResponse = exports.typeUrlMsgAggregateExchangeRatePrevote = exports.protobufLiterals = exports.defaultOracleExtensionKey = void 0; exports.isMsgAggregateExchangeRatePrevoteEncodeObject = isMsgAggregateExchangeRatePrevoteEncodeObject; exports.isMsgAggregateExchangeRateVoteEncodeObject = isMsgAggregateExchangeRateVoteEncodeObject; exports.isMsgDelegateFeedConsentEncodeObject = isMsgDelegateFeedConsentEncodeObject; exports.isMsgLegacyGovUpdateParamsEncodeObject = isMsgLegacyGovUpdateParamsEncodeObject; exports.isMsgGovUpdateParamsEncodeObject = isMsgGovUpdateParamsEncodeObject; exports.isMsgGovAddDenomsEncodeObject = isMsgGovAddDenomsEncodeObject; exports.isMsgGovRemoveCurrencyPairProvidersEncodeObject = isMsgGovRemoveCurrencyPairProvidersEncodeObject; exports.isMsgGovRemoveCurrencyDeviationThresholdsEncodeObject = isMsgGovRemoveCurrencyDeviationThresholdsEncodeObject; exports.isMsgGovCancelUpdateParamPlanEncodeObject = isMsgGovCancelUpdateParamPlanEncodeObject; const v2_1 = require("@cheqd/ts-proto-cjs/cheqd/oracle/v2"); const math_cjs_1 = require("@cosmjs/math-cjs"); const _1 = require("./_"); const stargate_cjs_1 = require("@cosmjs/stargate-cjs"); const utils_cjs_1 = require("@cosmjs/utils-cjs"); const tx_1 = require("cosmjs-types/cosmos/gov/v1/tx"); /** Default extension key for Oracle-related query operations */ exports.defaultOracleExtensionKey = 'oracle'; /** * Protobuf message type for Oracle operations. * Used for consistent message type identification across the module. */ exports.protobufLiterals = { /** Request to fetch exchange rates for specific denoms. */ QueryExchangeRates: 'QueryExchangeRates', /** Response containing the exchange rates payload. */ QueryExchangeRatesResponse: 'QueryExchangeRatesResponse', /** Request to list all active exchange rate denoms. */ QueryActiveExchangeRates: 'QueryActiveExchangeRates', /** Response providing the currently active exchange rate denoms. */ QueryActiveExchangeRatesResponse: 'QueryActiveExchangeRatesResponse', /** Request to retrieve the feeder delegation for a validator. */ QueryFeederDelegation: 'QueryFeederDelegation', /** Response with feeder delegation details. */ QueryFeederDelegationResponse: 'QueryFeederDelegationResponse', /** Request to obtain a validator's miss counter. */ QueryMissCounter: 'QueryMissCounter', /** Response returning the miss counter value. */ QueryMissCounterResponse: 'QueryMissCounterResponse', /** Request to inspect the current slash window information. */ QuerySlashWindow: 'QuerySlashWindow', /** Response detailing the slash window configuration. */ QuerySlashWindowResponse: 'QuerySlashWindowResponse', /** Request for a validator's aggregate prevote. */ QueryAggregatePrevote: 'QueryAggregatePrevote', /** Response containing the aggregate prevote. */ QueryAggregatePrevoteResponse: 'QueryAggregatePrevoteResponse', /** Request for all aggregate prevotes on the network. */ QueryAggregatePrevotes: 'QueryAggregatePrevotes', /** Response listing all aggregate prevotes. */ QueryAggregatePrevotesResponse: 'QueryAggregatePrevotesResponse', /** Request for aggregate votes from a validator. */ QueryAggregateVotes: 'QueryAggregateVotes', /** Response carrying aggregate votes. */ QueryAggregateVotesResponse: 'QueryAggregateVotesResponse', /** Request to fetch the oracle module parameters. */ QueryParams: 'QueryParams', /** Response returning the oracle module parameters. */ QueryParamsResponse: 'QueryParamsResponse', /** Request for price medians across denoms. */ QueryMedians: 'QueryMedians', /** Response containing price medians. */ QueryMediansResponse: 'QueryMediansResponse', /** Request for median deviations to assess volatility. */ QueryMedianDeviations: 'QueryMedianDeviations', /** Response returning median deviation values. */ QueryMedianDeviationsResponse: 'QueryMedianDeviationsResponse', /** Request to fetch the validator reward set. */ QueryValidatorRewardSet: 'QueryValidatorRewardSet', /** Response with validator reward set data. */ QueryValidatorRewardSetResponse: 'QueryValidatorRewardSetResponse', /** Request for an exponential moving average price. */ QueryEMARequest: 'QueryEMARequest', /** Response containing exponential moving average data. */ QueryEMAResponse: 'QueryEMAResponse', /** Request for a weighted moving average price. */ QueryWMARequest: 'QueryWMARequest', /** Response containing weighted moving average data. */ QueryWMAResponse: 'QueryWMAResponse', /** Request for a simple moving average price. */ QuerySMARequest: 'QuerySMARequest', /** Response containing simple moving average data. */ QuerySMAResponse: 'QuerySMAResponse', /** Request to convert a USDC amount into CHEQ. */ ConvertUSDCtoCHEQRequest: 'ConvertUSDCtoCHEQRequest', /** Response returning the converted CHEQ amount. */ ConvertUSDCtoCHEQResponse: 'ConvertUSDCtoCHEQResponse', /** Message to submit an aggregate exchange rate prevote. */ MsgAggregateExchangeRatePrevote: 'MsgAggregateExchangeRatePrevote', /** Message that defines the MsgAggregateExchangeRatePrevote response type. */ MsgAggregateExchangeRatePrevoteResponse: 'MsgAggregateExchangeRatePrevoteResponse', /** Message to submit an aggregate exchange rate vote. */ MsgAggregateExchangeRateVote: 'MsgAggregateExchangeRateVote', /** Message that defines the MsgAggregateExchangeRateVote response type. */ MsgAggregateExchangeRateVoteResponse: 'MsgAggregateExchangeRateVoteResponse', /** Message to delegate oracle voting rights to another address. */ MsgDelegateFeedConsent: 'MsgDelegateFeedConsent', /** Message that defines the MsgDelegateFeedConsent response type. */ MsgDelegateFeedConsentResponse: 'MsgDelegateFeedConsentResponse', /** Message that defines the MsgLegacyGovUpdateParams request type. */ MsgLegacyGovUpdateParams: 'MsgLegacyGovUpdateParams', /** Message that defines the MsgLegacyGovUpdateParams response type. */ MsgLegacyGovUpdateParamsResponse: 'MsgLegacyGovUpdateParamsResponse', /** Message that defines the MsgGovUpdateParams request type. */ MsgGovUpdateParams: 'MsgGovUpdateParams', /** Message that defines the MsgGovUpdateParams response type. */ MsgGovUpdateParamsResponse: 'MsgGovUpdateParamsResponse', /** Message that defines the MsgGovAddDenoms request type. */ MsgGovAddDenoms: 'MsgGovAddDenoms', /** Message that defines the MsgGovAddDenoms response type. */ MsgGovAddDenomsResponse: 'MsgGovAddDenomsResponse', /** Message that defines the MsgGovRemoveCurrencyPairProviders request type. */ MsgGovRemoveCurrencyPairProviders: 'MsgGovRemoveCurrencyPairProviders', /** Message that defines the MsgGovRemoveCurrencyPairProviders response type. */ MsgGovRemoveCurrencyPairProvidersResponse: 'MsgGovRemoveCurrencyPairProvidersResponse', /** Message that defines the MsgGovRemoveCurrencyDeviationThresholds request type. */ MsgGovRemoveCurrencyDeviationThresholds: 'MsgGovRemoveCurrencyDeviationThresholds', /** Message that defines the MsgGovRemoveCurrencyDeviationThresholds response type. */ MsgGovRemoveCurrencyDeviationThresholdsResponse: 'MsgGovRemoveCurrencyDeviationThresholdsResponse', /** Message that defines the MsgGovCancelUpdateParamPlan request type. */ MsgGovCancelUpdateParamPlan: 'MsgGovCancelUpdateParamPlan', /** Message that defines the MsgGovCancelUpdateParamPlan response type. */ MsgGovCancelUpdateParamPlanResponse: 'MsgGovCancelUpdateParamPlanResponse', }; /** Type URL for MsgAggregateExchangeRatePrevote messages */ exports.typeUrlMsgAggregateExchangeRatePrevote = `/${v2_1.protobufPackage}.MsgAggregateExchangeRatePrevote`; /** Type URL for MsgAggregateExchangeRatePrevoteResponse messages */ exports.typeUrlMsgAggregateExchangeRatePrevoteResponse = `/${v2_1.protobufPackage}.MsgAggregateExchangeRatePrevoteResponse`; /** Type URL for MsgAggregateExchangeRateVote messages */ exports.typeUrlMsgAggregateExchangeRateVote = `/${v2_1.protobufPackage}.MsgAggregateExchangeRateVote`; /** Type URL for MsgAggregateExchangeRateVoteResponse messages */ exports.typeUrlMsgAggregateExchangeRateVoteResponse = `/${v2_1.protobufPackage}.MsgAggregateExchangeRateVoteResponse`; /** Type URL for MsgDelegateFeedConsent messages */ exports.typeUrlMsgDelegateFeedConsent = `/${v2_1.protobufPackage}.MsgDelegateFeedConsent`; /** Type URL for MsgDelegateFeedConsentResponse messages */ exports.typeUrlMsgDelegateFeedConsentResponse = `/${v2_1.protobufPackage}.MsgDelegateFeedConsentResponse`; /** Type URL for MsgLegacyGovUpdateParams messages */ exports.typeUrlMsgLegacyGovUpdateParams = `/${v2_1.protobufPackage}.MsgLegacyGovUpdateParams`; /** Type URL for MsgLegacyGovUpdateParamsResponse messages */ exports.typeUrlMsgLegacyGovUpdateParamsResponse = `/${v2_1.protobufPackage}.MsgLegacyGovUpdateParamsResponse`; /** Type URL for MsgGovUpdateParams messages */ exports.typeUrlMsgGovUpdateParams = `/${v2_1.protobufPackage}.MsgGovUpdateParams`; /** Type URL for MsgGovUpdateParamsResponse messages */ exports.typeUrlMsgGovUpdateParamsResponse = `/${v2_1.protobufPackage}.MsgGovUpdateParamsResponse`; /** Type URL for MsgGovAddDenoms messages */ exports.typeUrlMsgGovAddDenoms = `/${v2_1.protobufPackage}.MsgGovAddDenoms`; /** Type URL for MsgGovAddDenomsResponse messages */ exports.typeUrlMsgGovAddDenomsResponse = `/${v2_1.protobufPackage}.MsgGovAddDenomsResponse`; /** Type URL for MsgGovRemoveCurrencyPairProviders messages */ exports.typeUrlMsgGovRemoveCurrencyPairProviders = `/${v2_1.protobufPackage}.MsgGovRemoveCurrencyPairProviders`; /** Type URL for MsgGovRemoveCurrencyPairProvidersResponse messages */ exports.typeUrlMsgGovRemoveCurrencyPairProvidersResponse = `/${v2_1.protobufPackage}.MsgGovRemoveCurrencyPairProvidersResponse`; /** Type URL for MsgGovRemoveCurrencyDeviationThresholds messages */ exports.typeUrlMsgGovRemoveCurrencyDeviationThresholds = `/${v2_1.protobufPackage}.MsgGovRemoveCurrencyDeviationThresholds`; /** Type URL for MsgGovRemoveCurrencyDeviationThresholdsResponse messages */ exports.typeUrlMsgGovRemoveCurrencyDeviationThresholdsResponse = `/${v2_1.protobufPackage}.MsgGovRemoveCurrencyDeviationThresholdsResponse`; /** Type URL for MsgGovCancelUpdateParamPlan messages */ exports.typeUrlMsgGovCancelUpdateParamPlan = `/${v2_1.protobufPackage}.MsgGovCancelUpdateParamPlan`; /** Type URL for MsgGovCancelUpdateParamPlanResponse messages */ exports.typeUrlMsgGovCancelUpdateParamPlanResponse = `/${v2_1.protobufPackage}.MsgGovCancelUpdateParamPlanResponse`; /** * Type guard function to check if an object is a MsgAggregateExchangeRatePrevoteEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgAggregateExchangeRatePrevoteEncodeObject, false otherwise */ function isMsgAggregateExchangeRatePrevoteEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgAggregateExchangeRatePrevote; } /** * Type guard function to check if an object is a MsgAggregateExchangeRateVoteEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgAggregateExchangeRateVoteEncodeObject, false otherwise */ function isMsgAggregateExchangeRateVoteEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgAggregateExchangeRateVote; } /** * Type guard function to check if an object is a MsgDelegateFeedConsentEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgDelegateFeedConsentEncodeObject, false otherwise */ function isMsgDelegateFeedConsentEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgDelegateFeedConsent; } /** * Type guard function to check if an object is a MsgLegacyGovUpdateParamsEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgLegacyGovUpdateParamsEncodeObject, false otherwise */ function isMsgLegacyGovUpdateParamsEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgLegacyGovUpdateParams; } /** * Type guard function to check if an object is a MsgGovUpdateParamsEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgGovUpdateParamsEncodeObject, false otherwise */ function isMsgGovUpdateParamsEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgGovUpdateParams; } /** * Type guard function to check if an object is a MsgGovAddDenomsEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgGovAddDenomsEncodeObject, false otherwise */ function isMsgGovAddDenomsEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgGovAddDenoms; } /** * Type guard function to check if an object is a MsgGovRemoveCurrencyPairProvidersEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgGovRemoveCurrencyPairProvidersEncodeObject, false otherwise */ function isMsgGovRemoveCurrencyPairProvidersEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgGovRemoveCurrencyPairProviders; } /** * Type guard function to check if an object is a MsgGovRemoveCurrencyDeviationThresholdsEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgGovRemoveCurrencyDeviationThresholdsEncodeObject, false otherwise */ function isMsgGovRemoveCurrencyDeviationThresholdsEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgGovRemoveCurrencyDeviationThresholds; } /** * Type guard function to check if an object is a MsgGovCancelUpdateParamPlanEncodeObject * @param obj - EncodeObject to check * @returns True if the object is a MsgGovCancelUpdateParamPlanEncodeObject, false otherwise */ function isMsgGovCancelUpdateParamPlanEncodeObject(obj) { return obj.typeUrl === exports.typeUrlMsgGovCancelUpdateParamPlan; } /** Enumeration of WMA strategies */ exports.WMAStrategies = { /** Balanced (linear) strategy */ BALANCED: 'BALANCED', /** Recent (weighted) strategy */ RECENT: 'RECENT', /** Oldest (weighted) strategy */ OLDEST: 'OLDEST', /** Custom weights strategy */ CUSTOM: 'CUSTOM', }; /** Enumeration of moving averages */ exports.MovingAverages = { /** Exponential Moving Average */ EMA: 'ema', /** Weighted Moving Average */ WMA: 'wma', /** Simple Moving Average */ SMA: 'sma', }; /** Sets up the Oracle extension for the querier client. * Creates and configures the Oracle-specific query methods. * @param base - Base QueryClient to extend * @returns Configured Oracle extension with query methods */ const setupOracleExtension = (base) => { const rpc = (0, stargate_cjs_1.createProtobufRpcClient)(base); const queryService = new v2_1.QueryClientImpl(rpc); return { [exports.defaultOracleExtensionKey]: { queryExchangeRates: async (denom = '') => { const response = await queryService.ExchangeRates({ denom }); (0, utils_cjs_1.assert)(response.exchangeRates, 'Expected exchangeRates in response'); return response; }, queryActiveExchangeRates: async () => { const response = await queryService.ActiveExchangeRates({}); (0, utils_cjs_1.assert)(response.activeRates, 'Expected activeRates in response'); return response; }, queryFeederDelegation: async (validatorAddr) => { const response = await queryService.FeederDelegation({ validatorAddr }); (0, utils_cjs_1.assert)(response.feederAddr, 'Expected feederAddr in response'); return response; }, queryMissCounter: async (validatorAddr) => { const response = await queryService.MissCounter({ validatorAddr }); (0, utils_cjs_1.assert)(response.missCounter, 'Expected missCounter in response'); return response; }, querySlashWindow: async () => { const response = await queryService.SlashWindow({}); (0, utils_cjs_1.assert)(response.windowProgress, 'Expected windowProgress in response'); return response; }, queryAggregatePrevote: async (validatorAddr) => { const response = await queryService.AggregatePrevote({ validatorAddr }); (0, utils_cjs_1.assert)(response.aggregatePrevote, 'Expected aggregatePrevote in response'); return response; }, queryAggregatePrevotes: async () => { const response = await queryService.AggregatePrevotes({}); (0, utils_cjs_1.assert)(response.aggregatePrevotes, 'Expected aggregatePrevotes in response'); return response; }, queryAggregateVote: async (validatorAddr) => { const response = await queryService.AggregateVote({ validatorAddr }); (0, utils_cjs_1.assert)(response.aggregateVote, 'Expected aggregateVote in response'); return response; }, queryAggregateVotes: async (validatorAddr) => { const response = await queryService.AggregateVotes({ validatorAddr }); (0, utils_cjs_1.assert)(response.aggregateVotes, 'Expected aggregateVotes in response'); return response; }, queryParams: async () => { const response = await queryService.Params({}); (0, utils_cjs_1.assert)(response.params, 'Expected params in response'); return response; }, queryMedians: async (denom, numStamps) => { const response = await queryService.Medians({ denom, numStamps }); (0, utils_cjs_1.assert)(response.medians, 'Expected medians in response'); return response; }, queryMedianDeviations: async (denom) => { const response = await queryService.MedianDeviations({ denom }); (0, utils_cjs_1.assert)(response.medianDeviations, 'Expected medianDeviations in response'); return response; }, queryValidatorRewardSet: async () => { const response = await queryService.ValidatorRewardSet({}); (0, utils_cjs_1.assert)(response.validators, 'Expected validators in response'); return response; }, queryEMA: async (denom) => { const response = await queryService.EMA({ denom }); (0, utils_cjs_1.assert)(response.price, 'Expected price in response'); return response; }, queryWMA: async (denom, strategy = exports.WMAStrategies.BALANCED, weights = []) => { const response = await queryService.WMA({ denom, strategy, customWeights: weights }); (0, utils_cjs_1.assert)(response.price, 'Expected price in response'); return response; }, querySMA: async (denom) => { const response = await queryService.SMA({ denom }); (0, utils_cjs_1.assert)(response.price, 'Expected price in response'); return response; }, convertUSDtoCHEQ: async (usdAmount, movingAverage, wmaStrategy = exports.WMAStrategies.BALANCED, weights = []) => { const response = await queryService.ConvertUSDCtoCHEQ({ amount: `${usdAmount}usd`, maType: movingAverage, wmaStrategy, customWeights: weights.map((w) => Number(w)), }); (0, utils_cjs_1.assert)(response.amount, 'Expected amount in response'); return response; }, }, }; }; exports.setupOracleExtension = setupOracleExtension; /** * Oracle Module class providing comprehensive access to Oracle functionalities. * Handles both querying and transaction operations related to the Oracle module. */ class OracleModule extends _1.AbstractCheqdSDKModule { // @ts-expect-error underlying type `GeneratedType` is intentionally wider static registryTypes = [ [exports.typeUrlMsgAggregateExchangeRatePrevote, v2_1.MsgAggregateExchangeRatePrevote], [exports.typeUrlMsgAggregateExchangeRatePrevoteResponse, v2_1.MsgAggregateExchangeRatePrevoteResponse], [exports.typeUrlMsgAggregateExchangeRateVote, v2_1.MsgAggregateExchangeRateVote], [exports.typeUrlMsgDelegateFeedConsent, v2_1.MsgDelegateFeedConsent], [exports.typeUrlMsgLegacyGovUpdateParams, v2_1.MsgLegacyGovUpdateParams], [exports.typeUrlMsgGovUpdateParams, v2_1.MsgGovUpdateParams], [exports.typeUrlMsgGovAddDenoms, v2_1.MsgGovAddDenoms], [exports.typeUrlMsgGovRemoveCurrencyPairProviders, v2_1.MsgGovRemoveCurrencyPairProviders], [exports.typeUrlMsgGovRemoveCurrencyDeviationThresholds, v2_1.MsgGovRemoveCurrencyDeviationThresholds], [exports.typeUrlMsgGovCancelUpdateParamPlan, v2_1.MsgGovCancelUpdateParamPlan], ]; /** Base denomination tickers for Cheqd network Oracle */ static baseDenomTickers = { CHEQ: 'CHEQ', USDC: 'USDC', USDT: 'USDT', }; /** Querier extension setup function for Oracle operations */ static querierExtensionSetup = exports.setupOracleExtension; /** Querier instance with Oracle extension capabilities */ querier; /** * Constructs a new Oracle module instance. * * @param signer - Signing client for blockchain transactions * @param querier - Querier client with Oracle extension for data retrieval */ constructor(signer, querier) { super(signer, querier); this.querier = querier; this.methods = { aggregateExchangeRatePrevoteTx: this.aggregateExchangeRatePrevoteTx.bind(this), aggregateExchangeRateVoteTx: this.aggregateExchangeRateVoteTx.bind(this), delegateFeedConsentTx: this.delegateFeedConsentTx.bind(this), legacyGovUpdateParamsTx: this.legacyGovUpdateParamsTx.bind(this), govUpdateParamsTx: this.govUpdateParamsTx.bind(this), govAddDenomsTx: this.govAddDenomsTx.bind(this), govRemoveCurrencyPairProvidersTx: this.govRemoveCurrencyPairProvidersTx.bind(this), govRemoveCurrencyDeviationThresholdsTx: this.govRemoveCurrencyDeviationThresholdsTx.bind(this), govCancelUpdateParamPlanTx: this.govCancelUpdateParamPlanTx.bind(this), queryExchangeRates: this.querier[exports.defaultOracleExtensionKey].queryExchangeRates.bind(this), queryActiveExchangeRates: this.querier[exports.defaultOracleExtensionKey].queryActiveExchangeRates.bind(this), queryFeederDelegation: this.querier[exports.defaultOracleExtensionKey].queryFeederDelegation.bind(this), queryMissCounter: this.querier[exports.defaultOracleExtensionKey].queryMissCounter.bind(this), querySlashWindow: this.querier[exports.defaultOracleExtensionKey].querySlashWindow.bind(this), queryAggregatePrevote: this.querier[exports.defaultOracleExtensionKey].queryAggregatePrevote.bind(this), queryAggregatePrevotes: this.querier[exports.defaultOracleExtensionKey].queryAggregatePrevotes.bind(this), queryAggregateVote: this.querier[exports.defaultOracleExtensionKey].queryAggregateVote.bind(this), queryAggregateVotes: this.querier[exports.defaultOracleExtensionKey].queryAggregateVotes.bind(this), queryParams: this.querier[exports.defaultOracleExtensionKey].queryParams.bind(this), queryMedians: this.querier[exports.defaultOracleExtensionKey].queryMedians.bind(this), queryMedianDeviations: this.querier[exports.defaultOracleExtensionKey].queryMedianDeviations.bind(this), queryValidatorRewardSet: this.querier[exports.defaultOracleExtensionKey].queryValidatorRewardSet.bind(this), queryEMA: this.querier[exports.defaultOracleExtensionKey].queryEMA.bind(this), queryWMA: this.querier[exports.defaultOracleExtensionKey].queryWMA.bind(this), querySMA: this.querier[exports.defaultOracleExtensionKey].querySMA.bind(this), convertUSDtoCHEQ: this.querier[exports.defaultOracleExtensionKey].convertUSDtoCHEQ.bind(this), }; } /** * Gets the registry types for Oracle message encoding/decoding. * * @returns Iterable of [typeUrl, GeneratedType] pairs for the registry */ getRegistryTypes() { return OracleModule.registryTypes; } /** * Gets the querier extension setup for Oracle operations. * * @returns Query extension setup function for Oracle functionality */ getQuerierExtensionSetup() { return OracleModule.querierExtensionSetup; } /** * Queries the module parameters from the blockchain. * * @returns Promise resolving to the QueryParamsResponse containing module parameters */ async queryParams() { return this.querier[exports.defaultOracleExtensionKey].queryParams(); } /** * Queries the exchange rate for a specific denom. * @param denom - The denomination to query the exchange rate for * @returns Promise resolving to the QueryExchangeRatesResponse containing the exchange rate */ async queryExchangeRate(denom) { return this.querier[exports.defaultOracleExtensionKey].queryExchangeRates(denom); } /** * Queries all active exchange rate denoms. * @returns Promise resolving to the QueryActiveExchangeRatesResponse containing active denoms */ async queryActiveExchangeRates() { return this.querier[exports.defaultOracleExtensionKey].queryActiveExchangeRates(); } /** * Queries the Exponential Moving Average (EMA) for a given denom. * @param denom - The denomination to query the EMA for * @returns Promise resolving to the QueryEMAResponse containing the EMA price in string Decimal format */ async queryEMA(denom) { const response = await this.querier[exports.defaultOracleExtensionKey].queryEMA(denom); return { price: math_cjs_1.Decimal.fromAtomics(BigInt(response.price).toString(), 18).toString(), }; } /** * Queries the Weighted Moving Average (WMA) for a given denom. * @param denom - The denomination to query the WMA for * @param strategy - Optional WMA strategy, defaults to 'BALANCED' * @param weights - Optional custom weights for the WMA calculation * @returns Promise resolving to the QueryWMAResponse containing the WMA price in string Decimal format */ async queryWMA(denom, strategy, weights) { const response = await this.querier[exports.defaultOracleExtensionKey].queryWMA(denom, strategy, weights?.map((w) => BigInt(w))); return { price: math_cjs_1.Decimal.fromAtomics(BigInt(response.price).toString(), 18).toString(), }; } /** * Queries the Simple Moving Average (SMA) for a given denom. * @param denom - The denomination to query the SMA for * @returns Promise resolving to the QuerySMAResponse containing the SMA price in string Decimal format */ async querySMA(denom) { const response = await this.querier[exports.defaultOracleExtensionKey].querySMA(denom); return { price: math_cjs_1.Decimal.fromAtomics(BigInt(response.price).toString(), 18).toString(), }; } /** * Converts a USD amount to CHEQ using the specified moving average type. * @param usdAmount - The USD amount to convert * @param movingAverage - The type of moving average to use for conversion * @param wmaStrategy - Optional WMA strategy, defaults to 'BALANCED' * @param weights - Optional custom weights for WMA calculation * @returns Promise resolving to the ConvertUSDCtoCHEQResponse containing the converted CHEQ amount */ async convertUSDtoCHEQ(usdAmount, movingAverage, wmaStrategy, weights) { return this.querier[exports.defaultOracleExtensionKey].convertUSDtoCHEQ(usdAmount, movingAverage, wmaStrategy, weights?.map((w) => BigInt(w))); } /** * Broadcasts an aggregate exchange rate prevote transaction. * * @param payload - Message payload describing the prevote * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @returns Promise resolving to the DeliverTxResponse */ async aggregateExchangeRatePrevoteTx(payload, address, fee, memo = '', context) { const encObj = { typeUrl: exports.typeUrlMsgAggregateExchangeRatePrevote, value: v2_1.MsgAggregateExchangeRatePrevote.fromPartial(payload), }; return this.broadcastOracleTx(encObj, address, fee, memo, context); } /** * Broadcasts an aggregate exchange rate vote transaction. * * @param payload - Message payload describing the vote * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @returns Promise resolving to the DeliverTxResponse */ async aggregateExchangeRateVoteTx(payload, address, fee, memo = '', context) { const encObj = { typeUrl: exports.typeUrlMsgAggregateExchangeRateVote, value: v2_1.MsgAggregateExchangeRateVote.fromPartial(payload), }; return this.broadcastOracleTx(encObj, address, fee, memo, context); } /** * Delegates feed consent between operator and delegate. * * @param payload - Message payload describing the delegation * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @returns Promise resolving to the DeliverTxResponse */ async delegateFeedConsentTx(payload, address, fee, memo = '', context) { const encObj = { typeUrl: exports.typeUrlMsgDelegateFeedConsent, value: v2_1.MsgDelegateFeedConsent.fromPartial(payload), }; return this.broadcastOracleTx(encObj, address, fee, memo, context); } /** * Submits a legacy governance update params transaction via MsgSubmitProposal. * * @param payload - Legacy governance update parameters payload * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async legacyGovUpdateParamsTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgLegacyGovUpdateParams, value: v2_1.MsgLegacyGovUpdateParams.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Submits a governance update params transaction via MsgSubmitProposal. * * @param payload - Governance update parameters payload * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async govUpdateParamsTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgGovUpdateParams, value: v2_1.MsgGovUpdateParams.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Adds new denoms to the oracle registry via MsgSubmitProposal. * * @param payload - Governance proposal payload that describes the new denoms * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async govAddDenomsTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgGovAddDenoms, value: v2_1.MsgGovAddDenoms.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Removes currency pair providers from the oracle configuration via MsgSubmitProposal. * * @param payload - Governance proposal payload describing providers to remove * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async govRemoveCurrencyPairProvidersTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgGovRemoveCurrencyPairProviders, value: v2_1.MsgGovRemoveCurrencyPairProviders.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Removes currency deviation thresholds via MsgSubmitProposal. * * @param payload - Governance payload describing currencies to remove * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async govRemoveCurrencyDeviationThresholdsTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgGovRemoveCurrencyDeviationThresholds, value: v2_1.MsgGovRemoveCurrencyDeviationThresholds.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Cancels a pending parameter update plan via MsgSubmitProposal. * * @param payload - Governance payload containing cancellation details * @param address - Address responsible for paying the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context to lazily resolve signer or wallet * @param proposalOptions - Optional MsgSubmitProposal configuration such as deposit or metadata * @returns Promise resolving to the DeliverTxResponse */ async govCancelUpdateParamPlanTx(payload, address, fee, memo = '', context, proposalOptions) { const signerAddress = await this.ensureSignerAddress(address, context); const proposalMsg = { typeUrl: tx_1.MsgSubmitProposal.typeUrl, value: tx_1.MsgSubmitProposal.fromPartial({ messages: [ { typeUrl: exports.typeUrlMsgGovCancelUpdateParamPlan, value: v2_1.MsgGovCancelUpdateParamPlan.encode(payload).finish(), }, ], proposer: signerAddress, initialDeposit: proposalOptions?.deposit ?? [], metadata: proposalOptions?.metadata ?? '', title: payload.title ?? '', summary: proposalOptions?.summary ?? payload.description ?? '', expedited: proposalOptions?.expedited ?? false, }), }; return this.broadcastOracleTx(proposalMsg, signerAddress, fee, memo, context); } /** * Ensures a signer client exists and resolves the address to use for broadcasting. * * @param address - Address provided by the caller (optional) * @param context - Optional SDK context used to resolve signer or wallet * @returns Resolved signer address */ async ensureSignerAddress(address, context) { if (!this._signer) { (0, utils_cjs_1.assert)(context?.sdk?.signer, 'Signer client is required to broadcast oracle transactions'); this._signer = context.sdk.signer; } if (address && address.length > 0) { return address; } (0, utils_cjs_1.assert)(context?.sdk?.options?.wallet, 'Wallet context is required when no address is provided'); const accounts = await context.sdk.options.wallet.getAccounts(); (0, utils_cjs_1.assert)(accounts.length > 0, 'No accounts available in the provided wallet'); return accounts[0].address; } /** * Signs and broadcasts the provided oracle transaction. * * @param message - EncodeObject representing the oracle message * @param address - Address responsible for the transaction fees * @param fee - Optional fee configuration, defaults to automatic calculation * @param memo - Optional transaction memo * @param context - Optional SDK context used to resolve signer or wallet * @returns Promise resolving to the DeliverTxResponse */ async broadcastOracleTx(message, address, fee, memo = '', context) { const signerAddress = await this.ensureSignerAddress(address, context); return this._signer.signAndBroadcast(signerAddress, [message], fee ?? 'auto', memo); } /** * Parses a decimal price string back into its atomic representation. * @param price - Price in decimal string format * @returns Promise resolving to the atomic string representation of the price */ static async parseFromDecimalPrice(price) { const decimal = math_cjs_1.Decimal.fromUserInput(price, 18); return decimal.atomics; } } exports.OracleModule = OracleModule; //# sourceMappingURL=oracle.js.map