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

Centrifuge App: Liquidity pools investments #1542

Merged
merged 69 commits into from
Oct 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d91787f
lp module
onnovisser Aug 18, 2023
3a029c7
collect
onnovisser Aug 18, 2023
02f22fb
invest redeem provider
onnovisser Aug 22, 2023
c7b09ad
add domain deploy table
onnovisser Aug 22, 2023
2f5cb43
mint
onnovisser Aug 23, 2023
5c0bf82
redeem
onnovisser Aug 24, 2023
da457b8
reduce abi
onnovisser Aug 24, 2023
725c194
Merge commit 'e5beac5a96e37fc649d00b3ac09f681e6199fddb' into liquidit…
onnovisser Aug 25, 2023
fa41c78
fix dialog networks
onnovisser Aug 25, 2023
07ca9eb
cancel order
onnovisser Aug 25, 2023
b2d9bd4
remove logs
onnovisser Aug 25, 2023
8711ca4
cleanup
onnovisser Aug 25, 2023
f6ff35e
fix allowance
onnovisser Aug 29, 2023
148b004
permit
onnovisser Aug 29, 2023
a0991ce
abi
onnovisser Aug 29, 2023
1a23c4c
fix permit tx
onnovisser Aug 30, 2023
6aee9d7
tranche token permit
onnovisser Aug 30, 2023
fa17027
deposit events
onnovisser Aug 31, 2023
83e503a
get liquidity pools refactor
onnovisser Aug 31, 2023
17cdf52
add allow currency to batch
onnovisser Sep 4, 2023
9fa64a8
fix select
onnovisser Sep 7, 2023
a7a0c9c
Merge branch 'main' into liquidity-pools-investments
onnovisser Sep 7, 2023
61b648f
account picker
onnovisser Sep 7, 2023
8995946
foreign asset fix
onnovisser Sep 12, 2023
e705612
merge main
onnovisser Sep 12, 2023
6799e43
picker fix
onnovisser Sep 12, 2023
198b9e6
swap orders
onnovisser Sep 12, 2023
d4b8091
foreign asset fix
onnovisser Sep 12, 2023
d30957d
swap page
onnovisser Sep 12, 2023
0c13ef9
currency meta
onnovisser Sep 12, 2023
2adde1d
fix
onnovisser Sep 12, 2023
a955e44
api changes
onnovisser Sep 14, 2023
629f7ef
merge main
onnovisser Sep 15, 2023
8c67bd9
merge main
onnovisser Sep 15, 2023
39d711c
get currency ids
onnovisser Sep 16, 2023
5be33b4
remove mocked data
onnovisser Sep 16, 2023
59cc554
fix evm conversion
onnovisser Sep 18, 2023
33ed728
fix loading
onnovisser Sep 18, 2023
71781df
fix validation
onnovisser Sep 18, 2023
f82315c
pending order
onnovisser Sep 18, 2023
8a02615
disable cancel
onnovisser Sep 18, 2023
697e68f
point to moonbase
onnovisser Sep 18, 2023
34437d9
update base logo
onnovisser Sep 18, 2023
4ddcc25
fix empty pool loans
onnovisser Sep 18, 2023
77d5adc
withdraw button
onnovisser Sep 18, 2023
1a004a2
add arbitrum
onnovisser Sep 18, 2023
9d40002
arbitrum debug flag
onnovisser Sep 18, 2023
703adbb
remove withdraw
onnovisser Sep 18, 2023
fae38b3
merge swaps
onnovisser Sep 18, 2023
b5cf966
fix chain id
onnovisser Sep 18, 2023
a754421
small fixes
onnovisser Sep 18, 2023
36e684b
account conversion
onnovisser Sep 21, 2023
66d6f5d
typo
onnovisser Sep 21, 2023
abce46e
dialog
onnovisser Sep 21, 2023
7988cd9
update domain member
onnovisser Sep 26, 2023
fc418f7
fix update member
onnovisser Sep 26, 2023
3a2ce95
fix update member
onnovisser Sep 26, 2023
f857b6c
deploy pools
onnovisser Sep 29, 2023
8884a1b
deploy tranche/lps
onnovisser Sep 29, 2023
4fdef08
add currency
onnovisser Oct 2, 2023
e396c36
merge main
onnovisser Oct 2, 2023
344b1fe
merge main
onnovisser Oct 4, 2023
5b611a0
Merge commit 'f19d396d1078ae1965bc309181fd0f565679b962' into liquidit…
onnovisser Oct 25, 2023
95df0e2
remove debug
onnovisser Oct 25, 2023
9c8bc0b
contract changes
onnovisser Oct 25, 2023
a94748e
contract changes
onnovisser Oct 27, 2023
1d545b2
permit amount
onnovisser Oct 27, 2023
702f28e
cancel order
onnovisser Oct 30, 2023
151a886
Merge branch 'main' into liquidity-pools-investments
onnovisser Oct 30, 2023
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
Next Next commit
lp module
onnovisser committed Aug 18, 2023

Verified

