Skip to content

Commit

Permalink
Update typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Sep 13, 2023
1 parent e688b29 commit 0c04bc4
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 191 deletions.
2 changes: 1 addition & 1 deletion typescript/packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@stargazezone/launchpad": "^2.3.3",
"@stargazezone/infinity-types": "0.5.0",
"@stargazezone/infinity-types": "0.6.0",
"@stargazezone/core-types": "0.1.0",
"@types/jest": "^29.5.2",
"axios": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/infinity-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stargazezone/infinity-types",
"version": "0.6.0",
"version": "0.7.0",
"description": "The official types package for the Infinity Swap protocol",
"author": "Tasio Victoria",
"homepage": "https://stargaze.zone/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ import {
ExecuteMsg,
InstantiateMsg,
NextPairResponse,
Pair,
PairConfigForAddr,
PairConfigForString,
PairImmutableForAddr,
PairImmutableForString,
PairInternal,
PairType,
QueryBoundForUint64,
QueryMsg,
QueryOptionsForUint64,
QuoteSummary,
QuotesResponse,
TokenPayment,
Uint128,
} from './InfinityFactory.types'

Expand All @@ -33,6 +40,8 @@ export interface InfinityFactoryReadOnlyInterface {
owner: string
queryOptions?: QueryOptionsForUint64
}) => Promise<ArrayOfTupleOfUint64AndAddr>
simSellToPairQuotes: ({ limit, pair }: { limit: number; pair: Pair }) => Promise<QuotesResponse>
simBuyFromPairQuotes: ({ limit, pair }: { limit: number; pair: Pair }) => Promise<QuotesResponse>
}
export class InfinityFactoryQueryClient implements InfinityFactoryReadOnlyInterface {
client: CosmWasmClient
Expand All @@ -43,6 +52,8 @@ export class InfinityFactoryQueryClient implements InfinityFactoryReadOnlyInterf
this.contractAddress = contractAddress
this.nextPair = this.nextPair.bind(this)
this.pairsByOwner = this.pairsByOwner.bind(this)
this.simSellToPairQuotes = this.simSellToPairQuotes.bind(this)
this.simBuyFromPairQuotes = this.simBuyFromPairQuotes.bind(this)
}

