Skip to content

Commit

Permalink
refactor(core)!: deprecate the default gasPrice on SigningArchwayClie…
Browse files Browse the repository at this point in the history
…nt (#86)

**BREAKING CHANGE:** modified the response of `getEstimateTxFees` to
change the `estimatedFee` type from `Coin[]` to `StdFee` and moved the
`gasLimit` into `estimatedFee.gas`.
  • Loading branch information
aelesbao authored May 26, 2023
1 parent 2b57a4d commit b1c72cf
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 101 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = {
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editorconfig": true,
"arrowParens": "avoid",
"printWidth": 120
}
6 changes: 6 additions & 0 deletions .yarn/versions/4d4c6e79.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
releases:
"@archwayhq/arch3-core": minor
"@archwayhq/arch3.js": minor

declined:
- "@archwayhq/arch3-proto"
20 changes: 20 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### New feature

#### **arch3-core**

- method to `calculateFees` for multiple messages on `SigningArchwayClient` (#86)

### Changes

#### **arch3-core**

- deprecated the default `gasPrice` option on `SigningArchwayClient` (#86)

### BREAKING CHANGES

- modified the response of `ArchwayCLient.getEstimateTxFees` to change the
`estimatedFee` type from `Coin[]` to `StdFee` and moved the `gasLimit`
into `estimatedFee.gas`

## v0.2.0 (2023-05-17)

### New feature
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@microsoft/eslint-formatter-sarif": "^3.0",
"@types/jest": "^29.5.1",
"@types/node": "^18.15.13",
"@types/prettier": "^2",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@yarnpkg/sdks": "^2.7.0",
Expand All @@ -105,6 +106,8 @@
"jest": "^29.5.0",
"lint-staged": "^13.2.1",
"pinst": "^3.0.0",
"prettier": "^2.8.8",
"prettier-eslint": "^15.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/arch3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@microsoft/eslint-formatter-sarif": "^3.0",
"@types/jest": "^29.5.1",
"@types/node": "^18.15.13",
"@types/prettier": "^2",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"dotenv": "^16.0.3",
Expand All @@ -78,6 +79,8 @@
"eslint-plugin-jsdoc": "^43.1.1",
"eslint-plugin-node": "^11.1.0",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"prettier-eslint": "^15.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
Expand Down
19 changes: 13 additions & 6 deletions packages/arch3-core/src/archwayclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ describe('ArchwayClient', () => {
const client = await ArchwayClient.connect(archwayd.endpoint);
const response = await client.getEstimateTxFees();

expect(response.gasLimit).toBeUndefined();
expect(response.gasUnitPrice).toMatchObject({
denom: archwayd.denom,
amount: expect.any(Decimal),
});
expect(response.contractAddress).toBeUndefined();
expect(response.estimatedFee).toHaveLength(0);
expect(response.estimatedFee).toMatchObject({
gas: '1',
amount: expect.objectContaining([{
denom: archwayd.denom,
amount: expect.stringMatching(/^\d+$/),
}])
});

client.disconnect();
});
Expand All @@ -70,15 +75,17 @@ describe('ArchwayClient', () => {
const client = await ArchwayClient.connect(archwayd.endpoint);
const response = await client.getEstimateTxFees(1, contractAddress);

expect(response.gasLimit).toBe(1);
expect(response.gasUnitPrice).toMatchObject({
denom: archwayd.denom,
amount: expect.any(Decimal),
});
expect(response.contractAddress).toBe(contractAddress);
expect(response.estimatedFee).toContainEqual({
denom: archwayd.denom,
amount: expect.stringMatching(/^\d+$/),
expect(response.estimatedFee).toMatchObject({
gas: '1',
amount: expect.objectContaining([{
denom: archwayd.denom,
amount: expect.stringMatching(/^\d+$/),
}])
});

client.disconnect();
Expand Down
1 change: 1 addition & 0 deletions packages/arch3-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {
SetContractMetadataResult,
SetContractPremiumResult,
SigningArchwayClient,
SigningArchwayClientOptions,
TxResult,
WithdrawContractRewardsResult,
} from './signingarchwayclient';
Expand Down
16 changes: 9 additions & 7 deletions packages/arch3-core/src/queryclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,27 @@ class ArchwayQueryClientImpl implements IArchwayQueryClient {
}
}

public async getEstimateTxFees(gasLimit?: number, contractAddress?: string): Promise<EstimateTxFees> {
public async getEstimateTxFees(gasLimit: number = 1, contractAddress?: string): Promise<EstimateTxFees> {
const client = this.forceGetQueryClient();
const {
estimatedFee,
gasUnitPrice: { amount: gasAmount, denom: gasDenom }
} = await client.rewards.estimateTxFees(gasLimit ?? 0, contractAddress ?? '');
gasUnitPrice: { amount: gasPriceAmount, denom: gasPriceDenom }
} = await client.rewards.estimateTxFees(gasLimit, contractAddress ?? '');

// The RPC queries do not include the decimal precision fot types.Dec,
// so we need to manually decode the gas amount from the proto, as suggested in
// https://github.com/osmosis-labs/telescope/issues/247#issuecomment-1292407464
// See also: https://github.com/cosmos/cosmos-sdk/issues/10863
const gasUnitPriceAmount = decodeCosmosSdkDecFromProto(gasAmount);
const gasUnitPrice = new GasPrice(gasUnitPriceAmount, gasDenom);
const gasUnitPriceAmount = decodeCosmosSdkDecFromProto(gasPriceAmount);
const gasUnitPrice = new GasPrice(gasUnitPriceAmount, gasPriceDenom);

return {
gasLimit,
contractAddress,
estimatedFee,
gasUnitPrice,
estimatedFee: {
amount: estimatedFee,
gas: gasLimit.toString(),
}
};
}

Expand Down
22 changes: 8 additions & 14 deletions packages/arch3-core/src/signingarchwayclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ async function getWalletWithAccounts(): Promise<[DirectSecp256k1HdWallet, readon

const flatFee = coin(1000, archwayd.denom);

const defaultSigningClientOptions: SigningCosmWasmClientOptions = {
const clientOptions: SigningCosmWasmClientOptions = {
broadcastPollIntervalMs: 200,
broadcastTimeoutMs: 8_000,
gasPrice: GasPrice.fromString(`900${archwayd.denom}`),
};

async function assertGasPriceEstimation(
Expand All @@ -63,7 +62,7 @@ describe('SigningArchwayClient', () => {
describe('connectWithSigner', () => {
it('can be constructed', async () => {
const wallet = await DirectSecp256k1HdWallet.generate(12, { prefix: archwayd.prefix });
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);
expect(client).toBeDefined();
client.disconnect();
});
Expand All @@ -72,18 +71,13 @@ describe('SigningArchwayClient', () => {
describe('offline', () => {
it('can be constructed', async () => {
const wallet = await DirectSecp256k1HdWallet.generate(12, { prefix: archwayd.prefix });
const client = await SigningArchwayClient.offline(wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.offline(wallet, clientOptions);
expect(client).toBeDefined();
client.disconnect();
});
});

describe('minimum gas fee estimation', () => {
const clientOptions: SigningCosmWasmClientOptions = {
broadcastPollIntervalMs: 200,
broadcastTimeoutMs: 8_000,
};

it('works for base transactions', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);
Expand Down Expand Up @@ -231,7 +225,7 @@ describe('SigningArchwayClient', () => {
describe('contract metadata', () => {
it('sets both owner and rewards', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

const contractAddress = contracts.voter.addresses[1];
const ownerAddress = accounts[1].address;
Expand Down Expand Up @@ -259,7 +253,7 @@ describe('SigningArchwayClient', () => {

it('do not modify the metadata when both owner and rewards are empty', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

const contractAddress = contracts.voter.addresses[1];
const ownerAddress = accounts[1].address;
Expand Down Expand Up @@ -288,7 +282,7 @@ describe('SigningArchwayClient', () => {
describe('contract premium', () => {
it('sets the contract premium', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

const ownerAddress = accounts[1].address;
const contractAddress = contracts.voter.addresses[1];
Expand Down Expand Up @@ -318,7 +312,7 @@ describe('SigningArchwayClient', () => {

it('disables the contract premium', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

const contractAddress = contracts.voter.addresses[2];
const ownerAddress = accounts[2].address;
Expand Down Expand Up @@ -350,7 +344,7 @@ describe('SigningArchwayClient', () => {
describe('withdraw', () => {
it('withdraws rewards by limit', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, defaultSigningClientOptions);
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

const contractAddress = contracts.voter.addresses[3];
const rewardsAddress = accounts[3].address;
Expand Down
Loading

0 comments on commit b1c72cf

Please sign in to comment.