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

ibc transaction success #19

Merged
merged 5 commits into from
Feb 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
import { useChainWallet } from '@interchain-kit/react';
import { chains } from '@chain-registry/v2'
import BigNumber from 'bignumber.js';
import { ibc } from 'osmo-query';
import { StdFee } from '@interchainjs/cosmos-types/types';
import { KeplrWalletName } from '@/config';
import { useDisclosure, useChainUtils, useTx, useBalance } from '@/hooks';
import { truncDecimals } from '@/utils';
import { MsgTransfer } from 'interchainjs/ibc/applications/transfer/v1/tx';

import {
PrettyAsset,
Expand All @@ -21,8 +21,6 @@ import {
Unpacked,
} from './types';

const { transfer } = ibc.applications.transfer.v1.MessageComposer.withTypeUrl;

const ZERO_AMOUNT = '0';

interface OverviewTransferWrapperProps {
Expand Down Expand Up @@ -156,16 +154,19 @@ const OverviewTransferWrapper = (
const stamp = Date.now();
const timeoutInNanos = (stamp + 1.2e6) * 1e6;

const msg = transfer({
sourcePort,
sourceChannel,
sender: sourceAddress,
receiver: destAddress,
token,
// @ts-ignore
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
});
const msg = {
typeUrl: MsgTransfer.typeUrl,
value: MsgTransfer.fromPartial({
sourcePort,
sourceChannel,
token,
sender: sourceAddress,
receiver: destAddress,
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
memo: '',
}),
}

await tx([msg], {
fee,
Expand Down
51 changes: 27 additions & 24 deletions examples/ibc-asset-list/components/asset-list/RowTransferModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import BigNumber from 'bignumber.js';
import { StdFee } from '@interchainjs/cosmos-types/types';
import { useDisclosure, useChainUtils, useBalance, useTx } from '@/hooks';
import { KeplrWalletName } from '@/config';
import { ibc } from 'osmo-query';
import { chains } from '@chain-registry/v2'

import { PriceHash, TransferInfo, Transfer } from './types';

const { transfer } = ibc.applications.transfer.v1.MessageComposer.withTypeUrl;
import { MsgTransfer } from 'interchainjs/ibc/applications/transfer/v1/tx';

interface IProps {
prices: PriceHash;
Expand Down Expand Up @@ -128,16 +125,19 @@ const TransferModalBody = (
const stamp = Date.now();
const timeoutInNanos = (stamp + 1.2e6) * 1e6;

const msg = transfer({
sourcePort,
sourceChannel,
sender: sourceAddress,
receiver: destAddress,
token,
// @ts-ignore
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
});
const msg = {
typeUrl: MsgTransfer.typeUrl,
value: MsgTransfer.fromPartial({
sourcePort,
sourceChannel,
token,
sender: sourceAddress,
receiver: destAddress,
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
memo: '',
}),
}

await tx([msg], {
fee,
Expand Down Expand Up @@ -196,16 +196,19 @@ const TransferModalBody = (
const stamp = Date.now();
const timeoutInNanos = (stamp + 1.2e6) * 1e6;

const msg = transfer({
sourcePort,
sourceChannel,
sender: sourceAddress,
receiver: destAddress,
token,
// @ts-ignore
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
});
const msg = {
typeUrl: MsgTransfer.typeUrl,
value: MsgTransfer.fromPartial({
sourcePort,
sourceChannel,
token,
sender: sourceAddress,
receiver: destAddress,
timeoutHeight: undefined,
timeoutTimestamp: BigInt(timeoutInNanos),
memo: '',
}),
}

await tx([msg], {
fee,
Expand Down
32 changes: 1 addition & 31 deletions examples/ibc-asset-list/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { assetLists as assets } from '@chain-registry/v2';
import { AssetList, Asset } from '@chain-registry/v2-types';
import { GeneratedType } from '@interchainjs/cosmos-types/types';
import { Registry } from '@cosmjs/proto-signing';
import { AminoTypes } from '@cosmjs/stargate';
import {
cosmosAminoConverters,
cosmosProtoRegistry,
cosmwasmAminoConverters,
cosmwasmProtoRegistry,
ibcProtoRegistry,
ibcAminoConverters,
osmosisAminoConverters,
osmosisProtoRegistry,
} from 'osmo-query';

export const defaultChainName = 'osmosis';
export const KeplrWalletName = 'keplr-extension';
Expand All @@ -23,21 +10,4 @@ export const chainassets: AssetList = assets.find(

export const coin: Asset = chainassets.assets.find(
(asset) => asset.base === 'uosmo'
) as Asset;

const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
...cosmwasmProtoRegistry,
...ibcProtoRegistry,
...osmosisProtoRegistry,
];

const aminoConverters = {
...cosmosAminoConverters,
...cosmwasmAminoConverters,
...ibcAminoConverters,
...osmosisAminoConverters,
};

export const registry = new Registry(protoRegistry);
export const aminoTypes = new AminoTypes(aminoConverters);
) as Asset;
12 changes: 10 additions & 2 deletions examples/ibc-asset-list/hooks/queries/useQueryHooks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useChain } from '@interchain-kit/react';
import { useRpcEndpoint, useRpcClient, createRpcQueryHooks } from 'osmo-query';
import { createRpcQueryHooks } from 'osmo-query';
import { useRpcClient } from 'interchain-react/react-query';
import { useRpcEndpoint } from 'interchain-react/react-query'
import { defaultContext } from '@tanstack/react-query';

export const useQueryHooks = (chainName: string, extraKey?: string) => {
const { address, getRpcEndpoint } = useChain(chainName);

const rpcEndpointQuery = useRpcEndpoint({
getter: getRpcEndpoint,
options: {
context: defaultContext,
enabled: !!address,
staleTime: Infinity,
queryKeyHashFn: (queryKey) => {
Expand All @@ -17,8 +21,12 @@ export const useQueryHooks = (chainName: string, extraKey?: string) => {
});

const rpcClientQuery = useRpcClient({
rpcEndpoint: rpcEndpointQuery.data || '',
// rpcEndpoint: rpcEndpointQuery.data || '',
clientResolver: {
rpcEndpoint: rpcEndpointQuery.data,
},
options: {
context: defaultContext,
enabled: !!address && !!rpcEndpointQuery.data,
staleTime: Infinity,
queryKeyHashFn: (queryKey) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/ibc-asset-list/hooks/queries/useTotalAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useEffect, useMemo } from 'react';
import { useChainUtils } from '../useChainUtils';
import { usePrices } from './usePrices';
import { defaultChainName as osmoChainName } from '@/config';
import { Pool } from 'osmo-query/dist/codegen/osmosis/gamm/pool-models/balancer/balancerPool';
import { Pool } from '@/types/pool-models';
import { convertGammTokenToDollarValue } from '@/utils';
import { useQueryHooks } from './useQueryHooks';

Expand Down
5 changes: 2 additions & 3 deletions examples/ibc-asset-list/hooks/useTx.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { cosmos } from 'osmo-query';
import { StdFee } from '@interchainjs/cosmos-types/types';
import { isDeliverTxSuccess } from '@interchainjs/cosmos/utils/asserts';
import { toast, ToastShape } from '@interchain-ui/react';
import { useChain } from '@interchain-kit/react';
import { TxRaw } from 'osmo-query/dist/codegen/cosmos/tx/v1beta1/tx';
import { assetLists } from '@chain-registry/v2';
import {
toConverters,
toEncoders,
} from '@interchainjs/cosmos/utils';
import { MsgTransfer } from 'interchainjs/ibc/applications/transfer/v1/tx';
import { TxRaw } from '@interchainjs/cosmos-types/cosmos/tx/v1beta1/tx'

interface Msg {
typeUrl: string;
Expand All @@ -28,7 +27,7 @@ export enum TxStatus {
Broadcasting = 'Transaction Broadcasting',
}

const txRaw = cosmos.tx.v1beta1.TxRaw;
const txRaw = TxRaw;

export const useTx = (chainName: string) => {
const { address, getSigningClient } =
Expand Down
9 changes: 5 additions & 4 deletions examples/ibc-asset-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"@cosmjs/stargate": "^0.32.3",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@interchain-kit/core": "0.0.1-beta.62",
"@interchain-kit/keplr-extension": "0.0.1-beta.62",
"@interchain-kit/leap-extension": "0.0.1-beta.62",
"@interchain-kit/react": "0.0.1-beta.62",
"@interchain-kit/core": "0.2.203",
"@interchain-kit/keplr-extension": "0.2.203",
"@interchain-kit/leap-extension": "0.2.203",
"@interchain-kit/react": "0.2.203",
"@interchain-ui/react": "1.26.0",
"@interchain-ui/react-no-ssr": "^0.1.6",
"@interchainjs/cosmos": "1.8.2",
Expand All @@ -37,6 +37,7 @@
"chain-registry": "^1.69.32",
"fast-fuzzy": "1.12.0",
"framer-motion": "9.0.7",
"interchain-react": "1.7.3",
"match-sorter": "^6.3.3",
"next": "^13",
"osmo-query": "16.5.1",
Expand Down
94 changes: 94 additions & 0 deletions examples/ibc-asset-list/types/pool-models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Coin } from '@interchainjs/cosmos-types/types';

export interface Pool {
$typeUrl?: string;
address: string;
id: bigint;
poolParams: PoolParams;
/**
* This string specifies who will govern the pool in the future.
* Valid forms of this are:
* {token name},{duration}
* {duration}
* where {token name} if specified is the token which determines the
* governor, and if not specified is the LP token for this pool.duration is
* a time specified as 0w,1w,2w, etc. which specifies how long the token
* would need to be locked up to count in governance. 0w means no lockup.
* TODO: Further improve these docs
*/
futurePoolGovernor: string;
/** sum of all LP tokens sent out */
totalShares: Coin;
/**
* These are assumed to be sorted by denomiation.
* They contain the pool asset and the information about the weight
*/
poolAssets: PoolAsset[];
/** sum of all non-normalized pool weights */
totalWeight: string;
}

interface PoolParams {
swapFee: string;
/**
* N.B.: exit fee is disabled during pool creation in x/poolmanager. While old
* pools can maintain a non-zero fee. No new pool can be created with non-zero
* fee anymore
*/
exitFee: string;
smoothWeightChangeParams?: SmoothWeightChangeParams;
}

interface SmoothWeightChangeParams {
/**
* The start time for beginning the weight change.
* If a parameter change / pool instantiation leaves this blank,
* it should be generated by the state_machine as the current time.
*/
startTime: Date;
/** Duration for the weights to change over */
duration: Duration;
/**
* The initial pool weights. These are copied from the pool's settings
* at the time of weight change instantiation.
* The amount PoolAsset.token.amount field is ignored if present,
* future type refactorings should just have a type with the denom & weight
* here.
*/
initialPoolWeights: PoolAsset[];
/**
* The target pool weights. The pool weights will change linearly with respect
* to time between start_time, and start_time + duration. The amount
* PoolAsset.token.amount field is ignored if present, future type
* refactorings should just have a type with the denom & weight here.
*/
targetPoolWeights: PoolAsset[];
}

interface Duration {
/**
* Signed seconds of the span of time. Must be from -315,576,000,000
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
*/
seconds: bigint;
/**
* Signed fractions of a second at nanosecond resolution of the span
* of time. Durations less than one second are represented with a 0
* `seconds` field and a positive or negative `nanos` field. For durations
* of one second or more, a non-zero value for the `nanos` field must be
* of the same sign as the `seconds` field. Must be from -999,999,999
* to +999,999,999 inclusive.
*/
nanos: number;
}

interface PoolAsset {
/**
* Coins we are talking about,
* the denomination must be unique amongst all PoolAssets for this pool.
*/
token: Coin;
/** Weight that is not normalized. This weight must be less than 2^50 */
weight: string;
}
4 changes: 2 additions & 2 deletions examples/ibc-asset-list/utils/pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pool } from 'osmo-query/dist/codegen/osmosis/gamm/pool-models/balancer/balancerPool';
import { Coin } from 'osmo-query/dist/codegen/cosmos/base/v1beta1/coin';
import { Pool } from '@/types/pool-models';
import { Coin } from 'interchainjs/types';
import {
PriceHash,
CoinValue,
Expand Down
20 changes: 2 additions & 18 deletions examples/ibc-asset-list/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { DenomUnit } from '@chain-registry/v2-types';
import { Duration } from 'osmo-query/dist/codegen/google/protobuf/duration';
import { Gauge } from 'osmo-query/dist/codegen/osmosis/incentives/gauge';
import { SuperfluidAsset } from 'osmo-query/dist/codegen/osmosis/superfluid/superfluid';
import { Coin } from 'osmo-query/dist/codegen/cosmos/base/v1beta1/coin';
import { Pool } from 'osmo-query/dist/codegen/osmosis/gamm/pool-models/balancer/balancerPool';
import { Coin } from 'interchainjs/types';
import { Pool } from '@/types/pool-models';

export type CoinDenom = DenomUnit['denom'];

Expand Down Expand Up @@ -55,19 +52,6 @@ export interface PoolPretty extends Pool {
poolAssetsPretty: PoolAssetPretty[];
}

export interface CalcPoolAprsParams {
activeGauges: Gauge[];
pool: Pool;
prices: PriceHash;
superfluidPools: SuperfluidAsset[];
aprSuperfluid: string | number;
lockupDurations: Duration[];
volume7d: string | number;
swapFee: string | number;
lockup?: string;
includeNonPerpetual?: boolean;
}

export interface Trade {
sell: Coin;
buy: Coin;
Expand Down
Loading
Loading