Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/auto gas #227

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/perfect-hounds-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@burnt-labs/abstraxion": minor
"demo-app": minor
---

introduce gasPrice param; provide documentation on "auto" fee use
3 changes: 2 additions & 1 deletion apps/demo-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const legacyConfig = {
};

const treasuryConfig = {
treasury: "xion17ah4x9te3sttpy2vj5x6hv4xvc0td526nu0msf7mt3kydqj4qs2s9jhe90", // Example XION treasury contract
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
// 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
19 changes: 13 additions & 6 deletions apps/demo-app/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,25 @@ export default function Page(): JSX.Element {
};

try {
// Use "auto" fee for most transactions
const claimRes = await client?.execute(
account.bech32Address,
seatContractAddress,
msg,
{
amount: [{ amount: "0", denom: "uxion" }],
gas: "500000",
},
"",
[],
"auto",
);

// Default cosmsjs gas multiplier for simulation is 1.4
// If you're finding that transactions are undersimulating, you can bump up the gas multiplier by setting fee to a number, ex. 1.5
// Fee amounts shouldn't stray too far away from the defaults
// Example:
// const claimRes = await client?.execute(
// account.bech32Address,
// seatContractAddress,
// msg,
// 1.5,
// );

setExecuteResult(claimRes);
} catch (error) {
// eslint-disable-next-line no-console -- No UI exists yet to display errors
Expand Down
2 changes: 2 additions & 0 deletions packages/abstraxion/src/components/Abstraxion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface AbstraxionConfig {
bank?: SpendLimit[];
callbackUrl?: string;
treasury?: string;
gasPrice?: string;
}

export function AbstraxionProvider({
Expand All @@ -87,6 +88,7 @@ export function AbstraxionProvider({
bank={config.bank}
callbackUrl={config.callbackUrl}
treasury={config.treasury}
gasPrice={config.gasPrice}
>
{children}
</AbstraxionContextProvider>
Expand Down
14 changes: 13 additions & 1 deletion packages/abstraxion/src/components/AbstraxionContext/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReactNode } from "react";
import { createContext, useCallback, useEffect, useState } from "react";
import { testnetChainInfo } from "@burnt-labs/constants";
import { testnetChainInfo, xionGasValues } from "@burnt-labs/constants";
import { GasPrice } from "@cosmjs/stargate";
import { SignArbSecp256k1HdWallet } from "@burnt-labs/abstraxion-core";
import { abstraxionAuth } from "../Abstraxion";

Expand Down Expand Up @@ -34,6 +35,7 @@ export interface AbstraxionContextProps {
stake?: boolean;
bank?: SpendLimit[];
treasury?: string;
gasPrice: GasPrice;
logout: () => void;
}

Expand All @@ -50,6 +52,7 @@ export function AbstraxionContextProvider({
bank,
callbackUrl,
treasury,
gasPrice,
}: {
children: ReactNode;
contracts?: ContractGrantDescription[];
Expand All @@ -60,6 +63,7 @@ export function AbstraxionContextProvider({
bank?: SpendLimit[];
callbackUrl?: string;
treasury?: string;
gasPrice?: string;
}): JSX.Element {
const [abstraxionError, setAbstraxionError] = useState("");
const [isConnected, setIsConnected] = useState(false);
Expand All @@ -70,6 +74,13 @@ export function AbstraxionContextProvider({
>(undefined);
const [granterAddress, setGranterAddress] = useState("");
const [dashboardUrl, setDashboardUrl] = useState("");
let gasPriceDefault: GasPrice;
const { gasPrice: gasPriceConstant } = xionGasValues;
if (rpcUrl.includes("mainnet")) {
gasPriceDefault = GasPrice.fromString(gasPriceConstant);
} else {
gasPriceDefault = GasPrice.fromString("0uxion");
}

const configureInstance = useCallback(() => {
abstraxionAuth.configureAbstraxionInstance(
Expand Down Expand Up @@ -160,6 +171,7 @@ export function AbstraxionContextProvider({
bank,
treasury,
logout,
gasPrice: gasPrice ? GasPrice.fromString(gasPrice) : gasPriceDefault,
}}
>
{children}
Expand Down
14 changes: 10 additions & 4 deletions packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useEffect, useState } from "react";
import { testnetChainInfo } from "@burnt-labs/constants";
import { testnetChainInfo, xionGasValues } from "@burnt-labs/constants";
import { GasPrice } from "@cosmjs/stargate";
import {
GranteeSignerClient,
Expand All @@ -15,8 +15,14 @@ export const useAbstraxionSigningClient = (): {
| undefined;
readonly logout: (() => void) | undefined;
} => {
const { isConnected, abstraxionAccount, granterAddress, rpcUrl, logout } =
useContext(AbstraxionContext);
const {
isConnected,
abstraxionAccount,
granterAddress,
rpcUrl,
logout,
gasPrice,
} = useContext(AbstraxionContext);
const [signArbWallet, setSignArbWallet] = useState<
SignArbSecp256k1HdWallet | undefined
>(undefined);
Expand Down Expand Up @@ -50,7 +56,7 @@ export const useAbstraxionSigningClient = (): {
rpcUrl || testnetChainInfo.rpc,
abstraxionAccount,
{
gasPrice: GasPrice.fromString("0uxion"),
gasPrice,
granterAddress,
granteeAddress,
},
Expand Down
Loading