@cheqd/sdk-esm 5.3.7-develop.1 → 5.4.0-develop.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/src/index.d.ts +142 -0
- package/build/cjs/src/index.d.ts.map +1 -0
- package/build/cjs/src/index.js +184 -0
- package/build/cjs/src/index.js.map +1 -0
- package/build/cjs/src/modules/_.d.ts +81 -0
- package/build/cjs/src/modules/_.d.ts.map +1 -0
- package/build/cjs/src/modules/_.js +93 -0
- package/build/cjs/src/modules/_.js.map +1 -0
- package/build/cjs/src/modules/did.d.ts +488 -0
- package/build/cjs/src/modules/did.d.ts.map +1 -0
- package/build/cjs/src/modules/did.js +1249 -0
- package/build/cjs/src/modules/did.js.map +1 -0
- package/build/cjs/src/modules/feeabstraction.d.ts +429 -0
- package/build/cjs/src/modules/feeabstraction.d.ts.map +1 -0
- package/build/cjs/src/modules/feeabstraction.js +474 -0
- package/build/cjs/src/modules/feeabstraction.js.map +1 -0
- package/build/cjs/src/modules/feemarket.d.ts +244 -0
- package/build/cjs/src/modules/feemarket.d.ts.map +1 -0
- package/build/cjs/src/modules/feemarket.js +297 -0
- package/build/cjs/src/modules/feemarket.js.map +1 -0
- package/build/cjs/src/modules/oracle.d.ts +563 -0
- package/build/cjs/src/modules/oracle.d.ts.map +1 -0
- package/build/cjs/src/modules/oracle.js +784 -0
- package/build/cjs/src/modules/oracle.js.map +1 -0
- package/build/cjs/src/modules/resource.d.ts +330 -0
- package/build/cjs/src/modules/resource.d.ts.map +1 -0
- package/build/cjs/src/modules/resource.js +556 -0
- package/build/cjs/src/modules/resource.js.map +1 -0
- package/build/cjs/src/querier.d.ts +62 -0
- package/build/cjs/src/querier.d.ts.map +1 -0
- package/build/cjs/src/querier.js +87 -0
- package/build/cjs/src/querier.js.map +1 -0
- package/build/cjs/src/registry.d.ts +18 -0
- package/build/cjs/src/registry.d.ts.map +1 -0
- package/build/cjs/src/registry.js +23 -0
- package/build/cjs/src/registry.js.map +1 -0
- package/build/cjs/src/signer.d.ts +250 -0
- package/build/cjs/src/signer.d.ts.map +1 -0
- package/build/cjs/src/signer.js +617 -0
- package/build/cjs/src/signer.js.map +1 -0
- package/build/cjs/src/types.d.ts +221 -0
- package/build/cjs/src/types.d.ts.map +1 -0
- package/build/cjs/src/types.js.map +1 -0
- package/build/cjs/src/utils.d.ts +233 -0
- package/build/cjs/src/utils.d.ts.map +1 -0
- package/build/cjs/src/utils.js +571 -0
- package/build/cjs/src/utils.js.map +1 -0
- package/build/{index.d.ts → esm/src/index.d.ts} +7 -3
- package/build/esm/src/index.d.ts.map +1 -0
- package/build/{index.js → esm/src/index.js} +3 -1
- package/build/esm/src/index.js.map +1 -0
- package/build/esm/src/modules/_.d.ts.map +1 -0
- package/build/esm/src/modules/_.js.map +1 -0
- package/build/{modules → esm/src/modules}/did.d.ts +109 -7
- package/build/esm/src/modules/did.d.ts.map +1 -0
- package/build/{modules → esm/src/modules}/did.js +212 -6
- package/build/esm/src/modules/did.js.map +1 -0
- package/build/esm/src/modules/feeabstraction.d.ts.map +1 -0
- package/build/esm/src/modules/feeabstraction.js.map +1 -0
- package/build/esm/src/modules/feemarket.d.ts.map +1 -0
- package/build/esm/src/modules/feemarket.js.map +1 -0
- package/build/esm/src/modules/oracle.d.ts +563 -0
- package/build/esm/src/modules/oracle.d.ts.map +1 -0
- package/build/esm/src/modules/oracle.js +784 -0
- package/build/esm/src/modules/oracle.js.map +1 -0
- package/build/{modules → esm/src/modules}/resource.d.ts +132 -6
- package/build/esm/src/modules/resource.d.ts.map +1 -0
- package/build/esm/src/modules/resource.js +556 -0
- package/build/esm/src/modules/resource.js.map +1 -0
- package/build/esm/src/querier.d.ts.map +1 -0
- package/build/esm/src/querier.js.map +1 -0
- package/build/esm/src/registry.d.ts.map +1 -0
- package/build/esm/src/registry.js.map +1 -0
- package/build/esm/src/signer.d.ts.map +1 -0
- package/build/esm/src/signer.js.map +1 -0
- package/build/{types → esm/src}/types.d.ts +27 -1
- package/build/esm/src/types.d.ts.map +1 -0
- package/build/esm/src/types.js +43 -0
- package/build/esm/src/types.js.map +1 -0
- package/build/esm/src/utils.d.ts.map +1 -0
- package/build/esm/src/utils.js.map +1 -0
- package/build/types/cjs/src/index.d.ts +142 -0
- package/build/types/cjs/src/index.d.ts.map +1 -0
- package/build/types/cjs/src/modules/_.d.ts +81 -0
- package/build/types/cjs/src/modules/_.d.ts.map +1 -0
- package/build/types/cjs/src/modules/did.d.ts +488 -0
- package/build/types/cjs/src/modules/did.d.ts.map +1 -0
- package/build/types/cjs/src/modules/feeabstraction.d.ts +429 -0
- package/build/types/cjs/src/modules/feeabstraction.d.ts.map +1 -0
- package/build/types/cjs/src/modules/feemarket.d.ts +244 -0
- package/build/types/cjs/src/modules/feemarket.d.ts.map +1 -0
- package/build/types/cjs/src/modules/oracle.d.ts +563 -0
- package/build/types/cjs/src/modules/oracle.d.ts.map +1 -0
- package/build/types/cjs/src/modules/resource.d.ts +330 -0
- package/build/types/cjs/src/modules/resource.d.ts.map +1 -0
- package/build/types/cjs/src/querier.d.ts +62 -0
- package/build/types/cjs/src/querier.d.ts.map +1 -0
- package/build/types/cjs/src/registry.d.ts +18 -0
- package/build/types/cjs/src/registry.d.ts.map +1 -0
- package/build/types/cjs/src/signer.d.ts +250 -0
- package/build/types/cjs/src/signer.d.ts.map +1 -0
- package/build/types/cjs/src/types.d.ts +221 -0
- package/build/types/cjs/src/types.d.ts.map +1 -0
- package/build/types/cjs/src/utils.d.ts +233 -0
- package/build/types/cjs/src/utils.d.ts.map +1 -0
- package/build/types/{index.d.ts → esm/src/index.d.ts} +7 -3
- package/build/types/esm/src/index.d.ts.map +1 -0
- package/build/types/esm/src/modules/_.d.ts.map +1 -0
- package/build/types/{modules → esm/src/modules}/did.d.ts +109 -7
- package/build/types/esm/src/modules/did.d.ts.map +1 -0
- package/build/types/esm/src/modules/feeabstraction.d.ts.map +1 -0
- package/build/types/esm/src/modules/feemarket.d.ts.map +1 -0
- package/build/types/esm/src/modules/oracle.d.ts +563 -0
- package/build/types/esm/src/modules/oracle.d.ts.map +1 -0
- package/build/types/{modules → esm/src/modules}/resource.d.ts +132 -6
- package/build/types/esm/src/modules/resource.d.ts.map +1 -0
- package/build/types/esm/src/querier.d.ts.map +1 -0
- package/build/types/esm/src/registry.d.ts.map +1 -0
- package/build/types/esm/src/signer.d.ts.map +1 -0
- package/build/{types.d.ts → types/esm/src/types.d.ts} +27 -1
- package/build/types/esm/src/types.d.ts.map +1 -0
- package/build/types/esm/src/utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/build/modules/_.d.ts.map +0 -1
- package/build/modules/_.js.map +0 -1
- package/build/modules/did.d.ts.map +0 -1
- package/build/modules/did.js.map +0 -1
- package/build/modules/feeabstraction.d.ts.map +0 -1
- package/build/modules/feeabstraction.js.map +0 -1
- package/build/modules/feemarket.d.ts.map +0 -1
- package/build/modules/feemarket.js.map +0 -1
- package/build/modules/resource.d.ts.map +0 -1
- package/build/modules/resource.js +0 -297
- package/build/modules/resource.js.map +0 -1
- package/build/querier.d.ts.map +0 -1
- package/build/querier.js.map +0 -1
- package/build/registry.d.ts.map +0 -1
- package/build/registry.js.map +0 -1
- package/build/signer.d.ts.map +0 -1
- package/build/signer.js.map +0 -1
- package/build/types/index.d.ts.map +0 -1
- package/build/types/modules/_.d.ts.map +0 -1
- package/build/types/modules/did.d.ts.map +0 -1
- package/build/types/modules/feeabstraction.d.ts.map +0 -1
- package/build/types/modules/feemarket.d.ts.map +0 -1
- package/build/types/modules/resource.d.ts.map +0 -1
- package/build/types/querier.d.ts.map +0 -1
- package/build/types/registry.d.ts.map +0 -1
- package/build/types/signer.d.ts.map +0 -1
- package/build/types/types.d.ts.map +0 -1
- package/build/types/utils.d.ts.map +0 -1
- package/build/types.d.ts.map +0 -1
- package/build/types.js.map +0 -1
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js.map +0 -1
- /package/build/{types.js → cjs/src/types.js} +0 -0
- /package/build/{modules → esm/src/modules}/_.d.ts +0 -0
- /package/build/{modules → esm/src/modules}/_.js +0 -0
- /package/build/{modules → esm/src/modules}/feeabstraction.d.ts +0 -0
- /package/build/{modules → esm/src/modules}/feeabstraction.js +0 -0
- /package/build/{modules → esm/src/modules}/feemarket.d.ts +0 -0
- /package/build/{modules → esm/src/modules}/feemarket.js +0 -0
- /package/build/{querier.d.ts → esm/src/querier.d.ts} +0 -0
- /package/build/{querier.js → esm/src/querier.js} +0 -0
- /package/build/{registry.d.ts → esm/src/registry.d.ts} +0 -0
- /package/build/{registry.js → esm/src/registry.js} +0 -0
- /package/build/{signer.d.ts → esm/src/signer.d.ts} +0 -0
- /package/build/{signer.js → esm/src/signer.js} +0 -0
- /package/build/{types → esm/src}/utils.d.ts +0 -0
- /package/build/{utils.js → esm/src/utils.js} +0 -0
- /package/build/types/{modules → esm/src/modules}/_.d.ts +0 -0
- /package/build/types/{modules → esm/src/modules}/feeabstraction.d.ts +0 -0
- /package/build/types/{modules → esm/src/modules}/feemarket.d.ts +0 -0
- /package/build/types/{querier.d.ts → esm/src/querier.d.ts} +0 -0
- /package/build/types/{registry.d.ts → esm/src/registry.d.ts} +0 -0
- /package/build/types/{signer.d.ts → esm/src/signer.d.ts} +0 -0
- /package/build/{utils.d.ts → types/esm/src/utils.d.ts} +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { GasPriceResponse, GasPricesResponse, ParamsResponse } from '@cheqd/ts-proto-cjs/feemarket/feemarket/v1/index.js';
|
|
2
|
+
import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing-cjs';
|
|
3
|
+
import { GasPrice, QueryClient } from '@cosmjs/stargate-cjs';
|
|
4
|
+
import { AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from './_';
|
|
5
|
+
import { DidStdFee, IContext, QueryExtensionSetup } from '../types';
|
|
6
|
+
import { CheqdQuerier } from '../querier';
|
|
7
|
+
import { CheqdSigningStargateClient } from '../signer';
|
|
8
|
+
/** Default extension key for fee market-related query operations */
|
|
9
|
+
export declare const defaultFeemarketExtensionKey: "feemarket";
|
|
10
|
+
/**
|
|
11
|
+
* Protobuf message type literals for fee market operations.
|
|
12
|
+
* Used for consistent message type identification across the module.
|
|
13
|
+
*/
|
|
14
|
+
export declare const protobufLiterals: {
|
|
15
|
+
/** Gas price response message type */
|
|
16
|
+
readonly GasPriceResponse: "GasPriceResponse";
|
|
17
|
+
/** Gas prices response message type */
|
|
18
|
+
readonly GasPricesResponse: "GasPricesResponse";
|
|
19
|
+
/** Parameters response message type */
|
|
20
|
+
readonly ParamsResponse: "ParamsResponse";
|
|
21
|
+
};
|
|
22
|
+
/** Type URL for GasPriceResponse messages */
|
|
23
|
+
export declare const typeUrlGasPriceResponse: "/feemarket.feemarket.v1.GasPriceResponse";
|
|
24
|
+
/** Type URL for GasPricesResponse messages */
|
|
25
|
+
export declare const typeUrlGasPricesResponse: "/feemarket.feemarket.v1.GasPricesResponse";
|
|
26
|
+
/** Type URL for ParamsResponse messages */
|
|
27
|
+
export declare const typeUrlParamsResponse: "/feemarket.feemarket.v1.ParamsResponse";
|
|
28
|
+
/**
|
|
29
|
+
* Default gas price tier names for fee calculation.
|
|
30
|
+
* Provides predefined tiers for different transaction priority levels.
|
|
31
|
+
*/
|
|
32
|
+
export declare const defaultGasPriceTiers: {
|
|
33
|
+
/** Low priority tier with lowest gas prices */
|
|
34
|
+
readonly Low: "DefaultLowTier";
|
|
35
|
+
/** Average priority tier with moderate gas prices */
|
|
36
|
+
readonly Avg: "DefaultAvgTier";
|
|
37
|
+
/** High priority tier with highest gas prices */
|
|
38
|
+
readonly High: "DefaultHighTier";
|
|
39
|
+
};
|
|
40
|
+
/** Type representing the available default gas price tiers */
|
|
41
|
+
/** Type representing the available default gas price tiers */
|
|
42
|
+
export type DefaultGasPriceTiers = (typeof defaultGasPriceTiers)[keyof typeof defaultGasPriceTiers];
|
|
43
|
+
/**
|
|
44
|
+
* Encode object interface for GasPriceResponse messages.
|
|
45
|
+
* Used for type-safe message encoding in gas price operations.
|
|
46
|
+
*/
|
|
47
|
+
export interface GasPriceEncodeObject extends EncodeObject {
|
|
48
|
+
readonly typeUrl: typeof typeUrlGasPriceResponse;
|
|
49
|
+
readonly value: Partial<GasPriceResponse>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type guard function to check if an object is a GasPriceEncodeObject.
|
|
53
|
+
*
|
|
54
|
+
* @param obj - EncodeObject to check
|
|
55
|
+
* @returns True if the object is a GasPriceEncodeObject
|
|
56
|
+
*/
|
|
57
|
+
export declare function isGasPriceEncodeObject(obj: EncodeObject): obj is GasPriceEncodeObject;
|
|
58
|
+
/**
|
|
59
|
+
* Encode object interface for GasPricesResponse messages.
|
|
60
|
+
* Used for type-safe message encoding in gas prices query operations.
|
|
61
|
+
*/
|
|
62
|
+
export interface GasPricesEncodeObject extends EncodeObject {
|
|
63
|
+
readonly typeUrl: typeof typeUrlGasPricesResponse;
|
|
64
|
+
readonly value: Partial<GasPricesResponse>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Type guard function to check if an object is a GasPricesEncodeObject.
|
|
68
|
+
*
|
|
69
|
+
* @param obj - EncodeObject to check
|
|
70
|
+
* @returns True if the object is a GasPricesEncodeObject
|
|
71
|
+
*/
|
|
72
|
+
export declare function isGasPricesEncodeObject(obj: EncodeObject): obj is GasPricesEncodeObject;
|
|
73
|
+
/**
|
|
74
|
+
* Encode object interface for ParamsResponse messages.
|
|
75
|
+
* Used for type-safe message encoding in parameter query operations.
|
|
76
|
+
*/
|
|
77
|
+
export interface ParamsEncodeObject extends EncodeObject {
|
|
78
|
+
readonly typeUrl: typeof typeUrlParamsResponse;
|
|
79
|
+
readonly value: Partial<ParamsResponse>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Type guard function to check if an object is a ParamsEncodeObject.
|
|
83
|
+
*
|
|
84
|
+
* @param obj - EncodeObject to check
|
|
85
|
+
* @returns True if the object is a ParamsEncodeObject
|
|
86
|
+
*/
|
|
87
|
+
export declare function isParamsEncodeObject(obj: EncodeObject): obj is ParamsEncodeObject;
|
|
88
|
+
/** Minimal importable version of the fee market module for clean external interfaces */
|
|
89
|
+
export type MinimalImportableFeemarketModule = MinimalImportableCheqdSDKModule<FeemarketModule>;
|
|
90
|
+
/**
|
|
91
|
+
* Fee market extension interface for querier functionality.
|
|
92
|
+
* Provides methods for querying gas prices and fee market parameters.
|
|
93
|
+
*/
|
|
94
|
+
export type FeemarketExtension = {
|
|
95
|
+
readonly [defaultFeemarketExtensionKey]: {
|
|
96
|
+
/** Query gas price for a specific denomination */
|
|
97
|
+
readonly gasPrice: (denom: string) => Promise<GasPriceResponse>;
|
|
98
|
+
/** Query all available gas prices */
|
|
99
|
+
readonly gasPrices: () => Promise<GasPricesResponse>;
|
|
100
|
+
/** Query fee market module parameters */
|
|
101
|
+
readonly params: () => Promise<ParamsResponse>;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Sets up the fee market extension for the querier client.
|
|
106
|
+
* Creates and configures the fee market-specific query methods.
|
|
107
|
+
*
|
|
108
|
+
* @param base - Base QueryClient to extend
|
|
109
|
+
* @returns Configured fee market extension with query methods
|
|
110
|
+
*/
|
|
111
|
+
export declare const setupFeemarketExtension: (base: QueryClient) => FeemarketExtension;
|
|
112
|
+
/**
|
|
113
|
+
* Fee Market Module class providing comprehensive fee market functionality.
|
|
114
|
+
* Handles gas price queries, dynamic fee calculation, and fee market parameter management.
|
|
115
|
+
*/
|
|
116
|
+
export declare class FeemarketModule extends AbstractCheqdSDKModule {
|
|
117
|
+
static readonly registryTypes: Iterable<[string, GeneratedType]>;
|
|
118
|
+
/**
|
|
119
|
+
* Default gas prices for different priority tiers.
|
|
120
|
+
* Used as fallback when live gas price queries are unavailable.
|
|
121
|
+
*/
|
|
122
|
+
static readonly defaultGasPrices: {
|
|
123
|
+
DefaultLowTier: {
|
|
124
|
+
amount: string;
|
|
125
|
+
denom: string;
|
|
126
|
+
};
|
|
127
|
+
DefaultAvgTier: {
|
|
128
|
+
amount: string;
|
|
129
|
+
denom: string;
|
|
130
|
+
};
|
|
131
|
+
DefaultHighTier: {
|
|
132
|
+
amount: string;
|
|
133
|
+
denom: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/** Gas offset factor used for adjusting live gas prices */
|
|
137
|
+
static readonly gasOffsetFactor: number;
|
|
138
|
+
/** Address of the fee collector account that receives transaction fees */
|
|
139
|
+
static readonly feeCollectorAddress: "cheqd13pxn9n3qw79e03844rdadagmg0nshmwfszqu0g";
|
|
140
|
+
/** Address of the fee market module account */
|
|
141
|
+
static readonly moduleAccountAddress: "cheqd1el68mjnzv87uurqks8u29tec0cj3297047g2dl";
|
|
142
|
+
/** Querier extension setup function for fee market operations */
|
|
143
|
+
static readonly querierExtensionSetup: QueryExtensionSetup<FeemarketExtension>;
|
|
144
|
+
/** Querier instance with fee market extension capabilities */
|
|
145
|
+
/** Querier instance with fee market extension capabilities */
|
|
146
|
+
querier: CheqdQuerier & FeemarketExtension;
|
|
147
|
+
/**
|
|
148
|
+
* Constructs a new fee market module instance.
|
|
149
|
+
*
|
|
150
|
+
* @param signer - Signing client for blockchain transactions
|
|
151
|
+
* @param querier - Querier client with fee market extension for data retrieval
|
|
152
|
+
*/
|
|
153
|
+
constructor(signer: CheqdSigningStargateClient, querier: CheqdQuerier & FeemarketExtension);
|
|
154
|
+
/**
|
|
155
|
+
* Gets the registry types for fee market message encoding/decoding.
|
|
156
|
+
*
|
|
157
|
+
* @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
|
|
158
|
+
*/
|
|
159
|
+
getRegistryTypes(): Iterable<[string, GeneratedType]>;
|
|
160
|
+
/**
|
|
161
|
+
* Gets the querier extension setup for fee market operations.
|
|
162
|
+
*
|
|
163
|
+
* @returns Query extension setup function for fee market functionality
|
|
164
|
+
*/
|
|
165
|
+
getQuerierExtensionSetup(): QueryExtensionSetup<FeemarketExtension>;
|
|
166
|
+
/**
|
|
167
|
+
* Queries the current gas price for a specific denomination.
|
|
168
|
+
* Retrieves live gas price data from the fee market module.
|
|
169
|
+
*
|
|
170
|
+
* @param denom - Token denomination to query gas price for
|
|
171
|
+
* @param context - Optional SDK context for accessing clients
|
|
172
|
+
* @returns Promise resolving to the gas price response
|
|
173
|
+
*/
|
|
174
|
+
queryGasPrice(denom: string, context?: IContext): Promise<GasPriceResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Queries all available gas prices from the fee market.
|
|
177
|
+
* Retrieves comprehensive gas pricing information for all denominations.
|
|
178
|
+
*
|
|
179
|
+
* @param context - Optional SDK context for accessing clients
|
|
180
|
+
* @returns Promise resolving to the gas prices response
|
|
181
|
+
*/
|
|
182
|
+
queryGasPrices(context?: IContext): Promise<GasPricesResponse>;
|
|
183
|
+
/**
|
|
184
|
+
* Queries the fee market module parameters.
|
|
185
|
+
* Retrieves configuration settings for the fee market functionality.
|
|
186
|
+
*
|
|
187
|
+
* @param context - Optional SDK context for accessing clients
|
|
188
|
+
* @returns Promise resolving to the parameters response
|
|
189
|
+
*/
|
|
190
|
+
queryParams(context?: IContext): Promise<ParamsResponse>;
|
|
191
|
+
/**
|
|
192
|
+
* Generates gas price for a denomination by live polling the fee market.
|
|
193
|
+
* Queries current gas prices and adjusts them using the gas offset factor.
|
|
194
|
+
* Throws an error if live polling fails.
|
|
195
|
+
*
|
|
196
|
+
* @param denom - Token denomination to generate gas price for
|
|
197
|
+
* @param context - Optional SDK context for accessing clients
|
|
198
|
+
* @returns Promise resolving to the calculated gas price
|
|
199
|
+
* @throws Error if live poll for gas price fails or returns invalid data
|
|
200
|
+
*/
|
|
201
|
+
generateGasPrice(denom: string, context?: IContext): Promise<GasPrice>;
|
|
202
|
+
/**
|
|
203
|
+
* Generates offline gas price for a denomination using static tier pricing.
|
|
204
|
+
* Uses predefined gas prices as fallback when live polling is unavailable.
|
|
205
|
+
*
|
|
206
|
+
* @param denom - Token denomination to generate gas price for
|
|
207
|
+
* @param tier - Priority tier for gas price calculation (defaults to Low)
|
|
208
|
+
* @returns Promise resolving to the static gas price
|
|
209
|
+
* @throws Error if denomination or tier is invalid
|
|
210
|
+
*/
|
|
211
|
+
generateOfflineGasPrice(denom: string, tier?: DefaultGasPriceTiers): Promise<GasPrice>;
|
|
212
|
+
/**
|
|
213
|
+
* Generates safe gas price with automatic fallback to offline pricing.
|
|
214
|
+
* Attempts live polling first, falls back to static tier pricing if it fails.
|
|
215
|
+
*
|
|
216
|
+
* @param denom - Token denomination to generate gas price for
|
|
217
|
+
* @param tier - Priority tier for fallback gas price calculation (defaults to Low)
|
|
218
|
+
* @param context - Optional SDK context for accessing clients
|
|
219
|
+
* @returns Promise resolving to the gas price (live or fallback)
|
|
220
|
+
*/
|
|
221
|
+
generateSafeGasPrice(denom: string, tier?: DefaultGasPriceTiers, context?: IContext): Promise<GasPrice>;
|
|
222
|
+
/**
|
|
223
|
+
* Generates safe gas price with exponential backoff retry mechanism.
|
|
224
|
+
* Retries live polling with exponential backoff before falling back to offline pricing.
|
|
225
|
+
*
|
|
226
|
+
* @param denom - Token denomination to generate gas price for
|
|
227
|
+
* @param tier - Priority tier for fallback gas price calculation (defaults to Low)
|
|
228
|
+
* @param backoffOptions - Retry configuration options (defaults to DefaultBackoffOptions)
|
|
229
|
+
* @param context - Optional SDK context for accessing clients
|
|
230
|
+
* @returns Promise resolving to the gas price (live with retries or fallback)
|
|
231
|
+
*/
|
|
232
|
+
generateSafeGasPriceWithExponentialBackoff(denom: string, tier?: DefaultGasPriceTiers, backoffOptions?: Partial<import("exponential-backoff").IBackOffOptions>, context?: IContext): Promise<GasPrice>;
|
|
233
|
+
/**
|
|
234
|
+
* Generates transaction fees from a given gas price.
|
|
235
|
+
* Calculates the total fee amount based on gas price and gas limit.
|
|
236
|
+
*
|
|
237
|
+
* @param gasPrice - Gas price to use for fee calculation
|
|
238
|
+
* @param payer - Address of the account paying the transaction fees
|
|
239
|
+
* @param gas - Gas limit for the transaction (defaults to '200000')
|
|
240
|
+
* @returns Standard fee configuration for the transaction
|
|
241
|
+
*/
|
|
242
|
+
static generateFeesFromGasPrice(gasPrice: GasPrice, payer: string, gas?: string): DidStdFee;
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=feemarket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feemarket.d.ts","sourceRoot":"","sources":["../../../../../cjs/src/modules/feemarket.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EAGd,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAA2B,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,KAAK,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAIvD,oEAAoE;AACpE,eAAO,MAAM,4BAA4B,EAAG,WAAoB,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC5B,sCAAsC;;IAEtC,uCAAuC;;IAEvC,uCAAuC;;CAE9B,CAAC;AAEX,6CAA6C;AAC7C,eAAO,MAAM,uBAAuB,4CAAsE,CAAC;AAC3G,8CAA8C;AAC9C,eAAO,MAAM,wBAAwB,6CAAuE,CAAC;AAC7G,2CAA2C;AAC3C,eAAO,MAAM,qBAAqB,0CAAoE,CAAC;AAEvG;;;GAGG;AACH,eAAO,MAAM,oBAAoB;IAChC,+CAA+C;;IAE/C,qDAAqD;;IAErD,iDAAiD;;CAExC,CAAC;AAEX,8DAA8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;IACG,cAAc,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAMpE;;;;;;OAMG;IACG,WAAW,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;IAM9D;;;;;;;;;OASG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkB5E;;;;;;;;OAQG;IACG,uBAAuB,CAC5B,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,oBAA+C,GACnD,OAAO,CAAC,QAAQ,CAAC;IAepB;;;;;;;;OAQG;IACG,oBAAoB,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,oBAA+C,EACrD,OAAO,CAAC,EAAE,QAAQ,GAChB,OAAO,CAAC,QAAQ,CAAC;IAYpB;;;;;;;;;OASG;IACG,0CAA0C,CAC/C,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,oBAA+C,EACrD,cAAc,yDAAwB,EACtC,OAAO,CAAC,EAAE,QAAQ,GAChB,OAAO,CAAC,QAAQ,CAAC;IAapB;;;;;;;;OAQG;IACH,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,SAAS;CAO7F"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { GasPriceResponse, GasPricesResponse, ParamsResponse, QueryClientImpl, protobufPackage, } from '@cheqd/ts-proto-cjs/feemarket/feemarket/v1/index.js';
|
|
2
|
+
import { createProtobufRpcClient, GasPrice } from '@cosmjs/stargate-cjs';
|
|
3
|
+
import { AbstractCheqdSDKModule } from './_';
|
|
4
|
+
import { DefaultBackoffOptions, retry } from '../utils';
|
|
5
|
+
import { Decimal, Uint32 } from '@cosmjs/math-cjs';
|
|
6
|
+
/** Default extension key for fee market-related query operations */
|
|
7
|
+
export const defaultFeemarketExtensionKey = 'feemarket';
|
|
8
|
+
/**
|
|
9
|
+
* Protobuf message type literals for fee market operations.
|
|
10
|
+
* Used for consistent message type identification across the module.
|
|
11
|
+
*/
|
|
12
|
+
export const protobufLiterals = {
|
|
13
|
+
/** Gas price response message type */
|
|
14
|
+
GasPriceResponse: 'GasPriceResponse',
|
|
15
|
+
/** Gas prices response message type */
|
|
16
|
+
GasPricesResponse: 'GasPricesResponse',
|
|
17
|
+
/** Parameters response message type */
|
|
18
|
+
ParamsResponse: 'ParamsResponse',
|
|
19
|
+
};
|
|
20
|
+
/** Type URL for GasPriceResponse messages */
|
|
21
|
+
export const typeUrlGasPriceResponse = `/${protobufPackage}.${protobufLiterals.GasPriceResponse}`;
|
|
22
|
+
/** Type URL for GasPricesResponse messages */
|
|
23
|
+
export const typeUrlGasPricesResponse = `/${protobufPackage}.${protobufLiterals.GasPricesResponse}`;
|
|
24
|
+
/** Type URL for ParamsResponse messages */
|
|
25
|
+
export const typeUrlParamsResponse = `/${protobufPackage}.${protobufLiterals.ParamsResponse}`;
|
|
26
|
+
/**
|
|
27
|
+
* Default gas price tier names for fee calculation.
|
|
28
|
+
* Provides predefined tiers for different transaction priority levels.
|
|
29
|
+
*/
|
|
30
|
+
export const defaultGasPriceTiers = {
|
|
31
|
+
/** Low priority tier with lowest gas prices */
|
|
32
|
+
Low: 'DefaultLowTier',
|
|
33
|
+
/** Average priority tier with moderate gas prices */
|
|
34
|
+
Avg: 'DefaultAvgTier',
|
|
35
|
+
/** High priority tier with highest gas prices */
|
|
36
|
+
High: 'DefaultHighTier',
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Type guard function to check if an object is a GasPriceEncodeObject.
|
|
40
|
+
*
|
|
41
|
+
* @param obj - EncodeObject to check
|
|
42
|
+
* @returns True if the object is a GasPriceEncodeObject
|
|
43
|
+
*/
|
|
44
|
+
export function isGasPriceEncodeObject(obj) {
|
|
45
|
+
return obj.typeUrl === typeUrlGasPriceResponse;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type guard function to check if an object is a GasPricesEncodeObject.
|
|
49
|
+
*
|
|
50
|
+
* @param obj - EncodeObject to check
|
|
51
|
+
* @returns True if the object is a GasPricesEncodeObject
|
|
52
|
+
*/
|
|
53
|
+
export function isGasPricesEncodeObject(obj) {
|
|
54
|
+
return obj.typeUrl === typeUrlGasPricesResponse;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Type guard function to check if an object is a ParamsEncodeObject.
|
|
58
|
+
*
|
|
59
|
+
* @param obj - EncodeObject to check
|
|
60
|
+
* @returns True if the object is a ParamsEncodeObject
|
|
61
|
+
*/
|
|
62
|
+
export function isParamsEncodeObject(obj) {
|
|
63
|
+
return obj.typeUrl === typeUrlParamsResponse;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sets up the fee market extension for the querier client.
|
|
67
|
+
* Creates and configures the fee market-specific query methods.
|
|
68
|
+
*
|
|
69
|
+
* @param base - Base QueryClient to extend
|
|
70
|
+
* @returns Configured fee market extension with query methods
|
|
71
|
+
*/
|
|
72
|
+
export const setupFeemarketExtension = (base) => {
|
|
73
|
+
const rpc = createProtobufRpcClient(base);
|
|
74
|
+
const queryService = new QueryClientImpl(rpc);
|
|
75
|
+
return {
|
|
76
|
+
[defaultFeemarketExtensionKey]: {
|
|
77
|
+
gasPrice: async (denom) => {
|
|
78
|
+
return queryService.GasPrice({ denom });
|
|
79
|
+
},
|
|
80
|
+
gasPrices: async () => {
|
|
81
|
+
return queryService.GasPrices({});
|
|
82
|
+
},
|
|
83
|
+
params: async () => {
|
|
84
|
+
return queryService.Params({});
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Fee Market Module class providing comprehensive fee market functionality.
|
|
91
|
+
* Handles gas price queries, dynamic fee calculation, and fee market parameter management.
|
|
92
|
+
*/
|
|
93
|
+
export class FeemarketModule extends AbstractCheqdSDKModule {
|
|
94
|
+
//@ts-expect-error underlying type `GeneratedType` is intentionally wider
|
|
95
|
+
static registryTypes = [
|
|
96
|
+
[typeUrlGasPriceResponse, GasPriceResponse],
|
|
97
|
+
[typeUrlGasPricesResponse, GasPricesResponse],
|
|
98
|
+
[typeUrlParamsResponse, ParamsResponse],
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* Default gas prices for different priority tiers.
|
|
102
|
+
* Used as fallback when live gas price queries are unavailable.
|
|
103
|
+
*/
|
|
104
|
+
static defaultGasPrices = {
|
|
105
|
+
[defaultGasPriceTiers.Low]: { amount: '5000', denom: 'ncheq' },
|
|
106
|
+
[defaultGasPriceTiers.Avg]: { amount: '7500', denom: 'ncheq' },
|
|
107
|
+
[defaultGasPriceTiers.High]: { amount: '10000', denom: 'ncheq' },
|
|
108
|
+
};
|
|
109
|
+
/** Gas offset factor used for adjusting live gas prices */
|
|
110
|
+
static gasOffsetFactor = 10 ** 4;
|
|
111
|
+
/** Address of the fee collector account that receives transaction fees */
|
|
112
|
+
static feeCollectorAddress = 'cheqd13pxn9n3qw79e03844rdadagmg0nshmwfszqu0g';
|
|
113
|
+
/** Address of the fee market module account */
|
|
114
|
+
static moduleAccountAddress = 'cheqd1el68mjnzv87uurqks8u29tec0cj3297047g2dl';
|
|
115
|
+
/** Querier extension setup function for fee market operations */
|
|
116
|
+
static querierExtensionSetup = setupFeemarketExtension;
|
|
117
|
+
/** Querier instance with fee market extension capabilities */
|
|
118
|
+
/** Querier instance with fee market extension capabilities */
|
|
119
|
+
querier;
|
|
120
|
+
/**
|
|
121
|
+
* Constructs a new fee market module instance.
|
|
122
|
+
*
|
|
123
|
+
* @param signer - Signing client for blockchain transactions
|
|
124
|
+
* @param querier - Querier client with fee market extension for data retrieval
|
|
125
|
+
*/
|
|
126
|
+
constructor(signer, querier) {
|
|
127
|
+
super(signer, querier);
|
|
128
|
+
this.querier = querier;
|
|
129
|
+
this.methods = {
|
|
130
|
+
queryGasPrice: this.queryGasPrice.bind(this),
|
|
131
|
+
queryGasPrices: this.queryGasPrices.bind(this),
|
|
132
|
+
queryParams: this.queryParams.bind(this),
|
|
133
|
+
generateGasPrice: this.generateGasPrice.bind(this),
|
|
134
|
+
generateOfflineGasPrice: this.generateOfflineGasPrice.bind(this),
|
|
135
|
+
generateSafeGasPrice: this.generateSafeGasPrice.bind(this),
|
|
136
|
+
generateSafeGasPriceWithExponentialBackoff: this.generateSafeGasPriceWithExponentialBackoff.bind(this),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets the registry types for fee market message encoding/decoding.
|
|
141
|
+
*
|
|
142
|
+
* @returns Iterable of [typeUrl, GeneratedType] pairs for the registry
|
|
143
|
+
*/
|
|
144
|
+
getRegistryTypes() {
|
|
145
|
+
return FeemarketModule.registryTypes;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets the querier extension setup for fee market operations.
|
|
149
|
+
*
|
|
150
|
+
* @returns Query extension setup function for fee market functionality
|
|
151
|
+
*/
|
|
152
|
+
getQuerierExtensionSetup() {
|
|
153
|
+
return FeemarketModule.querierExtensionSetup;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Queries the current gas price for a specific denomination.
|
|
157
|
+
* Retrieves live gas price data from the fee market module.
|
|
158
|
+
*
|
|
159
|
+
* @param denom - Token denomination to query gas price for
|
|
160
|
+
* @param context - Optional SDK context for accessing clients
|
|
161
|
+
* @returns Promise resolving to the gas price response
|
|
162
|
+
*/
|
|
163
|
+
async queryGasPrice(denom, context) {
|
|
164
|
+
if (!this.querier)
|
|
165
|
+
this.querier = context.sdk.querier;
|
|
166
|
+
return this.querier[defaultFeemarketExtensionKey].gasPrice(denom);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Queries all available gas prices from the fee market.
|
|
170
|
+
* Retrieves comprehensive gas pricing information for all denominations.
|
|
171
|
+
*
|
|
172
|
+
* @param context - Optional SDK context for accessing clients
|
|
173
|
+
* @returns Promise resolving to the gas prices response
|
|
174
|
+
*/
|
|
175
|
+
async queryGasPrices(context) {
|
|
176
|
+
if (!this.querier)
|
|
177
|
+
this.querier = context.sdk.querier;
|
|
178
|
+
return this.querier[defaultFeemarketExtensionKey].gasPrices();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Queries the fee market module parameters.
|
|
182
|
+
* Retrieves configuration settings for the fee market functionality.
|
|
183
|
+
*
|
|
184
|
+
* @param context - Optional SDK context for accessing clients
|
|
185
|
+
* @returns Promise resolving to the parameters response
|
|
186
|
+
*/
|
|
187
|
+
async queryParams(context) {
|
|
188
|
+
if (!this.querier)
|
|
189
|
+
this.querier = context.sdk.querier;
|
|
190
|
+
return this.querier[defaultFeemarketExtensionKey].params();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Generates gas price for a denomination by live polling the fee market.
|
|
194
|
+
* Queries current gas prices and adjusts them using the gas offset factor.
|
|
195
|
+
* Throws an error if live polling fails.
|
|
196
|
+
*
|
|
197
|
+
* @param denom - Token denomination to generate gas price for
|
|
198
|
+
* @param context - Optional SDK context for accessing clients
|
|
199
|
+
* @returns Promise resolving to the calculated gas price
|
|
200
|
+
* @throws Error if live poll for gas price fails or returns invalid data
|
|
201
|
+
*/
|
|
202
|
+
async generateGasPrice(denom, context) {
|
|
203
|
+
if (!this.querier)
|
|
204
|
+
this.querier = context.sdk.querier;
|
|
205
|
+
// query gas price, bubble up error, no catch
|
|
206
|
+
const gasPrice = await this.queryGasPrice(denom, context);
|
|
207
|
+
// validate gas price
|
|
208
|
+
if (!gasPrice.price)
|
|
209
|
+
throw new Error('Invalid gas price: live poll for gas price failed');
|
|
210
|
+
// convert gas price through offset factor
|
|
211
|
+
const adjustedGasPrice = Decimal.fromAtomics(gasPrice.price.amount, 18)
|
|
212
|
+
.multiply(Uint32.fromString(FeemarketModule.gasOffsetFactor.toString()))
|
|
213
|
+
.toString();
|
|
214
|
+
// safe convert gas price to string
|
|
215
|
+
return GasPrice.fromString(`${adjustedGasPrice}${gasPrice.price.denom}`);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Generates offline gas price for a denomination using static tier pricing.
|
|
219
|
+
* Uses predefined gas prices as fallback when live polling is unavailable.
|
|
220
|
+
*
|
|
221
|
+
* @param denom - Token denomination to generate gas price for
|
|
222
|
+
* @param tier - Priority tier for gas price calculation (defaults to Low)
|
|
223
|
+
* @returns Promise resolving to the static gas price
|
|
224
|
+
* @throws Error if denomination or tier is invalid
|
|
225
|
+
*/
|
|
226
|
+
async generateOfflineGasPrice(denom, tier = defaultGasPriceTiers.Low) {
|
|
227
|
+
// validate denom against default
|
|
228
|
+
if (!Object.values(FeemarketModule.defaultGasPrices).some((gp) => gp.denom === denom))
|
|
229
|
+
throw new Error(`Invalid denom: ${denom}`);
|
|
230
|
+
// validate tier against default
|
|
231
|
+
if (!Object.keys(FeemarketModule.defaultGasPrices).includes(tier))
|
|
232
|
+
throw new Error(`Invalid tier: ${tier}`);
|
|
233
|
+
// generate gas price
|
|
234
|
+
const gasPrice = FeemarketModule.defaultGasPrices[tier];
|
|
235
|
+
// safe convert gas price to string
|
|
236
|
+
return GasPrice.fromString(`${gasPrice.amount}${gasPrice.denom}`);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Generates safe gas price with automatic fallback to offline pricing.
|
|
240
|
+
* Attempts live polling first, falls back to static tier pricing if it fails.
|
|
241
|
+
*
|
|
242
|
+
* @param denom - Token denomination to generate gas price for
|
|
243
|
+
* @param tier - Priority tier for fallback gas price calculation (defaults to Low)
|
|
244
|
+
* @param context - Optional SDK context for accessing clients
|
|
245
|
+
* @returns Promise resolving to the gas price (live or fallback)
|
|
246
|
+
*/
|
|
247
|
+
async generateSafeGasPrice(denom, tier = defaultGasPriceTiers.Low, context) {
|
|
248
|
+
if (!this.querier)
|
|
249
|
+
this.querier = context.sdk.querier;
|
|
250
|
+
try {
|
|
251
|
+
// generate gas price
|
|
252
|
+
return await this.generateGasPrice(denom, context);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
// generate offline gas price
|
|
256
|
+
return await this.generateOfflineGasPrice(denom, tier);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Generates safe gas price with exponential backoff retry mechanism.
|
|
261
|
+
* Retries live polling with exponential backoff before falling back to offline pricing.
|
|
262
|
+
*
|
|
263
|
+
* @param denom - Token denomination to generate gas price for
|
|
264
|
+
* @param tier - Priority tier for fallback gas price calculation (defaults to Low)
|
|
265
|
+
* @param backoffOptions - Retry configuration options (defaults to DefaultBackoffOptions)
|
|
266
|
+
* @param context - Optional SDK context for accessing clients
|
|
267
|
+
* @returns Promise resolving to the gas price (live with retries or fallback)
|
|
268
|
+
*/
|
|
269
|
+
async generateSafeGasPriceWithExponentialBackoff(denom, tier = defaultGasPriceTiers.Low, backoffOptions = DefaultBackoffOptions, context) {
|
|
270
|
+
if (!this.querier)
|
|
271
|
+
this.querier = context.sdk.querier;
|
|
272
|
+
// live poll for gas price
|
|
273
|
+
const gasPrice = await retry(() => this.generateGasPrice(denom, context), backoffOptions);
|
|
274
|
+
// return, if applicable
|
|
275
|
+
if (gasPrice)
|
|
276
|
+
return gasPrice;
|
|
277
|
+
// otherwise, generate offline gas price
|
|
278
|
+
return await this.generateOfflineGasPrice(denom, tier);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Generates transaction fees from a given gas price.
|
|
282
|
+
* Calculates the total fee amount based on gas price and gas limit.
|
|
283
|
+
*
|
|
284
|
+
* @param gasPrice - Gas price to use for fee calculation
|
|
285
|
+
* @param payer - Address of the account paying the transaction fees
|
|
286
|
+
* @param gas - Gas limit for the transaction (defaults to '200000')
|
|
287
|
+
* @returns Standard fee configuration for the transaction
|
|
288
|
+
*/
|
|
289
|
+
static generateFeesFromGasPrice(gasPrice, payer, gas = '200000') {
|
|
290
|
+
return {
|
|
291
|
+
amount: [{ denom: gasPrice.denom, amount: gasPrice.amount.multiply(Uint32.fromString(gas)).toString() }],
|
|
292
|
+
gas,
|
|
293
|
+
payer,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=feemarket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feemarket.js","sourceRoot":"","sources":["../../../../../cjs/src/modules/feemarket.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,GACf,MAAM,qDAAqD,CAAC;AAE7D,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAe,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAmC,MAAM,KAAK,CAAC;AAI9E,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEnD,oEAAoE;AACpE,MAAM,CAAC,MAAM,4BAA4B,GAAG,WAAoB,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,sCAAsC;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,uCAAuC;IACvC,iBAAiB,EAAE,mBAAmB;IACtC,uCAAuC;IACvC,cAAc,EAAE,gBAAgB;CACvB,CAAC;AAEX,6CAA6C;AAC7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,eAAe,IAAI,gBAAgB,CAAC,gBAAgB,EAAW,CAAC;AAC3G,8CAA8C;AAC9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,eAAe,IAAI,gBAAgB,CAAC,iBAAiB,EAAW,CAAC;AAC7G,2CAA2C;AAC3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,eAAe,IAAI,gBAAgB,CAAC,cAAc,EAAW,CAAC;AAEvG;;;GAGG;AACH,MA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