@cheqd/sdk
Version:
A TypeScript SDK built with CosmJS to interact with the cheqd network ledger
493 lines • 23.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeeabstractionModule = exports.setupFeeabstractionExtension = exports.typeUrlMsgUpdateParamsResponse = exports.typeUrlMsgUpdateParams = exports.typeUrlMsgUpdateHostZoneResponse = exports.typeUrlMsgUpdateHostZone = exports.typeUrlMsgSwapCrossChainResponse = exports.typeUrlMsgSwapCrossChain = exports.typeUrlMsgSendQueryIbcDenomTWAPResponse = exports.typeUrlMsgSendQueryIbcDenomTWAP = exports.typeUrlMsgRemoveHostZoneResponse = exports.typeUrlMsgRemoveHostZone = exports.typeUrlMsgFundFeeAbsModuleAccountResponse = exports.typeUrlMsgFundFeeAbsModuleAccount = exports.typeUrlMsgAddHostZoneResponse = exports.typeUrlMsgAddHostZone = exports.protobufLiterals = exports.defaultFeeabstractionExtensionKey = void 0;
exports.isMsgAddHostZoneEncodeObject = isMsgAddHostZoneEncodeObject;
exports.isMsgAddHostZoneResponseEncodeObject = isMsgAddHostZoneResponseEncodeObject;
exports.isMsgFundFeeAbsModuleAccountEncodeObject = isMsgFundFeeAbsModuleAccountEncodeObject;
exports.isMsgFundFeeAbsModuleAccountResponseEncodeObject = isMsgFundFeeAbsModuleAccountResponseEncodeObject;
exports.isMsgRemoveHostZoneEncodeObject = isMsgRemoveHostZoneEncodeObject;
exports.isMsgRemoveHostZoneResponseEncodeObject = isMsgRemoveHostZoneResponseEncodeObject;
exports.isMsgSendQueryIbcDenomTWAPEncodeObject = isMsgSendQueryIbcDenomTWAPEncodeObject;
exports.isMsgSendQueryIbcDenomTWAPResponseEncodeObject = isMsgSendQueryIbcDenomTWAPResponseEncodeObject;
exports.isMsgSwapCrossChainEncodeObject = isMsgSwapCrossChainEncodeObject;
exports.isMsgSwapCrossChainResponseEncodeObject = isMsgSwapCrossChainResponseEncodeObject;
exports.isMsgUpdateHostZoneEncodeObject = isMsgUpdateHostZoneEncodeObject;
exports.isMsgUpdateHostZoneResponseEncodeObject = isMsgUpdateHostZoneResponseEncodeObject;
exports.isMsgUpdateParamsEncodeObject = isMsgUpdateParamsEncodeObject;
exports.isMsgUpdateParamsResponseEncodeObject = isMsgUpdateParamsResponseEncodeObject;
const index_1 = require("@cheqd/ts-proto-cjs/feeabstraction/feeabs/v1beta1/index");
const _1 = require("./_");
const stargate_cjs_1 = require("@cosmjs/stargate-cjs");
const tx_1 = require("cosmjs-types/cosmos/gov/v1/tx");
/** Default extension key for fee abstraction-related query operations */
exports.defaultFeeabstractionExtensionKey = 'feeabs';
/**
* Protobuf message type literals for fee abstraction operations.
* Used for consistent message type identification across the module.
*/
exports.protobufLiterals = {
/** Add host zone message type */
MsgAddHostZone: 'MsgAddHostZone',
/** Add host zone response message type */
MsgAddHostZoneResponse: 'MsgAddHostZoneResponse',
/** Fund fee abstraction module account message type */
MsgFundFeeAbsModuleAccount: 'MsgFundFeeAbsModuleAccount',
/** Fund fee abstraction module account response message type */
MsgFundFeeAbsModuleAccountResponse: 'MsgFundFeeAbsModuleAccountResponse',
/** Remove host zone message type */
MsgRemoveHostZone: 'MsgRemoveHostZone',
/** Remove host zone response message type */
MsgRemoveHostZoneResponse: 'MsgRemoveHostZoneResponse',
/** Send query IBC denomination TWAP message type */
MsgSendQueryIbcDenomTWAP: 'MsgSendQueryIbcDenomTWAP',
/** Send query IBC denomination TWAP response message type */
MsgSendQueryIbcDenomTWAPResponse: 'MsgSendQueryIbcDenomTWAPResponse',
/** Swap cross-chain message type */
MsgSwapCrossChain: 'MsgSwapCrossChain',
/** Swap cross-chain response message type */
MsgSwapCrossChainResponse: 'MsgSwapCrossChainResponse',
/** Update host zone message type */
MsgUpdateHostZone: 'MsgUpdateHostZone',
/** Update host zone response message type */
MsgUpdateHostZoneResponse: 'MsgUpdateHostZoneResponse',
/** Update parameters message type */
MsgUpdateParams: 'MsgUpdateParams',
/** Update parameters response message type */
MsgUpdateParamsResponse: 'MsgUpdateParamsResponse',
};
/** Type URL for MsgAddHostZone messages */
exports.typeUrlMsgAddHostZone = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgAddHostZone}`;
/** Type URL for MsgAddHostZoneResponse messages */
exports.typeUrlMsgAddHostZoneResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgAddHostZoneResponse}`;
/** Type URL for MsgFundFeeAbsModuleAccount messages */
exports.typeUrlMsgFundFeeAbsModuleAccount = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgFundFeeAbsModuleAccount}`;
/** Type URL for MsgFundFeeAbsModuleAccountResponse messages */
exports.typeUrlMsgFundFeeAbsModuleAccountResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgFundFeeAbsModuleAccountResponse}`;
/** Type URL for MsgRemoveHostZone messages */
exports.typeUrlMsgRemoveHostZone = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgRemoveHostZone}`;
/** Type URL for MsgRemoveHostZoneResponse messages */
exports.typeUrlMsgRemoveHostZoneResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgRemoveHostZoneResponse}`;
/** Type URL for MsgSendQueryIbcDenomTWAP messages */
exports.typeUrlMsgSendQueryIbcDenomTWAP = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgSendQueryIbcDenomTWAP}`;
/** Type URL for MsgSendQueryIbcDenomTWAPResponse messages */
exports.typeUrlMsgSendQueryIbcDenomTWAPResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgSendQueryIbcDenomTWAPResponse}`;
/** Type URL for MsgSwapCrossChain messages */
exports.typeUrlMsgSwapCrossChain = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgSwapCrossChain}`;
/** Type URL for MsgSwapCrossChainResponse messages */
exports.typeUrlMsgSwapCrossChainResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgSwapCrossChainResponse}`;
/** Type URL for MsgUpdateHostZone messages */
exports.typeUrlMsgUpdateHostZone = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgUpdateHostZone}`;
/** Type URL for MsgUpdateHostZoneResponse messages */
exports.typeUrlMsgUpdateHostZoneResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgUpdateHostZoneResponse}`;
/** Type URL for MsgUpdateParams messages */
exports.typeUrlMsgUpdateParams = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgUpdateParams}`;
/** Type URL for MsgUpdateParamsResponse messages */
exports.typeUrlMsgUpdateParamsResponse = `/${index_1.protobufPackage}.${exports.protobufLiterals.MsgUpdateParamsResponse}`;
/**
* Type guard function to check if an object is a MsgAddHostZoneEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgAddHostZoneEncodeObject
*/
function isMsgAddHostZoneEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgAddHostZone;
}
/**
* Type guard function to check if an object is a MsgAddHostZoneResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgAddHostZoneResponseEncodeObject
*/
function isMsgAddHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgAddHostZoneResponse;
}
/**
* Type guard function to check if an object is a MsgFundFeeAbsModuleAccountEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgFundFeeAbsModuleAccountEncodeObject
*/
function isMsgFundFeeAbsModuleAccountEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgFundFeeAbsModuleAccount;
}
/**
* Type guard function to check if an object is a MsgFundFeeAbsModuleAccountResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgFundFeeAbsModuleAccountResponseEncodeObject
*/
function isMsgFundFeeAbsModuleAccountResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgFundFeeAbsModuleAccountResponse;
}
/**
* Type guard function to check if an object is a MsgRemoveHostZoneEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgRemoveHostZoneEncodeObject
*/
function isMsgRemoveHostZoneEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgRemoveHostZone;
}
/**
* Type guard function to check if an object is a MsgRemoveHostZoneResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgRemoveHostZoneResponseEncodeObject
*/
function isMsgRemoveHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgRemoveHostZoneResponse;
}
/**
* Type guard function to check if an object is a MsgSendQueryIbcDenomTWAPEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgSendQueryIbcDenomTWAPEncodeObject
*/
function isMsgSendQueryIbcDenomTWAPEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgSendQueryIbcDenomTWAP;
}
/**
* Type guard function to check if an object is a MsgSendQueryIbcDenomTWAPResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgSendQueryIbcDenomTWAPResponseEncodeObject
*/
function isMsgSendQueryIbcDenomTWAPResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgSendQueryIbcDenomTWAPResponse;
}
/**
* Type guard function to check if an object is a MsgSwapCrossChainEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgSwapCrossChainEncodeObject
*/
function isMsgSwapCrossChainEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgSwapCrossChain;
}
/**
* Type guard function to check if an object is a MsgSwapCrossChainResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgSwapCrossChainResponseEncodeObject
*/
function isMsgSwapCrossChainResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgSwapCrossChainResponse;
}
/**
* Type guard function to check if an object is a MsgUpdateHostZoneEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateHostZoneEncodeObject
*/
function isMsgUpdateHostZoneEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgUpdateHostZone;
}
/**
* Type guard function to check if an object is a MsgUpdateHostZoneResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateHostZoneResponseEncodeObject
*/
function isMsgUpdateHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgUpdateHostZoneResponse;
}
/**
* Type guard function to check if an object is a MsgUpdateParamsEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateParamsEncodeObject
*/
function isMsgUpdateParamsEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgUpdateParams;
}
/**
* Type guard function to check if an object is a MsgUpdateParamsResponseEncodeObject.
*
* @param obj - EncodeObject to check
* @returns True if the object is a MsgUpdateParamsResponseEncodeObject
*/
function isMsgUpdateParamsResponseEncodeObject(obj) {
return obj.typeUrl === exports.typeUrlMsgUpdateParamsResponse;
}
/**
* Sets up the fee abstraction extension for the querier client.
* Creates and configures the fee abstraction-specific query methods.
*
* @param base - Base QueryClient to extend
* @returns Configured fee abstraction extension with query methods
*/
const setupFeeabstractionExtension = (base) => {
const rpc = (0, stargate_cjs_1.createProtobufRpcClient)(base);
const queryService = new index_1.QueryClientImpl(rpc);
return {
[exports.defaultFeeabstractionExtensionKey]: {
hostChainConfig: async (request) => {
return await queryService.HostChainConfig(request);
},
osmosisArithmeticTwap: async (request) => {
return await queryService.OsmosisArithmeticTwap(request);
},
feeabsModuleBalances: async (request) => {
return await queryService.FeeabsModuleBalances(request);
},
},
};
};
exports.setupFeeabstractionExtension = setupFeeabstractionExtension;
/**
* Fee Abstraction Module class providing comprehensive fee abstraction functionality.
* Handles host zone management, cross-chain swaps, and fee abstraction operations on the Cheqd blockchain.
*/
class FeeabstractionModule extends _1.AbstractCheqdSDKModule {
//@ts-expect-error underlying type `GeneratedType` is intentionally wider
static registryTypes = [
[exports.typeUrlMsgAddHostZone, index_1.MsgAddHostZone],
[exports.typeUrlMsgAddHostZoneResponse, index_1.MsgAddHostZoneResponse],
[exports.typeUrlMsgFundFeeAbsModuleAccount, index_1.MsgFundFeeAbsModuleAccount],
[exports.typeUrlMsgFundFeeAbsModuleAccountResponse, index_1.MsgFundFeeAbsModuleAccountResponse],
[exports.typeUrlMsgRemoveHostZone, index_1.MsgRemoveHostZone],
[exports.typeUrlMsgRemoveHostZoneResponse, index_1.MsgRemoveHostZoneResponse],
[exports.typeUrlMsgSendQueryIbcDenomTWAP, index_1.MsgSendQueryIbcDenomTWAP],
[exports.typeUrlMsgSendQueryIbcDenomTWAPResponse, index_1.MsgSendQueryIbcDenomTWAPResponse],
[exports.typeUrlMsgSwapCrossChain, index_1.MsgSwapCrossChain],
[exports.typeUrlMsgSwapCrossChainResponse, index_1.MsgSwapCrossChainResponse],
[exports.typeUrlMsgUpdateHostZone, index_1.MsgUpdateHostZone],
[exports.typeUrlMsgUpdateHostZoneResponse, index_1.MsgUpdateHostZoneResponse],
[exports.typeUrlMsgUpdateParams, index_1.MsgUpdateParams],
[exports.typeUrlMsgUpdateParamsResponse, index_1.MsgUpdateParamsResponse],
];
/** Querier extension setup function for fee abstraction operations */
static querierExtensionSetup = exports.setupFeeabstractionExtension;
/** Querier instance with fee abstraction extension capabilities */
querier;
/**
* Constructs a new fee abstraction module instance.
*
* @param signer - Signing client for blockchain transactions
* @param querier - Querier client with fee abstraction extension for data retrieval
*/
constructor(signer, querier) {
super(signer, querier);
this.querier = querier;
this.methods = {
addHostZoneProposal: this.addHostZoneProposal.bind(this),
fundFeeAbsModuleAccount: this.fundFeeAbsModuleAccount.bind(this),
removeHostZoneProposal: this.removeHostZoneProposal.bind(this),
sendQueryIbcDenomTWAP: this.sendQueryIbcDenomTWAP.bind(this),
swapCrossChain: this.swapCrossChain.bind(this),
updateHostZoneProposal: this.updateHostZoneProposal.bind(this),
updateParamsProposal: this.updateParamsProposal.bind(this),
};
}
/**
* Gets the registry types for fee abstraction message encoding/decoding.
*
* @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
*/
getRegistryTypes() {
return FeeabstractionModule.registryTypes;
}
/**
* Gets the querier extension setup for fee abstraction operations.
*
* @returns Query extension setup function for fee abstraction functionality
*/
getQuerierExtensionSetup() {
return FeeabstractionModule.querierExtensionSetup;
}
/**
* Creates a governance proposal to add a new host zone for fee abstraction.
* Submits the proposal through the governance module for community voting.
*
* @param data - Host zone data to add
* @param title - Proposal title
* @param deposit - Initial deposit for the proposal
* @param proposer - Address of the proposal submitter
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
*/
async addHostZoneProposal(data, title, deposit, proposer, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const proposalEncodeObject = {
typeUrl: '/cosmos.gov.v1.MsgSubmitProposal',
value: tx_1.MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: exports.typeUrlMsgAddHostZone,
value: Uint8Array.from(index_1.MsgAddHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
/**
* Funds the fee abstraction module account with tokens.
* Allows users to provide liquidity for fee abstraction functionality.
*
* @param sender - Address of the account sending funds
* @param amount - Array of coins to send to the module account
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
*/
async fundFeeAbsModuleAccount(sender, amount, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const fundFeeAbsModuleAccountMsg = {
typeUrl: exports.typeUrlMsgFundFeeAbsModuleAccount,
value: {
sender,
amount,
},
};
return await this._signer.signAndBroadcast(sender, [fundFeeAbsModuleAccountMsg], fee, memo);
}
/**
* Creates a governance proposal to remove an existing host zone from fee abstraction.
* Submits the proposal through the governance module for community voting.
*
* @param data - Host zone data to remove
* @param title - Proposal title
* @param deposit - Initial deposit for the proposal
* @param proposer - Address of the proposal submitter
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
*/
async removeHostZoneProposal(data, title, deposit, proposer, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const proposalEncodeObject = {
typeUrl: '/cosmos.gov.v1.MsgSubmitProposal',
value: tx_1.MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: exports.typeUrlMsgRemoveHostZone,
value: Uint8Array.from(index_1.MsgRemoveHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
/**
* Sends a query for IBC denomination Time-Weighted Average Price (TWAP) data.
* Initiates a cross-chain query to retrieve pricing information for fee calculation.
*
* @param sender - Address of the account sending the query
* @param data - TWAP query data containing denomination and parameters
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the TWAP query response
*/
async sendQueryIbcDenomTWAP(sender, data, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const sendQueryIbcDenomTwapMsg = {
typeUrl: exports.typeUrlMsgSendQueryIbcDenomTWAP,
value: data,
};
return await this._signer.signAndBroadcast(sender, [sendQueryIbcDenomTwapMsg], fee, memo);
}
/**
* Performs a cross-chain token swap using fee abstraction.
* Enables users to swap IBC tokens across different chains.
*
* @param sender - Address of the account initiating the swap
* @param ibcDenom - IBC denomination to swap
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the swap response
*/
async swapCrossChain(sender, ibcDenom, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const swapCrossChainMsg = {
typeUrl: exports.typeUrlMsgSwapCrossChain,
value: {
ibcDenom,
},
};
return await this._signer.signAndBroadcast(sender, [swapCrossChainMsg], fee, memo);
}
/**
* Creates a governance proposal to update an existing host zone configuration.
* Submits the proposal through the governance module for community voting.
*
* @param data - Updated host zone configuration data
* @param title - Proposal title
* @param deposit - Initial deposit for the proposal
* @param proposer - Address of the proposal submitter
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
*/
async updateHostZoneProposal(data, title, deposit, proposer, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const proposalEncodeObject = {
typeUrl: '/cosmos.gov.v1.MsgSubmitProposal',
value: tx_1.MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: exports.typeUrlMsgUpdateHostZone,
value: Uint8Array.from(index_1.MsgUpdateHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
/**
* Creates a governance proposal to update fee abstraction module parameters.
* Submits the proposal through the governance module for community voting.
*
* @param data - Updated module parameters
* @param title - Proposal title
* @param deposit - Initial deposit for the proposal
* @param proposer - Address of the proposal submitter
* @param fee - Transaction fee configuration
* @param memo - Optional transaction memo
* @param context - Optional SDK context for accessing clients
* @returns Promise resolving to the transaction response
*/
async updateParamsProposal(data, title, deposit, proposer, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const proposalEncodeObject = {
typeUrl: '/cosmos.gov.v1.MsgSubmitProposal',
value: tx_1.MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: exports.typeUrlMsgUpdateParams,
value: Uint8Array.from(index_1.MsgUpdateParams.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
}
exports.FeeabstractionModule = FeeabstractionModule;
//# sourceMappingURL=feeabstraction.js.map