@cheqd/sdk
Version:
A TypeScript SDK built with CosmJS to interact with the cheqd network ledger
243 lines • 11.7 kB
JavaScript
import { protobufPackage, MsgAddHostZone, MsgAddHostZoneResponse, MsgFundFeeAbsModuleAccount, MsgFundFeeAbsModuleAccountResponse, MsgRemoveHostZone, MsgRemoveHostZoneResponse, MsgSendQueryIbcDenomTWAP, MsgSendQueryIbcDenomTWAPResponse, MsgSwapCrossChain, MsgSwapCrossChainResponse, MsgUpdateHostZone, MsgUpdateHostZoneResponse, MsgUpdateParams, MsgUpdateParamsResponse, QueryClientImpl, } from '@cheqd/ts-proto/feeabstraction/feeabs/v1beta1/index.js';
import { AbstractCheqdSDKModule } from './_.js';
import { createProtobufRpcClient } from '@cosmjs/stargate';
import { MsgSubmitProposal } from 'cosmjs-types/cosmos/gov/v1/tx.js';
export const defaultExtensionKey = 'feeabs';
export const protobufLiterals = {
MsgAddHostZone: 'MsgAddHostZone',
MsgAddHostZoneResponse: 'MsgAddHostZoneResponse',
MsgFundFeeAbsModuleAccount: 'MsgFundFeeAbsModuleAccount',
MsgFundFeeAbsModuleAccountResponse: 'MsgFundFeeAbsModuleAccountResponse',
MsgRemoveHostZone: 'MsgRemoveHostZone',
MsgRemoveHostZoneResponse: 'MsgRemoveHostZoneResponse',
MsgSendQueryIbcDenomTWAP: 'MsgSendQueryIbcDenomTWAP',
MsgSendQueryIbcDenomTWAPResponse: 'MsgSendQueryIbcDenomTWAPResponse',
MsgSwapCrossChain: 'MsgSwapCrossChain',
MsgSwapCrossChainResponse: 'MsgSwapCrossChainResponse',
MsgUpdateHostZone: 'MsgUpdateHostZone',
MsgUpdateHostZoneResponse: 'MsgUpdateHostZoneResponse',
MsgUpdateParams: 'MsgUpdateParams',
MsgUpdateParamsResponse: 'MsgUpdateParamsResponse',
};
export const typeUrlMsgAddHostZone = `/${protobufPackage}.${protobufLiterals.MsgAddHostZone}`;
export const typeUrlMsgAddHostZoneResponse = `/${protobufPackage}.${protobufLiterals.MsgAddHostZoneResponse}`;
export const typeUrlMsgFundFeeAbsModuleAccount = `/${protobufPackage}.${protobufLiterals.MsgFundFeeAbsModuleAccount}`;
export const typeUrlMsgFundFeeAbsModuleAccountResponse = `/${protobufPackage}.${protobufLiterals.MsgFundFeeAbsModuleAccountResponse}`;
export const typeUrlMsgRemoveHostZone = `/${protobufPackage}.${protobufLiterals.MsgRemoveHostZone}`;
export const typeUrlMsgRemoveHostZoneResponse = `/${protobufPackage}.${protobufLiterals.MsgRemoveHostZoneResponse}`;
export const typeUrlMsgSendQueryIbcDenomTWAP = `/${protobufPackage}.${protobufLiterals.MsgSendQueryIbcDenomTWAP}`;
export const typeUrlMsgSendQueryIbcDenomTWAPResponse = `/${protobufPackage}.${protobufLiterals.MsgSendQueryIbcDenomTWAPResponse}`;
export const typeUrlMsgSwapCrossChain = `/${protobufPackage}.${protobufLiterals.MsgSwapCrossChain}`;
export const typeUrlMsgSwapCrossChainResponse = `/${protobufPackage}.${protobufLiterals.MsgSwapCrossChainResponse}`;
export const typeUrlMsgUpdateHostZone = `/${protobufPackage}.${protobufLiterals.MsgUpdateHostZone}`;
export const typeUrlMsgUpdateHostZoneResponse = `/${protobufPackage}.${protobufLiterals.MsgUpdateHostZoneResponse}`;
export const typeUrlMsgUpdateParams = `/${protobufPackage}.${protobufLiterals.MsgUpdateParams}`;
export const typeUrlMsgUpdateParamsResponse = `/${protobufPackage}.${protobufLiterals.MsgUpdateParamsResponse}`;
export function isMsgAddHostZoneEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgAddHostZone;
}
export function isMsgAddHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgAddHostZoneResponse;
}
export function isMsgFundFeeAbsModuleAccountEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgFundFeeAbsModuleAccount;
}
export function isMsgFundFeeAbsModuleAccountResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgFundFeeAbsModuleAccountResponse;
}
export function isMsgRemoveHostZoneEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgRemoveHostZone;
}
export function isMsgRemoveHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgRemoveHostZoneResponse;
}
export function isMsgSendQueryIbcDenomTWAPEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgSendQueryIbcDenomTWAP;
}
export function isMsgSendQueryIbcDenomTWAPResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgSendQueryIbcDenomTWAPResponse;
}
export function isMsgSwapCrossChainEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgSwapCrossChain;
}
export function isMsgSwapCrossChainResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgSwapCrossChainResponse;
}
export function isMsgUpdateHostZoneEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgUpdateHostZone;
}
export function isMsgUpdateHostZoneResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgUpdateHostZoneResponse;
}
export function isMsgUpdateParamsEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgUpdateParams;
}
export function isMsgUpdateParamsResponseEncodeObject(obj) {
return obj.typeUrl === typeUrlMsgUpdateParamsResponse;
}
export const setupFeeabstractionExtension = (base) => {
const rpc = createProtobufRpcClient(base);
const queryService = new QueryClientImpl(rpc);
return {
[defaultExtensionKey]: {
hostChainConfig: async (request) => {
return await queryService.HostChainConfig(request);
},
osmosisArithmeticTwap: async (request) => {
return await queryService.OsmosisArithmeticTwap(request);
},
feeabsModuleBalances: async (request) => {
return await queryService.FeeabsModuleBalances(request);
},
},
};
};
export class FeeabstractionModule extends AbstractCheqdSDKModule {
// @ts-expect-error underlying type `GeneratedType` is intentionally wider
static registryTypes = [
[typeUrlMsgAddHostZone, MsgAddHostZone],
[typeUrlMsgAddHostZoneResponse, MsgAddHostZoneResponse],
[typeUrlMsgFundFeeAbsModuleAccount, MsgFundFeeAbsModuleAccount],
[typeUrlMsgFundFeeAbsModuleAccountResponse, MsgFundFeeAbsModuleAccountResponse],
[typeUrlMsgRemoveHostZone, MsgRemoveHostZone],
[typeUrlMsgRemoveHostZoneResponse, MsgRemoveHostZoneResponse],
[typeUrlMsgSendQueryIbcDenomTWAP, MsgSendQueryIbcDenomTWAP],
[typeUrlMsgSendQueryIbcDenomTWAPResponse, MsgSendQueryIbcDenomTWAPResponse],
[typeUrlMsgSwapCrossChain, MsgSwapCrossChain],
[typeUrlMsgSwapCrossChainResponse, MsgSwapCrossChainResponse],
[typeUrlMsgUpdateHostZone, MsgUpdateHostZone],
[typeUrlMsgUpdateHostZoneResponse, MsgUpdateHostZoneResponse],
[typeUrlMsgUpdateParams, MsgUpdateParams],
[typeUrlMsgUpdateParamsResponse, MsgUpdateParamsResponse],
];
static querierExtensionSetup = setupFeeabstractionExtension;
querier;
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),
};
}
getRegistryTypes() {
return FeeabstractionModule.registryTypes;
}
getQuerierExtensionSetup() {
return FeeabstractionModule.querierExtensionSetup;
}
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: MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: typeUrlMsgAddHostZone,
value: Uint8Array.from(MsgAddHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
async fundFeeAbsModuleAccount(sender, amount, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const fundFeeAbsModuleAccountMsg = {
typeUrl: typeUrlMsgFundFeeAbsModuleAccount,
value: {
sender,
amount,
},
};
return await this._signer.signAndBroadcast(sender, [fundFeeAbsModuleAccountMsg], fee, memo);
}
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: MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: typeUrlMsgRemoveHostZone,
value: Uint8Array.from(MsgRemoveHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
async sendQueryIbcDenomTWAP(sender, data, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const sendQueryIbcDenomTwapMsg = {
typeUrl: typeUrlMsgSendQueryIbcDenomTWAP,
value: data,
};
return await this._signer.signAndBroadcast(sender, [sendQueryIbcDenomTwapMsg], fee, memo);
}
async swapCrossChain(sender, ibcDenom, fee, memo, context) {
if (!this._signer)
this._signer = context.sdk.signer;
const swapCrossChainMsg = {
typeUrl: typeUrlMsgSwapCrossChain,
value: {
ibcDenom,
},
};
return await this._signer.signAndBroadcast(sender, [swapCrossChainMsg], fee, memo);
}
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: MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: typeUrlMsgUpdateHostZone,
value: Uint8Array.from(MsgUpdateHostZone.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
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: MsgSubmitProposal.fromPartial({
messages: [
{
typeUrl: typeUrlMsgUpdateParams,
value: Uint8Array.from(MsgUpdateParams.encode(data).finish()),
},
],
title,
initialDeposit: deposit,
proposer,
}),
};
return await this._signer.signAndBroadcast(proposer, [proposalEncodeObject], fee, memo);
}
}
//# sourceMappingURL=feeabstraction.js.map