nextPair = async ({ sender }: { sender: string }): Promise<NextPairResponse> => {
Expand All @@ -66,6 +77,22 @@ export class InfinityFactoryQueryClient implements InfinityFactoryReadOnlyInterf
},
})
}
simSellToPairQuotes = async ({ limit, pair }: { limit: number; pair: Pair }): Promise<QuotesResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
sim_sell_to_pair_quotes: {
limit,
pair,
},
})
}
simBuyFromPairQuotes = async ({ limit, pair }: { limit: number; pair: Pair }): Promise<QuotesResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
sim_buy_from_pair_quotes: {
limit,
pair,
},
})
}
}
export interface InfinityFactoryInterface extends InfinityFactoryReadOnlyInterface {
contractAddress: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Coin } from "@cosmjs/amino";
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { toUtf8 } from "@cosmjs/encoding";
import { InstantiateMsg, ExecuteMsg, BondingCurve, Uint128, Decimal, PairType, PairConfigForString, PairImmutableForString, QueryMsg, QueryBoundForUint64, QueryOptionsForUint64, Addr, Binary, NextPairResponse, ArrayOfTupleOfUint64AndAddr } from "./InfinityFactory.types";
import { InstantiateMsg, ExecuteMsg, BondingCurve, Uint128, Decimal, PairType, PairConfigForString, PairImmutableForString, QueryMsg, QueryBoundForUint64, Addr, QueryOptionsForUint64, Pair, PairConfigForAddr, PairImmutableForAddr, PairInternal, QuoteSummary, TokenPayment, Binary, NextPairResponse, ArrayOfTupleOfUint64AndAddr, QuotesResponse } from "./InfinityFactory.types";
export interface InfinityFactoryMessage {
contractAddress: string;
sender: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ import {
ExecuteMsg,
InstantiateMsg,
NextPairResponse,
Pair,
PairConfigForAddr,
PairConfigForString,
PairImmutableForAddr,
PairImmutableForString,
PairInternal,
PairType,
QueryBoundForUint64,
QueryMsg,
QueryOptionsForUint64,
QuoteSummary,
QuotesResponse,
TokenPayment,
Uint128,
} from './InfinityFactory.types'
import { UseQueryOptions, useQuery } from 'react-query'
Expand All @@ -35,6 +42,10 @@ export const infinityFactoryQueryKeys = {
[{ ...infinityFactoryQueryKeys.address(contractAddress)[0], method: 'next_pair', args }] as const,
pairsByOwner: (contractAddress: string | undefined, args?: Record<string, unknown>) =>
[{ ...infinityFactoryQueryKeys.address(contractAddress)[0], method: 'pairs_by_owner', args }] as const,
simSellToPairQuotes: (contractAddress: string | undefined, args?: Record<string, unknown>) =>
[{ ...infinityFactoryQueryKeys.address(contractAddress)[0], method: 'sim_sell_to_pair_quotes', args }] as const,
simBuyFromPairQuotes: (contractAddress: string | undefined, args?: Record<string, unknown>) =>
[{ ...infinityFactoryQueryKeys.address(contractAddress)[0], method: 'sim_buy_from_pair_quotes', args }] as const,
}
export const infinityFactoryQueries = {
nextPair: <TData = NextPairResponse>({
Expand Down Expand Up @@ -68,11 +79,91 @@ export const infinityFactoryQueries = {
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true),
}),
simSellToPairQuotes: <TData = QuotesResponse>({
client,
args,
options,
}: InfinityFactorySimSellToPairQuotesQuery<TData>): UseQueryOptions<QuotesResponse, Error, TData> => ({
queryKey: infinityFactoryQueryKeys.simSellToPairQuotes(client?.contractAddress, args),
queryFn: () =>
client
? client.simSellToPairQuotes({
limit: args.limit,
pair: args.pair,
})
: Promise.reject(new Error('Invalid client')),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true),
}),
simBuyFromPairQuotes: <TData = QuotesResponse>({
client,
args,
options,
}: InfinityFactorySimBuyFromPairQuotesQuery<TData>): UseQueryOptions<QuotesResponse, Error, TData> => ({
queryKey: infinityFactoryQueryKeys.simBuyFromPairQuotes(client?.contractAddress, args),
queryFn: () =>
client
? client.simBuyFromPairQuotes({
limit: args.limit,
pair: args.pair,
})
: Promise.reject(new Error('Invalid client')),
...options,
enabled: !!client && (options?.enabled != undefined ? options.enabled : true),
}),
}
export interface InfinityFactoryReactQuery<TResponse, TData = TResponse> {
client: InfinityFactoryQueryClient | undefined
options?: UseQueryOptions<TResponse, Error, TData>
}
export interface InfinityFactorySimBuyFromPairQuotesQuery<TData>
extends InfinityFactoryReactQuery<QuotesResponse, TData> {
args: {
limit: number
pair: Pair
}
}
export function useInfinityFactorySimBuyFromPairQuotesQuery<TData = QuotesResponse>({
client,
args,
options,
}: InfinityFactorySimBuyFromPairQuotesQuery<TData>) {
return useQuery<QuotesResponse, Error, TData>(
infinityFactoryQueryKeys.simBuyFromPairQuotes(client?.contractAddress, args),
() =>
client
? client.simBuyFromPairQuotes({
limit: args.limit,
pair: args.pair,
})
: Promise.reject(new Error('Invalid client')),
{ ...options, enabled: !!client && (options?.enabled != undefined ? options.enabled : true) },
)
}
export interface InfinityFactorySimSellToPairQuotesQuery<TData>
extends InfinityFactoryReactQuery<QuotesResponse, TData> {
args: {
limit: number
pair: Pair
}
}
export function useInfinityFactorySimSellToPairQuotesQuery<TData = QuotesResponse>({
client,
args,
options,
}: InfinityFactorySimSellToPairQuotesQuery<TData>) {
return useQuery<QuotesResponse, Error, TData>(
infinityFactoryQueryKeys.simSellToPairQuotes(client?.contractAddress, args),
() =>
client
? client.simSellToPairQuotes({
limit: args.limit,
pair: args.pair,
})
: Promise.reject(new Error('Invalid client')),
{ ...options, enabled: !!client && (options?.enabled != undefined ? options.enabled : true) },
)
}
export interface InfinityFactoryPairsByOwnerQuery<TData>
extends InfinityFactoryReactQuery<ArrayOfTupleOfUint64AndAddr, TData> {
args: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,70 @@ export type QueryMsg = {
owner: string;
query_options?: QueryOptionsForUint64 | null;
};
} | {
sim_sell_to_pair_quotes: {
limit: number;
pair: Pair;
};
} | {
sim_buy_from_pair_quotes: {
limit: number;
pair: Pair;
};
};
export type QueryBoundForUint64 = {
inclusive: number;
} | {
exclusive: number;
};
export type Addr = string;
export interface QueryOptionsForUint64 {
descending?: boolean | null;
limit?: number | null;
max?: QueryBoundForUint64 | null;
min?: QueryBoundForUint64 | null;
}
export type Addr = string;
export interface Pair {
config: PairConfigForAddr;
immutable: PairImmutableForAddr;
internal: PairInternal;
total_tokens: Uint128;
}
export interface PairConfigForAddr {
asset_recipient?: Addr | null;
bonding_curve: BondingCurve;
is_active: boolean;
pair_type: PairType;
}
export interface PairImmutableForAddr {
collection: Addr;
denom: string;
owner: Addr;
}
export interface PairInternal {
buy_from_pair_quote_summary?: QuoteSummary | null;
sell_to_pair_quote_summary?: QuoteSummary | null;
total_nfts: number;
}
export interface QuoteSummary {
fair_burn: TokenPayment;
royalty?: TokenPayment | null;
seller_amount: Uint128;
swap?: TokenPayment | null;
}
export interface TokenPayment {
amount: Uint128;
recipient: Addr;
}
export type Binary = string;
export interface NextPairResponse {
counter: number;
pair: Addr;
salt: Binary;
sender: Addr;
}
export type ArrayOfTupleOfUint64AndAddr = [number, Addr][];
export type ArrayOfTupleOfUint64AndAddr = [number, Addr][];
export interface QuotesResponse {
denom: string;
quotes: Uint128[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import { InstantiateMsg, ExecuteMsg, NftForTokensSource, Uint128, TokensForNftSource, SellOrder, SwapParamsForString, QueryMsg, Addr, BondingCurve, Decimal, PairType, Pair, PairConfigForAddr, PairImmutableForAddr, PairInternal, QuoteSummary, TokenPayment, ArrayOfNftForTokensQuote, NftForTokensQuote, QuotesResponse, ArrayOfTokensForNftQuote, TokensForNftQuote } from "./InfinityRouter.types";
import { InstantiateMsg, ExecuteMsg, NftForTokensSource, Uint128, TokensForNftSource, SellOrder, SwapParamsForString, QueryMsg, Addr, ArrayOfNftForTokensQuote, NftForTokensQuote, ArrayOfTokensForNftQuote, TokensForNftQuote } from "./InfinityRouter.types";
export interface InfinityRouterReadOnlyInterface {
contractAddress: string;
nftsForTokens: ({
Expand All @@ -31,20 +31,6 @@ export interface InfinityRouterReadOnlyInterface {
filterSources?: TokensForNftSource[];
limit: number;
}) => Promise<ArrayOfTokensForNftQuote>;
simSellToPairQuotes: ({
limit,
pair
}: {
limit: number;
pair: Pair;
}) => Promise<QuotesResponse>;
simBuyFromPairQuotes: ({
limit,
pair
}: {
limit: number;
pair: Pair;
}) => Promise<QuotesResponse>;
}
export class InfinityRouterQueryClient implements InfinityRouterReadOnlyInterface {
client: CosmWasmClient;
Expand All @@ -55,8 +41,6 @@ export class InfinityRouterQueryClient implements InfinityRouterReadOnlyInterfac
this.contractAddress = contractAddress;
this.nftsForTokens = this.nftsForTokens.bind(this);
this.tokensForNfts = this.tokensForNfts.bind(this);
this.simSellToPairQuotes = this.simSellToPairQuotes.bind(this);
this.simBuyFromPairQuotes = this.simBuyFromPairQuotes.bind(this);
}

nftsForTokens = async ({
Expand Down Expand Up @@ -99,34 +83,6 @@ export class InfinityRouterQueryClient implements InfinityRouterReadOnlyInterfac
}
});
};
simSellToPairQuotes = async ({
limit,
pair
}: {
limit: number;
pair: Pair;
}): Promise<QuotesResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
sim_sell_to_pair_quotes: {
limit,
pair
}
});
};
simBuyFromPairQuotes = async ({
limit,
pair
}: {
limit: number;
pair: Pair;
}): Promise<QuotesResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
sim_buy_from_pair_quotes: {
limit,
pair
}
});
};
}
export interface InfinityRouterInterface extends InfinityRouterReadOnlyInterface {
contractAddress: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Coin } from "@cosmjs/amino";
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { toUtf8 } from "@cosmjs/encoding";
import { InstantiateMsg, ExecuteMsg, NftForTokensSource, Uint128, TokensForNftSource, SellOrder, SwapParamsForString, QueryMsg, Addr, BondingCurve, Decimal, PairType, Pair, PairConfigForAddr, PairImmutableForAddr, PairInternal, QuoteSummary, TokenPayment, ArrayOfNftForTokensQuote, NftForTokensQuote, QuotesResponse, ArrayOfTokensForNftQuote, TokensForNftQuote } from "./InfinityRouter.types";
import { InstantiateMsg, ExecuteMsg, NftForTokensSource, Uint128, TokensForNftSource, SellOrder, SwapParamsForString, QueryMsg, Addr, ArrayOfNftForTokensQuote, NftForTokensQuote, ArrayOfTokensForNftQuote, TokensForNftQuote } from "./InfinityRouter.types";
export interface InfinityRouterMessage {
contractAddress: string;
sender: string;
Expand Down
Loading

0 comments on commit 0c04bc4

Please sign in to comment.