Add support for using auto fee calculation #22

Merged
nabarun merged 19 commits from deep-stack/registry-sdk:iv-add-tx-info-test into main 2024-09-06 09:07:58 +00:00
3 changed files with 32 additions and 30 deletions
Showing only changes of commit fa64e725c0 - Show all commits

View File

@ -1 +1,4 @@
export const DENOM = 'alnt';
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
export const DEFAULT_GAS_ESTIMATION_MULTIPLIER = 1.5;

View File

@ -31,8 +31,7 @@ import { Coin } from './proto/cosmos/base/v1beta1/coin';
import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx';
import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx';
import { MsgSendResponse } from './proto/cosmos/bank/v1beta1/tx';
export const DEFAULT_CHAIN_ID = 'laconic_9000-1';
import { DEFAULT_CHAIN_ID, DEFAULT_GAS_ESTIMATION_MULTIPLIER } from './constants';
/**
* Create an auction bid.
@ -132,7 +131,7 @@ export class Registry {
async setRecord (
{ privateKey, record, bondId }: { privateKey: string, record: any, bondId: string },
transactionPrivateKey: string,
fee: StdFee
fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER
) {
const account = new Account(Buffer.from(transactionPrivateKey, 'hex'));
await account.init();
@ -147,7 +146,7 @@ export class Registry {
/**
* Send coins.
*/
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee) {
async sendCoins ({ amount, denom, destinationAddress }: MessageMsgSendCoins, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -209,7 +208,7 @@ export class Registry {
/**
* Create bond.
*/
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee): Promise<MsgCreateBondResponse> {
async createBond ({ denom, amount }: MessageMsgCreateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCreateBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -225,7 +224,7 @@ export class Registry {
/**
* Refill bond.
*/
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee): Promise<MsgRefillBondResponse> {
async refillBond ({ denom, amount, id }: MessageMsgRefillBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgRefillBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -242,7 +241,7 @@ export class Registry {
/**
* Withdraw (from) bond.
*/
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee): Promise<MsgWithdrawBondResponse> {
async withdrawBond ({ denom, amount, id }: MessageMsgWithdrawBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgWithdrawBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -259,7 +258,7 @@ export class Registry {
/**
* Cancel bond.
*/
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee): Promise<MsgCancelBondResponse> {
async cancelBond ({ id }: MessageMsgCancelBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgCancelBondResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -274,7 +273,7 @@ export class Registry {
/**
* Associate record with bond.
*/
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee) {
async associateBond ({ bondId, recordId }: MessageMsgAssociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -290,7 +289,7 @@ export class Registry {
/**
* Dissociate record from bond.
*/
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee) {
async dissociateBond ({ recordId }: MessageMsgDissociateBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -305,7 +304,7 @@ export class Registry {
/**
* Dissociate all records from bond.
*/
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee) {
async dissociateRecords ({ bondId }: MessageMsgDissociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -320,7 +319,7 @@ export class Registry {
/**
* Reassociate records (switch bond).
*/
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee) {
async reassociateRecords ({ newBondId, oldBondId }: MessageMsgReAssociateRecords, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -336,7 +335,7 @@ export class Registry {
/**
* Reserve authority.
*/
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee) {
async reserveAuthority ({ name, owner }: { name: string, owner?: string }, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -352,7 +351,7 @@ export class Registry {
/**
* Set authority bond.
*/
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee) {
async setAuthorityBond ({ bondId, name }: MessageMsgSetAuthorityBond, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -368,7 +367,7 @@ export class Registry {
/**
* Commit auction bid.
*/
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee) {
async commitBid ({ auctionId, commitHash }: MessageMsgCommitBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -384,7 +383,7 @@ export class Registry {
/**
* Reveal auction bid.
*/
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee) {
async revealBid ({ auctionId, reveal }: MessageMsgRevealBid, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -420,7 +419,7 @@ export class Registry {
/**
* Set name (LRN) to record ID (CID).
*/
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee) {
async setName ({ cid, lrn }: MessageMsgSetName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -443,7 +442,7 @@ export class Registry {
/**
* Delete name (LRN) mapping.
*/
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee) {
async deleteName ({ lrn }: MessageMsgDeleteName, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER) {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -454,20 +453,10 @@ export class Registry {
);
}
async getLaconicClient (account: Account) {
return LaconicClient.connectWithSigner(
this._endpoints.rpc,
account.wallet,
{
gasPrice: this._gasPrice
}
);
}
/**
* Onboard participant.
*/
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise<MsgOnboardParticipantResponse> {
async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee | number = DEFAULT_GAS_ESTIMATION_MULTIPLIER): Promise<MsgOnboardParticipantResponse> {
const account = new Account(Buffer.from(privateKey, 'hex'));
await account.init();
const laconicClient = await this.getLaconicClient(account);
@ -502,9 +491,18 @@ export class Registry {
async getParticipantByNitroAddress (nitroAddress: string) {
return this._client.getParticipantByNitroAddress(nitroAddress);
}
async getLaconicClient (account: Account) {
return LaconicClient.connectWithSigner(
this._endpoints.rpc,
account.wallet,
{ gasPrice: this._gasPrice }
);
}
}
export { Account };
export { LaconicClient };
export * from './constants';
export * from './types/cerc/bond/message';
export * from './types/cerc/onboarding/message';

View File

@ -2,7 +2,8 @@ import assert from 'assert';
import yaml from 'node-yaml';
import semver from 'semver';
import { Account, DEFAULT_CHAIN_ID } from '../index';
import { Account } from '../index';
import { DEFAULT_CHAIN_ID } from '../constants';
export const ensureUpdatedConfig = async (path: string) => {
const conf = await yaml.read(path);