From a32fc3938cf8384d956081f6fdbc5548ded91f7a Mon Sep 17 00:00:00 2001 From: Angela Gilhotra Date: Fri, 22 Nov 2024 17:23:33 +0530 Subject: [PATCH 1/4] update default gas price to 0.001uxion --- apps/demo-app/src/app/layout.tsx | 2 +- .../abstraxion/src/components/AbstraxionContext/index.tsx | 2 +- packages/constants/src/index.ts | 8 ++++---- packages/signers/src/signers/utils/client.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/demo-app/src/app/layout.tsx b/apps/demo-app/src/app/layout.tsx index 3cae284..d98c720 100644 --- a/apps/demo-app/src/app/layout.tsx +++ b/apps/demo-app/src/app/layout.tsx @@ -33,7 +33,7 @@ const legacyConfig = { const treasuryConfig = { treasury: "xion1h82c0efsxxq4pgua754u6xepfu6avglup20fl834gc2ah0ptgn5s2zffe9", // Example XION treasury contract with /cosmwasm.wasm.v1.MsgExecuteContract grant - // gasPrice: "0uxion", // This defaults to "0uxion" on testnet and "0.025uxion" on mainnet. If you feel the need to change the gasPrice when connecting to signer, set this value. Please stick to the string format seen in example + // gasPrice: "0.001uxion", // If you feel the need to change the gasPrice when connecting to signer, set this value. Please stick to the string format seen in example // Optional params to activate mainnet config // rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443", // restUrl: "https://api.xion-mainnet-1.burnt.com:443", diff --git a/packages/abstraxion/src/components/AbstraxionContext/index.tsx b/packages/abstraxion/src/components/AbstraxionContext/index.tsx index 4679335..6811647 100644 --- a/packages/abstraxion/src/components/AbstraxionContext/index.tsx +++ b/packages/abstraxion/src/components/AbstraxionContext/index.tsx @@ -79,7 +79,7 @@ export function AbstraxionContextProvider({ if (rpcUrl.includes("mainnet")) { gasPriceDefault = GasPrice.fromString(gasPriceConstant); } else { - gasPriceDefault = GasPrice.fromString("0uxion"); + gasPriceDefault = GasPrice.fromString("0.001uxion"); } const configureInstance = useCallback(() => { diff --git a/packages/constants/src/index.ts b/packages/constants/src/index.ts index 8fb1c81..cf8d26c 100644 --- a/packages/constants/src/index.ts +++ b/packages/constants/src/index.ts @@ -42,14 +42,14 @@ export const xionCoin: Coin = { coinMinimalDenom: "uxion", coinDecimals: 6, gasPriceStep: { - low: 0.01, - average: 0.025, - high: 0.03, + low: 0.0005, + average: 0.001, + high: 0.01, }, }; export const xionGasValues = { - gasPrice: "0.025uxion", + gasPrice: "0.001uxion", gasAdjustment: 1.4, gasAdjustmentMargin: 5000, }; diff --git a/packages/signers/src/signers/utils/client.ts b/packages/signers/src/signers/utils/client.ts index c987cce..beeebc7 100644 --- a/packages/signers/src/signers/utils/client.ts +++ b/packages/signers/src/signers/utils/client.ts @@ -130,7 +130,7 @@ export class AAClient extends SigningCosmWasmClient { const chainId = await this.getChainId(); if (/testnet/.test(chainId)) { - defaultFee = { amount: [{ amount: "0", denom: "uxion" }], gas: gas }; + defaultFee = { amount: [{ amount: "0.001", denom: "uxion" }], gas: gas }; } else { defaultFee = { amount: calculatedFee.amount, gas: gas }; } From 5f5edf4cf38546b9f726af9b685ea1ce39444551 Mon Sep 17 00:00:00 2001 From: Justin <328965+justinbarry@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:05:31 -0800 Subject: [PATCH 2/4] Add changeset file for the gas price change (#240) --- .changeset/sixty-geckos-give.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/sixty-geckos-give.md diff --git a/.changeset/sixty-geckos-give.md b/.changeset/sixty-geckos-give.md new file mode 100644 index 0000000..f159f2f --- /dev/null +++ b/.changeset/sixty-geckos-give.md @@ -0,0 +1,6 @@ +--- +"demo-app": minor +"@burnt-labs/constants": minor +--- + +Update default gas price to 0.001uxion From c933eca9e21d84404edf82f3b4a05e36c4aae288 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:46:32 -0800 Subject: [PATCH 3/4] chore: update versions (alpha) (#241) Co-authored-by: burnt-daemon <146226939+burnt-daemon@users.noreply.github.com> --- .changeset/pre.json | 1 + apps/demo-app/CHANGELOG.md | 14 ++++++++++++++ apps/demo-app/package.json | 2 +- packages/abstraxion-core/CHANGELOG.md | 8 ++++++++ packages/abstraxion-core/package.json | 2 +- packages/abstraxion/CHANGELOG.md | 9 +++++++++ packages/abstraxion/package.json | 2 +- packages/constants/CHANGELOG.md | 6 ++++++ packages/constants/package.json | 2 +- 9 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.changeset/pre.json b/.changeset/pre.json index 43794d5..127d82e 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -65,6 +65,7 @@ "silly-seas-sip", "silver-plants-rule", "six-zebras-impress", + "sixty-geckos-give", "slimy-deers-hammer", "slow-kangaroos-glow", "smart-deers-cough", diff --git a/apps/demo-app/CHANGELOG.md b/apps/demo-app/CHANGELOG.md index a37e646..01b5ae2 100644 --- a/apps/demo-app/CHANGELOG.md +++ b/apps/demo-app/CHANGELOG.md @@ -1,5 +1,19 @@ # demo-app +## 1.1.0-alpha.38 + +### Minor Changes + +- [#240](https://github.com/burnt-labs/xion.js/pull/240) [`5f5edf4`](https://github.com/burnt-labs/xion.js/commit/5f5edf4cf38546b9f726af9b685ea1ce39444551) Thanks [@justinbarry](https://github.com/justinbarry)! - Update default gas price to 0.001uxion + +### Patch Changes + +- Updated dependencies [[`5f5edf4`](https://github.com/burnt-labs/xion.js/commit/5f5edf4cf38546b9f726af9b685ea1ce39444551)]: + - @burnt-labs/constants@0.1.0-alpha.14 + - @burnt-labs/abstraxion@1.0.0-alpha.53 + - @burnt-labs/abstraxion-core@1.0.0-alpha.48 + - @burnt-labs/signers@0.1.0-alpha.13 + ## 1.1.0-alpha.37 ### Patch Changes diff --git a/apps/demo-app/package.json b/apps/demo-app/package.json index a82abde..9b00e5b 100644 --- a/apps/demo-app/package.json +++ b/apps/demo-app/package.json @@ -1,6 +1,6 @@ { "name": "demo-app", - "version": "1.1.0-alpha.37", + "version": "1.1.0-alpha.38", "private": true, "scripts": { "dev": "next dev --port 3001", diff --git a/packages/abstraxion-core/CHANGELOG.md b/packages/abstraxion-core/CHANGELOG.md index 6575ffb..d81045e 100644 --- a/packages/abstraxion-core/CHANGELOG.md +++ b/packages/abstraxion-core/CHANGELOG.md @@ -1,5 +1,13 @@ # @burnt-labs/abstraxion-core +## 1.0.0-alpha.48 + +### Patch Changes + +- Updated dependencies [[`5f5edf4`](https://github.com/burnt-labs/xion.js/commit/5f5edf4cf38546b9f726af9b685ea1ce39444551)]: + - @burnt-labs/constants@0.1.0-alpha.14 + - @burnt-labs/signers@0.1.0-alpha.13 + ## 1.0.0-alpha.47 ### Minor Changes diff --git a/packages/abstraxion-core/package.json b/packages/abstraxion-core/package.json index 540df53..d44b2a6 100644 --- a/packages/abstraxion-core/package.json +++ b/packages/abstraxion-core/package.json @@ -1,6 +1,6 @@ { "name": "@burnt-labs/abstraxion-core", - "version": "1.0.0-alpha.47", + "version": "1.0.0-alpha.48", "sideEffects": [ "**/*.css" ], diff --git a/packages/abstraxion/CHANGELOG.md b/packages/abstraxion/CHANGELOG.md index a6f3cbf..f751101 100644 --- a/packages/abstraxion/CHANGELOG.md +++ b/packages/abstraxion/CHANGELOG.md @@ -1,5 +1,14 @@ # @burnt-labs/abstraxion +## 1.0.0-alpha.53 + +### Patch Changes + +- Updated dependencies [[`5f5edf4`](https://github.com/burnt-labs/xion.js/commit/5f5edf4cf38546b9f726af9b685ea1ce39444551)]: + - @burnt-labs/constants@0.1.0-alpha.14 + - @burnt-labs/abstraxion-core@1.0.0-alpha.48 + - @burnt-labs/signers@0.1.0-alpha.13 + ## 1.0.0-alpha.52 ### Minor Changes diff --git a/packages/abstraxion/package.json b/packages/abstraxion/package.json index f54707d..e973f3d 100644 --- a/packages/abstraxion/package.json +++ b/packages/abstraxion/package.json @@ -1,6 +1,6 @@ { "name": "@burnt-labs/abstraxion", - "version": "1.0.0-alpha.52", + "version": "1.0.0-alpha.53", "sideEffects": [ "**/*.css" ], diff --git a/packages/constants/CHANGELOG.md b/packages/constants/CHANGELOG.md index 321ace3..21a0ebc 100644 --- a/packages/constants/CHANGELOG.md +++ b/packages/constants/CHANGELOG.md @@ -1,5 +1,11 @@ # @burnt-labs/constants +## 0.1.0-alpha.14 + +### Minor Changes + +- [#240](https://github.com/burnt-labs/xion.js/pull/240) [`5f5edf4`](https://github.com/burnt-labs/xion.js/commit/5f5edf4cf38546b9f726af9b685ea1ce39444551) Thanks [@justinbarry](https://github.com/justinbarry)! - Update default gas price to 0.001uxion + ## 0.1.0-alpha.13 ### Patch Changes diff --git a/packages/constants/package.json b/packages/constants/package.json index 4e690ff..7e8bcd0 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -1,6 +1,6 @@ { "name": "@burnt-labs/constants", - "version": "0.1.0-alpha.13", + "version": "0.1.0-alpha.14", "module": "./dist/index.mjs", "main": "./dist/index.js", "types": "./dist/index.d.ts", From 6ca7dad417a01b4a2594cdf4f935966cab62d442 Mon Sep 17 00:00:00 2001 From: Burnt Val <117188229+BurntVal@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:39:29 -0500 Subject: [PATCH 4/4] override fee granter (#239) * override fee granter * changeset * remove comments --- .changeset/silly-worms-hear.md | 7 +++ apps/demo-app/src/app/layout.tsx | 4 +- .../abstraxion-core/src/AbstraxionAuth.ts | 1 + .../src/GranteeSignerClient.ts | 62 +++++++++++++++++-- .../src/hooks/useAbstraxionSigningClient.ts | 5 +- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 .changeset/silly-worms-hear.md diff --git a/.changeset/silly-worms-hear.md b/.changeset/silly-worms-hear.md new file mode 100644 index 0000000..a66aadf --- /dev/null +++ b/.changeset/silly-worms-hear.md @@ -0,0 +1,7 @@ +--- +"@burnt-labs/abstraxion-core": minor +"@burnt-labs/abstraxion": minor +"demo-app": minor +--- + +simulation fix and granter override diff --git a/apps/demo-app/src/app/layout.tsx b/apps/demo-app/src/app/layout.tsx index d98c720..0f2ae0b 100644 --- a/apps/demo-app/src/app/layout.tsx +++ b/apps/demo-app/src/app/layout.tsx @@ -32,8 +32,8 @@ const legacyConfig = { }; const treasuryConfig = { - treasury: "xion1h82c0efsxxq4pgua754u6xepfu6avglup20fl834gc2ah0ptgn5s2zffe9", // Example XION treasury contract with /cosmwasm.wasm.v1.MsgExecuteContract grant - // gasPrice: "0.001uxion", // If you feel the need to change the gasPrice when connecting to signer, set this value. Please stick to the string format seen in example + treasury: "xion1nn55ch09p4a4z30am967n5n8r75m2ag3s3sujutxfmchhsxqtg3qghdg7h", // Example XION treasury instance for executing seat contract + gasPrice: "0.001uxion", // If you feel the need to change the gasPrice when connecting to signer, set this value. Please stick to the string format seen in example // Optional params to activate mainnet config // rpcUrl: "https://rpc.xion-mainnet-1.burnt.com:443", // restUrl: "https://api.xion-mainnet-1.burnt.com:443", diff --git a/packages/abstraxion-core/src/AbstraxionAuth.ts b/packages/abstraxion-core/src/AbstraxionAuth.ts index c4c95b1..9eac87e 100644 --- a/packages/abstraxion-core/src/AbstraxionAuth.ts +++ b/packages/abstraxion-core/src/AbstraxionAuth.ts @@ -208,6 +208,7 @@ export class AbstraxionAuth { gasPrice: GasPrice.fromString("0uxion"), granterAddress, granteeAddress, + treasuryAddress: this.treasury, }, ); diff --git a/packages/abstraxion-core/src/GranteeSignerClient.ts b/packages/abstraxion-core/src/GranteeSignerClient.ts index ce726d2..dd3b209 100644 --- a/packages/abstraxion-core/src/GranteeSignerClient.ts +++ b/packages/abstraxion-core/src/GranteeSignerClient.ts @@ -8,8 +8,14 @@ import { EncodeObject, OfflineSigner, } from "@cosmjs/proto-signing"; -import type { Account, SignerData, StdFee } from "@cosmjs/stargate"; -import type { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx"; +import { + calculateFee, + GasPrice, + type Account, + type SignerData, + type StdFee, +} from "@cosmjs/stargate"; +import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx"; import { MsgExec } from "cosmjs-types/cosmos/authz/v1beta1/tx"; import { HttpEndpoint, @@ -18,15 +24,19 @@ import { } from "@cosmjs/tendermint-rpc"; import { customAccountFromAny } from "@burnt-labs/signers"; -interface GranteeSignerOptions { +export interface GranteeSignerOptions { readonly granterAddress: string; readonly granteeAddress: string; + readonly treasuryAddress?: string; } export class GranteeSignerClient extends SigningCosmWasmClient { protected readonly granterAddress: string; private readonly _granteeAddress: string; private readonly _signer: OfflineSigner; + private readonly _gasPrice?: GasPrice; + private readonly _treasury?: string; + private readonly _defaultGasMultiplier = 1.4; // cosmjs 0.32.4 default public get granteeAddress(): string { return this._granteeAddress; @@ -65,10 +75,12 @@ export class GranteeSignerClient extends SigningCosmWasmClient { { granterAddress, granteeAddress, + gasPrice, + treasuryAddress, ...options }: SigningCosmWasmClientOptions & GranteeSignerOptions, ) { - super(cometClient, signer, options); + super(cometClient, signer, { ...options, gasPrice }); if (granterAddress === undefined) { throw new Error("granterAddress is required"); } @@ -78,6 +90,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient { throw new Error("granteeAddress is required"); } this._granteeAddress = granteeAddress; + this._gasPrice = gasPrice; + this._treasury = treasuryAddress; this._signer = signer; } @@ -111,7 +125,45 @@ export class GranteeSignerClient extends SigningCosmWasmClient { ]; } - return super.signAndBroadcast(signerAddress, messages, fee, memo); + let usedFee: StdFee; + + const granter = this._treasury ? this._treasury : this.granterAddress; + + if (fee == "auto" || typeof fee === "number") { + if (!this._gasPrice) { + throw new Error( + "Gas price must be set in the client options when auto gas is used", + ); + } + const gasEstimation = await this.simulate(signerAddress, messages, memo); + const multiplier = + typeof fee == "number" ? fee : this._defaultGasMultiplier; + const calculatedFee = calculateFee( + Math.round(gasEstimation * multiplier), + this._gasPrice, + ); + + usedFee = { + ...calculatedFee, + granter, + }; + } else { + usedFee = { ...fee, granter }; + } + + const txRaw = await this.sign( + signerAddress, + messages, + usedFee, + memo, + undefined, + ); + const txBytes = TxRaw.encode(txRaw).finish(); + return this.broadcastTx( + txBytes, + this.broadcastTimeoutMs, + this.broadcastPollIntervalMs, + ); } public async sign( diff --git a/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts b/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts index acddd2f..c5408e4 100644 --- a/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts +++ b/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts @@ -1,6 +1,5 @@ import { useContext, useEffect, useState } from "react"; -import { testnetChainInfo, xionGasValues } from "@burnt-labs/constants"; -import { GasPrice } from "@cosmjs/stargate"; +import { testnetChainInfo } from "@burnt-labs/constants"; import { GranteeSignerClient, SignArbSecp256k1HdWallet, @@ -22,6 +21,7 @@ export const useAbstraxionSigningClient = (): { rpcUrl, logout, gasPrice, + treasury, } = useContext(AbstraxionContext); const [signArbWallet, setSignArbWallet] = useState< SignArbSecp256k1HdWallet | undefined @@ -59,6 +59,7 @@ export const useAbstraxionSigningClient = (): { gasPrice, granterAddress, granteeAddress, + treasuryAddress: treasury, }, );