Skip to content

Commit

Permalink
Merge branch 'main' into chore/grant-validity-check
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal authored Nov 26, 2024
2 parents a1f907c + 6ca7dad commit 8704930
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 19 deletions.
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions .changeset/silly-worms-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@burnt-labs/abstraxion-core": minor
"@burnt-labs/abstraxion": minor
"demo-app": minor
---

simulation fix and granter override
6 changes: 6 additions & 0 deletions .changeset/sixty-geckos-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"demo-app": minor
"@burnt-labs/constants": minor
---

Update default gas price to 0.001uxion
14 changes: 14 additions & 0 deletions apps/demo-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/demo-app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ 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
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",
Expand Down
8 changes: 8 additions & 0 deletions packages/abstraxion-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/abstraxion-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@burnt-labs/abstraxion-core",
"version": "1.0.0-alpha.47",
"version": "1.0.0-alpha.48",
"sideEffects": [
"**/*.css"
],
Expand Down
1 change: 1 addition & 0 deletions packages/abstraxion-core/src/AbstraxionAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class AbstraxionAuth {
gasPrice: GasPrice.fromString("0uxion"),
granterAddress,
granteeAddress,
treasuryAddress: this.treasury,
},
);

Expand Down
62 changes: 57 additions & 5 deletions packages/abstraxion-core/src/GranteeSignerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions packages/abstraxion/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/abstraxion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@burnt-labs/abstraxion",
"version": "1.0.0-alpha.52",
"version": "1.0.0-alpha.53",
"sideEffects": [
"**/*.css"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
5 changes: 3 additions & 2 deletions packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,6 +21,7 @@ export const useAbstraxionSigningClient = (): {
rpcUrl,
logout,
gasPrice,
treasury,
} = useContext(AbstraxionContext);
const [signArbWallet, setSignArbWallet] = useState<
SignArbSecp256k1HdWallet | undefined
Expand Down Expand Up @@ -59,6 +59,7 @@ export const useAbstraxionSigningClient = (): {
gasPrice,
granterAddress,
granteeAddress,
treasuryAddress: treasury,
},
);

Expand Down
6 changes: 6 additions & 0 deletions packages/constants/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/constants/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/constants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/signers/src/signers/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 8704930

Please sign in to comment.