This commit was signed with the committer’s verified signature.
onnovisser Onno Visser
commit d91787ff2b663af8e0fdad2f1e29278e0e47db91
281 changes: 148 additions & 133 deletions centrifuge-app/src/components/InvestRedeem/InvestRedeem.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -23,9 +23,7 @@ export function InvestRedeemCentrifugeProvider({ poolId, trancheId, children }:
const tranche = pool.tranches.find((t) => t.id === trancheId)
const { data: metadata, isLoading: isMetadataLoading } = usePoolMetadata(pool)
const trancheMeta = metadata?.tranches?.[trancheId]
const {
state: { combinedStakes },
} = useLiquidityRewards()
const combinedStakes = useLiquidityRewards().state?.combinedStakes

if (!tranche) throw new Error(`Token not found. Pool id: ${poolId}, token id: ${trancheId}`)

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useWallet } from '@centrifuge/centrifuge-react'
import * as React from 'react'
import { InvestRedeemCentrifugeProvider } from './InvestRedeemCentrifugeProvider'
import { InvestRedeemLiquidityPoolsProvider } from './InvestRedeemLiquidityPoolsProvider'
import { InvestRedeemTinlakeProvider } from './InvestRedeemTinlakeProvider'
import { InvestRedeemContext as InvestRedeemContextType, InvestRedeemProviderProps as Props } from './types'

