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
Prev Previous commit
Next Next commit
deposit events
onnovisser committed Aug 31, 2023
commit fa170272fb34f68de36f0c4d19b5f5d3c6ea9f21
Original file line number Diff line number Diff line change
@@ -455,6 +455,7 @@ function InvestForm({ onCancel, hasInvestment, autoFocus, investLabel = 'Invest'
return (
<Stack gap={2}>
<EpochBusy busy={state.isPoolBusy} />
{state.statusMessage && <InlineFeedback>{state.statusMessage}</InlineFeedback>}
{nativeBalanceTooLow && (
<InlineFeedback>
{state.nativeCurrency && `${state.nativeCurrency.symbol} balance is too low.`}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import * as React from 'react'
import { Dec } from '../../utils/Decimal'
import { useEvmTransaction } from '../../utils/tinlake/useEvmTransaction'
import { useAddress } from '../../utils/useAddress'
import { useLiquidityPoolInvestment, useLiquidityPools } from '../../utils/useLiquidityPools'
import { useLiquidityPoolInvestment, useLiquidityPools, useLPEvents } from '../../utils/useLiquidityPools'
import { usePendingCollect, usePool, usePoolMetadata } from '../../utils/usePools'
import { InvestRedeemContext } from './InvestRedeemProvider'
import { InvestRedeemAction, InvestRedeemActions, InvestRedeemProviderProps as Props, InvestRedeemState } from './types'
@@ -28,6 +28,8 @@ export function InvestRedeemLiquidityPoolsProvider({ poolId, trancheId, children
refetch: refetchInvest,
isLoading: isInvestmentLoading,
} = useLiquidityPoolInvestment(poolId, trancheId)

const { data: lpEvents } = useLPEvents(poolId, trancheId, lpInvest?.lpAddress)
const isAllowedToInvest = lpInvest?.isAllowedToInvest
const tranche = pool.tranches.find((t) => t.id === trancheId)
const { data: metadata, isLoading: isMetadataLoading } = usePoolMetadata(pool)
@@ -80,6 +82,12 @@ export function InvestRedeemLiquidityPoolsProvider({ poolId, trancheId, children
? 'redeem'
: pendingActionState
const pendingTransaction = pendingActionState && txActions[pendingActionState]?.lastCreatedTransaction
let statusMessage
if (order?.remainingInvestCurrency.isZero() && lpEvents?.find((e) => e.event === 'DepositRequested')) {
statusMessage = 'Investment order is currently being bridged and will show up soon'
} else if (order?.remainingRedeemToken.isZero() && lpEvents?.find((e) => e.event === 'RedeemRequested')) {
statusMessage = 'Redemption order is currently being bridged and will show up soon'
}

function doAction<T = any>(
name: InvestRedeemAction,
@@ -155,6 +163,7 @@ export function InvestRedeemLiquidityPoolsProvider({ poolId, trancheId, children
canChangeOrder: false,
pendingAction,
pendingTransaction,
statusMessage,
}

const actions: InvestRedeemActions = {
1 change: 1 addition & 0 deletions centrifuge-app/src/components/InvestRedeem/types.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ export type InvestRedeemState = {
canChangeOrder: boolean
pendingAction?: InvestRedeemAction | null
pendingTransaction?: Transaction | null
statusMessage?: string
}

export type ActionOptions = {
22 changes: 15 additions & 7 deletions centrifuge-app/src/pages/IssuerPool/Investors/LiquidityPools.tsx
Original file line number Diff line number Diff line change
@@ -64,14 +64,22 @@ function EnableButton({ poolId, chainId }: { poolId: string; chainId: number })
const { data: isEnabled, isLoading: isFetching } = useQuery(
['poolLps', poolId],
async () => {
const results = await Promise.allSettled(
pool.tranches.map((t) =>
cent.liquidityPools.getLiquidityPools([managerAddress!, poolId, t.id], {
rpcProvider: getProvider(chainId),
})
try {
await Promise.any(
pool.tranches.map((t) =>
cent.liquidityPools
.getLiquidityPools([managerAddress!, poolId, t.id], {
rpcProvider: getProvider(chainId),
})
.then((r) => {
if (!r.length) throw new Error('tranche not enabled')
})
)
)
)
return results.some((result) => result.status === 'fulfilled' && result.value.length > 0)
return true
} catch {
return false
}
},
{
enabled: !!managerAddress,
22 changes: 22 additions & 0 deletions centrifuge-app/src/utils/useLiquidityPools.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,28 @@ export function useLiquidityPools(poolId: string, trancheId: string) {
return query
}

export function useLPEvents(poolId: string, trancheId: string, lpAddress?: string) {
const {
evm: { chainId, getProvider, selectedAddress },
} = useWallet()
const cent = useCentrifuge()
const { data: lps } = useLiquidityPools(poolId, trancheId)
const lp = lps?.find((l) => l.lpAddress === lpAddress)

const query = useQuery(
['lpDepositedEvents', chainId, lp?.lpAddress, selectedAddress],
() =>
cent.liquidityPools.getRecentLPEvents([lp!.lpAddress, selectedAddress!], {
rpcProvider: getProvider(chainId!),
}),

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

export function useLiquidityPoolInvestment(poolId: string, trancheId: string, lpIndex?: number) {
const {
evm: { chainId, getProvider, selectedAddress },
26 changes: 22 additions & 4 deletions centrifuge-js/src/modules/liquidityPools.ts
Original file line number Diff line number Diff line change
@@ -45,6 +45,10 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
)
}

function getProvider(options?: EvmQueryOptions) {
return options?.rpcProvider ?? inst.config.evmSigner?.provider
}

function enablePoolOnDomain(args: [poolId: string, chainId: number], options?: TransactionOptions) {
const [poolId, chainId] = args
const $api = inst.getApi()
@@ -168,12 +172,25 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {

async function getManagerFromRouter(args: [router: string], options?: EvmQueryOptions) {
const [router] = args
return '0x91924F801C8989fbaaa4F4CDf96adfb8ad5014d8'
return '0xa83BF9425E84BCf915691e193c154FB90DfeaA1c'
const gatewayAddress = await contract(router, ABI.Router, options).gateway()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this gateway do/facilitate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it manages the routers and handles the incoming/outgoing messages

const managerAddress = await contract(gatewayAddress, ABI.Gateway, options).investmentManager()
return managerAddress as string
}

async function getRecentLPEvents(args: [lpAddress: string, user: string], options?: EvmQueryOptions) {
const [lpAddress, user] = args
const blockNumber = await getProvider(options)!.getBlockNumber()
const cont = contract(lpAddress, ABI.LiquidityPool, options)
const depositFilter = cont.filters.DepositRequested(user)
const redeemFilter = cont.filters.RedeemRequested(user)
const events = await Promise.all([
cont.queryFilter(depositFilter, blockNumber - 300),
cont.queryFilter(redeemFilter, blockNumber - 300),
])
return events.flat()
}

async function getPool(args: [connector: string, poolId: string], options?: EvmQueryOptions) {
const [connector, poolId] = args
const calls: Call[] = [
@@ -184,7 +201,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
},
]
const pool = await multicall<{ poolId: string; createdAt: number; isActive: boolean }>(calls, {
rpcProvider: options?.rpcProvider ?? inst.config.evmSigner?.provider!,
rpcProvider: getProvider(options)!,
})
return pool
}
@@ -200,7 +217,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
// trancheId
// )

const lps = ['0x4E683165ACcbBCF95dAe7c4e77359c3a8C666cC6']
const lps = ['0x6627eC6b0e467D02117bE6949189054102EAe177']

const assetData = await multicall<{ assets?: string[]; share: string }>(
[
@@ -220,7 +237,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
},
],
{
rpcProvider: options?.rpcProvider ?? inst.config.evmSigner?.provider!,
rpcProvider: getProvider(options)!,
}
)

@@ -384,5 +401,6 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
getPool,
getLiquidityPools,
getLiquidityPoolInvestment,
getRecentLPEvents,
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
"event DepositRequested(address indexed, uint256)",
"event RedeemRequested(address indexed, uint256)",
"function mint(uint256, address) public returns (uint256)",
"function withdraw(uint256, address, address) public returns (uint256)",
"function requestDeposit(uint256, address) public",