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

fix(juno-incentive-contract-messages): handled messages for juno #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 deletions components/Pages/Trade/Incentivize/hooks/useClosePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { useClients } from 'hooks/useClients'
import useTxStatus from 'hooks/useTxStatus'
import { usePoolFromListQueryById } from 'queries/usePoolsListQuery'
import { useRecoilValue } from 'recoil'
import { TerraTreasuryService } from 'services/treasuryService'
import { chainState } from 'state/chainState'
import { createExecuteMessage, validateTransactionSuccess } from 'util/messages/index'

import { TerraTreasuryService } from '../../../../../services/treasuryService'

type OpenPosition = {
poolId: string
}
Expand All @@ -25,8 +24,17 @@ export const useClosePosition = ({ poolId }: OpenPosition) => {
signingClient,
})

const createClosePositionMessage = (flow_id: number) => {
const msg = createExecuteMessage({
const createClosePositionMessage = (flow_id: number, walletChainName: string) => {
const msg = walletChainName === 'juno' ? createExecuteMessage({
message: {
close_flow: {
flow_identifier: { id: flow_id },
},
},
senderAddress: address,
contractAddress: pool?.staking_address,
funds: [],
}) : createExecuteMessage({
message: {
close_flow: {
flow_id,
Expand All @@ -36,13 +44,13 @@ export const useClosePosition = ({ poolId }: OpenPosition) => {
contractAddress: pool?.staking_address,
funds: [],
})

return [msg]
}

const { mutate: submit, ...state } = useMutation({
mutationFn: async ({ flowId }: { flowId: number }) => {
const msg = createClosePositionMessage(flowId)
const msg = createClosePositionMessage(flowId, walletChainName)

try {
await signingClient.simulate(
address, msg, '',
Expand All @@ -61,9 +69,6 @@ export const useClosePosition = ({ poolId }: OpenPosition) => {
}
}

console.log({ msg,
flowId,
poolId })
let fee:any = 'auto'
if (await signingClient.getChainId() === 'columbus-5') {
const gas = Math.ceil(await signingClient.simulate(
Expand Down
30 changes: 18 additions & 12 deletions components/Pages/Trade/Incentivize/hooks/useIncentivePoolInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useQuery } from 'react-query'

import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import {
Config,
useConfig,
Expand All @@ -12,7 +13,7 @@ import {
B_WHALE_TOKEN_SYMBOL,
WHALE_TOKEN_SYMBOL,
} from 'constants/index'
import usePrices from 'hooks/usePrices'
import usePrices, { Prices } from 'hooks/usePrices'
import { useRecoilValue } from 'recoil'
import { chainState } from 'state/chainState'
import { convertMicroDenomToDenom } from 'util/conversion/index'
Expand Down Expand Up @@ -40,6 +41,7 @@ export interface Flow {
}
}
}
asset_history: Array<{ [key: number]: number }>
flow_creator: string
flow_id: number
start_epoch: number
Expand All @@ -57,16 +59,17 @@ export interface IncentivePoolInfo {

poolId: string
}
const fetchFlows = async (client, address): Promise<Flow[]> => await client?.queryContractSmart(address, { flows: {} })

const fetchFlows = async (client: CosmWasmClient, address: string): Promise<Flow[]> => await client?.queryContractSmart(address, { flows: {} })
const getPoolFlowData = async (
client,
pools,
currentEpochData,
poolAssets,
prices,
poolsWithAprAnd24HrVolume,
client: CosmWasmClient,
pools: { staking_address: string; pool_id: any; swap_address: string }[],
currentEpochData: { currentEpoch: any },
poolAssets: any[],
prices: Promise<Prices>,
poolsWithAprAnd24HrVolume: any[],
): Promise<IncentivePoolInfo[]> => await (pools
? Promise.all(pools.map(async (pool) => {
? Promise.all(pools.map(async (pool: { staking_address: string; pool_id: any; swap_address: string }) => {
if (pool.staking_address === '') {
return {
poolId: pool.pool_id,
Expand All @@ -83,7 +86,7 @@ const getPoolFlowData = async (
const currentEpochId: number =
Number(currentEpochData?.currentEpoch?.epoch.id) || 0

let lockedLpShare
let lockedLpShare: number
try {
const weight = await client.queryContractSmart(pool.staking_address,
{
Expand Down Expand Up @@ -131,7 +134,10 @@ const getPoolFlowData = async (
flow.flow_asset.info?.token?.contract_addr ??
flow.flow_asset.info?.native_token?.denom

const emission = convertMicroDenomToDenom((Number(flow.flow_asset.amount) - emittedTokens) /
// Last entry of flow param asset history represents total flow amount, param only given if flow was expanded, otherwise we use amount of flow asset which is the initial flow amount
const amount = flow?.asset_history && flow?.asset_history?.length > 0 ? flow.asset_history[flow.asset_history.length - 1][Object.keys(flow.asset_history[flow.asset_history.length - 1])[0]] : flow.flow_asset.amount

const emission = convertMicroDenomToDenom((Number(amount) - emittedTokens) /
(flow.start_epoch +
(flow.end_epoch - flow.start_epoch) -
Number(currentEpochData.currentEpoch.epoch.id)),
Expand Down Expand Up @@ -169,7 +175,7 @@ const getPoolFlowData = async (
: [])

export const useIncentivePoolInfo = (
client, pools, currentChainPrefix,
client: CosmWasmClient, pools: any[], currentChainPrefix: string,
) => {
const { chainId, network } = useRecoilValue(chainState)
const config: Config = useConfig(network, chainId)
Expand Down
7 changes: 3 additions & 4 deletions components/Pages/Trade/Liquidity/hooks/useClosePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { useClients } from 'hooks/useClients'
import useTxStatus from 'hooks/useTxStatus'
import { usePoolFromListQueryById } from 'queries/usePoolsListQuery'
import { useRecoilValue } from 'recoil'
import { TerraTreasuryService } from 'services/treasuryService'
import { chainState } from 'state/chainState'
import { createExecuteMessage, validateTransactionSuccess } from 'util/messages/index'

import { TerraTreasuryService } from '../../../../../services/treasuryService'

type OpenPosition = {
poolId: string
}
Expand All @@ -25,7 +24,7 @@ export const useClosePosition = ({ poolId }: OpenPosition) => {
signingClient,
})

const createClosPositionMessage = (unbonding_duration: number) => {
const createClosePositionMessage = (unbonding_duration: number) => {
const msg = createExecuteMessage({
message: {
close_position: {
Expand All @@ -46,7 +45,7 @@ export const useClosePosition = ({ poolId }: OpenPosition) => {
}: {
unbonding_duration: number
}) => {
const msgs = createClosPositionMessage(unbonding_duration)
const msgs = createClosePositionMessage(unbonding_duration)
let fee:any = 'auto'
if (await signingClient.getChainId() === 'columbus-5') {
const gas = Math.ceil(await signingClient.simulate(
Expand Down
Loading