@@ -13,7 +15,12 @@ export function useInvestRedeem() {

export function InvestRedeemProvider(props: Props) {
const isTinlakePool = props.poolId.startsWith('0x')
const Comp = isTinlakePool ? InvestRedeemTinlakeProvider : InvestRedeemCentrifugeProvider
const { connectedType, isEvmOnSubstrate } = useWallet()
const Comp = isTinlakePool
? InvestRedeemTinlakeProvider
: connectedType === 'evm' && !isEvmOnSubstrate
? InvestRedeemLiquidityPoolsProvider
: InvestRedeemCentrifugeProvider

return <Comp {...props} />
}
Original file line number Diff line number Diff line change
@@ -10,14 +10,15 @@ import { LiquidityRewardsContext } from './LiquidityRewardsContext'
import { LiquidityRewardsActions, LiquidityRewardsProviderProps, LiquidityRewardsState } from './types'

export function LiquidityRewardsProvider(props: LiquidityRewardsProviderProps) {
// const { connectedType, isEvmOnSubstrate } = useWallet()
const isTinlakePool = props.poolId.startsWith('0x')
return !isTinlakePool ? <Provider {...props} /> : <>{props.children}</>
}

function Provider({ poolId, trancheId, children }: LiquidityRewardsProviderProps) {
const pool = usePool(poolId) as Pool
const consts = useCentrifugeConsts()
const address = useAddress()
const address = useAddress('substrate')
const order = usePendingCollect(poolId, trancheId, address)
const stakes = useAccountStakes(address, poolId, trancheId)
const rewards = useComputeLiquidityRewards(address, poolId, trancheId)
1 change: 0 additions & 1 deletion centrifuge-app/src/components/LiquidityRewards/hooks.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ export function useAccountStakes(address?: string, poolId?: string, trancheId?:
['stakes', address, poolId, trancheId],
(cent) => cent.rewards.getAccountStakes([address!, poolId!, trancheId!]),
{
suspense: true,
enabled: !!address && !!poolId && !!trancheId,
}
)
9 changes: 1 addition & 8 deletions centrifuge-app/src/pages/Pool/Overview/index.tsx
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import { PageWithSideBar } from '../../../components/PageWithSideBar'
import { PoolToken } from '../../../components/PoolToken'
import { Spinner } from '../../../components/Spinner'
import { Tooltips } from '../../../components/Tooltips'
import { ethConfig } from '../../../config'
import { formatDate, getAge } from '../../../utils/date'
import { Dec } from '../../../utils/Decimal'
import { formatBalance, formatBalanceAbbreviated, formatPercentage } from '../../../utils/formatting'
@@ -65,13 +64,7 @@ export function PoolDetailSideBar({
const { pid: poolId } = useParams<{ pid: string }>()

return (
<InvestRedeem
poolId={poolId}
trancheId={selectedToken}
onSetTrancheId={setSelectedToken}
networks={poolId.startsWith('0x') ? [ethConfig.network === 'goerli' ? 5 : 1] : ['centrifuge']}
actionsRef={investRef}
/>
<InvestRedeem poolId={poolId} trancheId={selectedToken} onSetTrancheId={setSelectedToken} actionsRef={investRef} />
)
}

3 changes: 1 addition & 2 deletions centrifuge-app/src/utils/useAddress.ts
Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@ import { useDebugFlags } from '../components/DebugFlags'

export function useAddress(typeOverride?: 'substrate' | 'evm') {
const { address: debugSubstrateAddress, evmAddress: debugEvmAddress } = useDebugFlags()
const { connectedType } = useWallet()
const address = useWalletAddress(typeOverride)
const { isEvmOnSubstrate } = useWallet()
const debugAddress =
typeOverride === 'evm' || (connectedType === 'evm' && !isEvmOnSubstrate) ? debugEvmAddress : debugSubstrateAddress
typeOverride === 'evm' || (!typeOverride && !isEvmOnSubstrate) ? debugEvmAddress : debugSubstrateAddress

return (debugAddress as string) || address
}
111 changes: 111 additions & 0 deletions centrifuge-app/src/utils/useLiquidityPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { useCentrifuge, useCentrifugeQuery, useWallet } from '@centrifuge/centrifuge-react'
import { useQuery } from 'react-query'

export function useDomainRouters() {
const [data] = useCentrifugeQuery(['domainRouters'], (cent) => cent.liquidityPools.getDomainRouters())

return data
}

export function useActiveDomains(poolId: string) {
const {
evm: { getProvider },
} = useWallet()
const cent = useCentrifuge()
const routers = useDomainRouters()
const query = useQuery(
['activeDomains', poolId, routers?.length],
async () => {
// const results = await Promise.allSettled(
// routers!.map(async (r) => {
// const manager = await cent.liquidityPools.getManagerFromRouter([r.router], {
// rpcProvider: getProvider(r.chainId),
// })
// const pool = await cent.liquidityPools.getPool([manager, poolId], { rpcProvider: getProvider(r.chainId) })
// return [manager, pool] as const
// })
// )
// console.log('res', results)
// return results!
// .map((result, i) => {
// if (result.status === 'rejected') return null
// const [manager, pool] = result.value
// const router = routers![i]
// if (!pool.isActive) return null
// return {
// chainId: router.chainId,
// managerAddress: manager,
// }
// })
// .filter(Boolean) as {
// chainId: number
// managerAddress: string
// }[]
return [
{
chainId: 5,
managerAddress: '0xB21A283d9317907e6437b1136b0e937baB89343b',
},
]
},
{
enabled: !!routers?.length && !poolId.startsWith('0x'),
staleTime: Infinity,
}
)

return query
}

export function useLiquidityPools(poolId: string, trancheId: string) {
const {
evm: { chainId, getProvider },
} = useWallet()
const cent = useCentrifuge()
const { data: domains } = useActiveDomains(poolId)
const managerAddress = domains?.find((d) => d.chainId === chainId)?.managerAddress

const query = useQuery(
['lps', poolId, trancheId, chainId],
() =>
cent.liquidityPools.getLiquidityPools([managerAddress!, poolId, trancheId], {
rpcProvider: getProvider(chainId!),
}),
{
enabled: !!managerAddress,
staleTime: Infinity,
}
)

return query
}

export function useLiquidityPoolInvestment(poolId: string, trancheId: string, lpIndex?: number) {
const {
evm: { chainId, getProvider, selectedAddress },
} = useWallet()
const cent = useCentrifuge()
const { data: domains } = useActiveDomains(poolId)
const managerAddress = domains?.find((d) => d.chainId === chainId)?.managerAddress

const { data: lps } = useLiquidityPools(poolId, trancheId)
const lp = lps?.[lpIndex ?? 0]

const query = useQuery(
['lpInvestment', chainId, lp?.lpAddress, selectedAddress],
async () => ({
...(await cent.liquidityPools.getLiquidityPoolInvestment([selectedAddress!, managerAddress!, lp!.lpAddress], {
rpcProvider: getProvider(chainId!),
})),
...lp!,
}),

{
enabled: !!lp && !!selectedAddress,
}
)

console.log('lpInvest', query.data)

return query
}
6 changes: 5 additions & 1 deletion centrifuge-js/package.json
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@
"lint": "eslint src/**/*.ts"
},
"dependencies": {
"@ethersproject/abi": "^5.6.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.6.0",
"@ethersproject/providers": "^5.6.0",
"@ethersproject/units": "^5.6.0",
@@ -36,11 +38,13 @@
"clp-wasm": "^0.0.15",
"decimal.js-light": "^2.5.1",
"isomorphic-fetch": "^3.0.0",
"jw3t": "^1.0.8"
"jw3t": "^1.0.8",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^27.0.3",
"@types/lodash": "^4",
"@types/node": "^16.11.12",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
2 changes: 2 additions & 0 deletions centrifuge-js/src/Centrifuge.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { AddressOrPair } from '@polkadot/api/types'
import { Signer } from '@polkadot/types/types'
import { CentrifugeBase, UserProvidedConfig } from './CentrifugeBase'
import { getAuthModule } from './modules/auth'
import { getLiquidityPoolsModule } from './modules/liquidityPools'
import { getMetadataModule } from './modules/metadata'
import { getMultisigModule } from './modules/multisig'
import { getNftsModule } from './modules/nfts'
@@ -18,6 +19,7 @@ import { getUtilsModule } from './modules/utils'
export class Centrifuge extends CentrifugeBase {
nfts = getNftsModule(this)
pools = getPoolsModule(this)
liquidityPools = getLiquidityPoolsModule(this)
utils = getUtilsModule(this)
proxies = getProxiesModule(this)
metadata = getMetadataModule(this)
Loading