Skip to content

Commit

Permalink
liquidity
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Apr 5, 2024
1 parent 6d9c156 commit f7b5f98
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ jobs:
run: |
cca --example swap-tokens --name swap-tokens
cd swap-tokens
yarn build
- name: provide-liquidity
run: |
cca --example provide-liquidity --name provide-liquidity
cd provide-liquidity
yarn build
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ export const AddLiquidityModal = ({

const currentInputTokens = singleToken
? [
inputTokens.find(
({ denom }) => denom === getOsmoDenomForSymbol(singleToken)
)!,
]
inputTokens.find(
({ denom }) => denom === getOsmoDenomForSymbol(singleToken)
)!,
]
: inputTokens;

const hasEmptyAmount = currentInputTokens.some((t) => !t.inputAmount);
Expand All @@ -126,10 +126,10 @@ export const AddLiquidityModal = ({
const btnText = hasEmptyAmount
? 'Amount is empty'
: hasInsufficientAmount
? 'Insufficient amount'
: hasZeroAmount
? 'Amount is Zero'
: 'Add liquidity';
? 'Insufficient amount'
: hasZeroAmount
? 'Amount is Zero'
: 'Add liquidity';

const closeModal = () => {
setInputTokens(
Expand Down Expand Up @@ -167,7 +167,9 @@ export const AddLiquidityModal = ({
coinSymbol,
inputCoin.amount
);
// @ts-ignore
const coinsNeeded = convertDollarValueToCoins(inputValue, pool, prices);
// @ts-ignore
const shareOutAmount = calcShareOutAmount(pool, coinsNeeded);
const joinSwapExternAmountInMsg = joinSwapExternAmountIn({
poolId: currentPool.id,
Expand All @@ -180,6 +182,7 @@ export const AddLiquidityModal = ({
});
msgs.push(joinSwapExternAmountInMsg);
} else {
// @ts-ignore
const shareOutAmount = calcShareOutAmount(pool, allCoins);
const tokenInMaxs = allCoins.map((c: Coin) => {
return coin(c.amount, c.denom);
Expand Down Expand Up @@ -224,7 +227,9 @@ export const AddLiquidityModal = ({
size={isMobile ? 'sm' : { sm: 'sm', md: 'xl', lg: '3xl' }}
>
<ModalOverlay bg="blackAlpha.800" />
{/* @ts-ignore */}
<ModalContent bg={useColorModeValue('#FFF', '#2C3137')}>
{/* @ts-ignore */}
<ModalHeader>
<Text fontWeight="600" fontSize="20px" color={statColor}>
Add liquidity
Expand Down
1 change: 1 addition & 0 deletions examples/provide-liquidity/hooks/queries/usePoolsApr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const usePoolsApr = (pools: ExtendedPool[]) => {
pool,
prices,
lockup: duration,
// @ts-ignore
assets: osmosisAssets,
volume7d: pool.volume7d,
activeGauges: gauges,
Expand Down
1 change: 1 addition & 0 deletions examples/provide-liquidity/hooks/queries/usePoolsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const usePoolsData = () => {
},
});

// @ts-ignore
const poolsQuery: UseQueryResult<Pool[]> = osmosisQuery.gamm.v1beta1.usePools(
{
request: {
Expand Down
2 changes: 1 addition & 1 deletion examples/provide-liquidity/hooks/useTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useTx = (chainName: string) => {
if (client && signed) {
await client
.broadcastTx(Uint8Array.from(txRaw.encode(signed).finish()))
.then((res) => {
.then((res: any) => {
if (isDeliverTxSuccess(res)) {
if (options.onSuccess) options.onSuccess();

Expand Down
6 changes: 5 additions & 1 deletion examples/provide-liquidity/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SignerOptions, wallets } from 'cosmos-kit';
import { assets, chains } from 'chain-registry';
import { GasPrice } from '@cosmjs/stargate';
import { aminoTypes, registry } from '../config/defaults';
import { Chain } from '@chain-registry/types';

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -24,13 +25,15 @@ const queryClient = new QueryClient({

function CreateCosmosApp({ Component, pageProps }: AppProps) {
const signerOptions: SignerOptions = {
// @ts-ignore
signingStargate: () => {
return {
aminoTypes,
registry,
};
},
signingCosmwasm: (chain) => {
// @ts-ignore
signingCosmwasm: (chain: Chain) => {
switch (chain.chain_name) {
case 'osmosis':
case 'osmosistestnet':
Expand Down Expand Up @@ -62,6 +65,7 @@ function CreateCosmosApp({ Component, pageProps }: AppProps) {
}}
>
<QueryClientProvider client={queryClient}>
{/* @ts-ignore */}
<Component {...pageProps} />
</QueryClientProvider>
</ChainProvider>
Expand Down
8 changes: 8 additions & 0 deletions examples/provide-liquidity/utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const convertGeckoPricesToDenomPriceHash = (
};

export const calcPoolLiquidity = (pool: Pool, prices: PriceHash): string => {
// @ts-ignore
return _calcPoolLiquidity(osmosisAssets, pool, prices);
};

Expand All @@ -84,6 +85,7 @@ export const convertGammTokenToDollarValue = (
pool: Pool,
prices: PriceHash
): string => {
// @ts-ignore
return _convertGammTokenToDollarValue(osmosisAssets, coin, pool, prices);
};

Expand All @@ -92,6 +94,7 @@ export const convertDollarValueToCoins = (
pool: Pool,
prices: PriceHash
): CoinValue[] => {
// @ts-ignore
return _convertDollarValueToCoins(osmosisAssets, value, pool, prices);
};

Expand All @@ -100,13 +103,15 @@ export const convertDollarValueToShares = (
pool: Pool,
prices: PriceHash
) => {
// @ts-ignore
return _convertDollarValueToShares(osmosisAssets, value, pool, prices);
};

export const prettyPool = (
pool: Pool,
{ includeDetails = false } = {}
): PoolPretty => {
// @ts-ignore
return _prettyPool(osmosisAssets, pool, { includeDetails });
};

Expand Down Expand Up @@ -146,6 +151,7 @@ export const calcCoinsNeededForValue = (
poolInfo: PoolPretty,
value: string | number
) => {
// @ts-ignore
return _calcCoinsNeededForValue(osmosisAssets, prices, poolInfo, value);
};

Expand All @@ -154,6 +160,7 @@ export const getCoinBalance = (
balances: Coin[],
prettyAsset: PoolAssetPretty
): CoinBalance => {
// @ts-ignore
return _getCoinBalance(osmosisAssets, prices, balances, prettyAsset);
};

Expand All @@ -162,6 +169,7 @@ export const calcMaxCoinsForPool = (
poolInfo: PoolPretty,
balances: Coin[]
) => {
// @ts-ignore
return _calcMaxCoinsForPool(osmosisAssets, prices, poolInfo, balances);
};

Expand Down

0 comments on commit f7b5f98

Please sign in to comment.