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
Show file tree
Hide file tree
Changes from 67 commits
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
2 changes: 1 addition & 1 deletion centrifuge-app/.env-config/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ REACT_APP_WHITELISTED_ACCOUNTS=
REACT_APP_TINLAKE_SUBGRAPH_URL=https://graph.centrifuge.io/tinlake
REACT_APP_REWARDS_TREE_URL=https://storage.googleapis.com/rad-rewards-trees-kovan-staging/latest.json
REACT_APP_WALLETCONNECT_ID=c32fa79350803519804a67fcab0b742a
REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY=kAJ27w29x7gHM75xajP2yXVLjVBaKmmUTxHwgRuCoAcWaoEiz
REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY=kAJ27w29x7gHM75xajP2yXVLjVBaKmmUTxHwgRuCoAcWaoEiz
214 changes: 214 additions & 0 deletions centrifuge-app/src/components/DebugFlags/components/ConvertAddress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { addressToHex } from '@centrifuge/centrifuge-js'
import {
getChainInfo,
truncateAddress,
useCentrifugeApi,
useCentrifugeUtils,
useWallet,
} from '@centrifuge/centrifuge-react'
import { Dialog, Grid, Select, Stack, Text, TextInput } from '@centrifuge/fabric'
import { isAddress as isEvmAddress } from '@ethersproject/address'
import { isAddress as isSubstrateAddress } from '@polkadot/util-crypto'
import * as React from 'react'
import { useQuery } from 'react-query'
import { firstValueFrom } from 'rxjs'
import { copyToClipboard } from '../../../utils/copyToClipboard'

enum LocationType {
Parachain = 'Parachain',
Relaychain = 'Relaychain',
Native = 'Native',
EVM = 'EVM',
}

export function ConvertAddress() {
const [open, setOpen] = React.useState(false)
const {
evm: { accounts: evmAccounts, chains },
substrate: { accounts: substrateAccounts },
} = useWallet()

const [address, setAddress] = React.useState('')
const [locationType, setLocationType] = React.useState<LocationType>(LocationType.Parachain)
const [locationDetail, setLocationDetail] = React.useState('')
const utils = useCentrifugeUtils()
const api = useCentrifugeApi()
const addressListId = React.useId()
const locationListId = React.useId()
const isValidAddress =
locationType === LocationType.EVM
? isEvmAddress(address)
: locationType === LocationType.Parachain
? isSubstrateAddress(address) || isEvmAddress(address)
: !isEvmAddress(address) && isSubstrateAddress(address)

function getMultilocation() {
if (!isValidAddress) return null
switch (locationType) {
case LocationType.Parachain:
if (!locationDetail) return null
return {
parents: 1,
interior: {
X2: [
{
Parachain: locationDetail,
},
isEvmAddress(address)
? {
AccountKey20: {
network: null,
key: address,
},
}
: {
AccountId32: {
id: addressToHex(address),
},
},
],
},
}
case LocationType.Relaychain:
return {
parents: 1,
interior: {
X1: {
AccountId32: {
id: addressToHex(address),
},
},
},
}
case LocationType.Native:
return {}
case LocationType.EVM:
if (!locationDetail) return null
return {
parents: 0,
interior: {
X1: {
AccountKey20: {
network: { Ethereum: { chainId: locationDetail } },
key: address,
},
},
},
}
}
}

const multilocation = getMultilocation()

const { data: convertedAddress } = useQuery(
[address, locationType, locationDetail],
async () => {
if (locationType === LocationType.Native) return address
const addr = await firstValueFrom(api.call.accountConversionApi.conversionOf(multilocation))
return addr.toHuman() as string
},
{
enabled: !!address && !!multilocation && isValidAddress,
staleTime: Infinity,
}
)

return (
<>
<button onClick={() => setOpen(true)}>Convert address</button>
<Dialog title="Convert address" width="800px" isOpen={open} onClose={() => setOpen(false)}>
<Stack gap={4}>
<Stack gap={1}>
<datalist id={addressListId}>
{evmAccounts?.map((addr) => (
<option value={addr}>{truncateAddress(addr)} (EVM)</option>
))}
{substrateAccounts?.map((acc) => (
<option value={utils.formatAddress(acc.address)}>
{acc.name && `${acc.name} - `}
{truncateAddress(utils.formatAddress(acc.address))}
</option>
))}
</datalist>
<Select
label="From"
value={locationType}
options={[
{ label: 'Parachain', value: LocationType.Parachain },
{ label: 'Relaychain', value: LocationType.Relaychain },
{ label: 'Native', value: LocationType.Native },
{ label: 'EVM', value: LocationType.EVM },
]}
onChange={(e) => {
setLocationType(e.target.value as any)
}}
/>
{locationType === LocationType.EVM ? (
<>
<TextInput
label="EVM chain ID"
value={locationDetail}
onChange={(e) => setLocationDetail(e.target.value)}
list={locationListId}
/>
<datalist id={locationListId}>
{Object.keys(chains).map((chainId) => (
<option value={chainId}>
{chainId} - {getChainInfo(chains, Number(chainId)).name}
</option>
))}
</datalist>
</>
) : locationType === LocationType.Parachain ? (
<>
<TextInput
label="Para ID"
value={locationDetail}
onChange={(e) => setLocationDetail(e.target.value)}
list={locationListId}
/>
<datalist id={locationListId}></datalist>
</>
) : null}

<TextInput
label={
locationType === LocationType.EVM
? 'EVM address'
: locationType === LocationType.Parachain
? 'Substrate or EVM address'
: 'Substrate address'
}
value={address}
onChange={(e) => setAddress(e.target.value)}
list={addressListId}
errorMessage={address && !isValidAddress ? 'Invalid address' : ''}
/>
</Stack>
{convertedAddress && (
<Stack gap={2}>
<Text variant="heading3">Converted address</Text>
<Grid columns={2} gap={1}>
<Text variant="label1">ss58</Text>
<Text
style={{ wordBreak: 'break-all', cursor: 'copy' }}
onClick={() => copyToClipboard(utils.formatAddress(convertedAddress))}
>
{utils.formatAddress(convertedAddress)}
</Text>

<Text variant="label1">hex</Text>
<Text
style={{ wordBreak: 'break-all', cursor: 'copy' }}
onClick={() => copyToClipboard(addressToHex(convertedAddress))}
>
{addressToHex(convertedAddress)}
</Text>
</Grid>
</Stack>
)}
</Stack>
</Dialog>
</>
)
}

This file was deleted.

33 changes: 27 additions & 6 deletions centrifuge-app/src/components/DebugFlags/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { config } from '../../config'
import { ConvertEvmAddress } from './components/ConvertEvmAddress'
import { config, isTestEnv } from '../../config'
import { ConvertAddress } from './components/ConvertAddress'

const params = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : {})
export const debug =
Expand Down Expand Up @@ -36,6 +36,7 @@ export type Key =
| 'batchMintNFTs'
| 'persistDebugFlags'
| 'showBase'
| 'showArbitrum'
| 'showUnusedFlags'
| 'allowInvestBelowMin'
| 'alternativeTheme'
Expand All @@ -45,8 +46,11 @@ export type Key =
| 'showAdvancedAccounts'
| 'editAdminConfig'
| 'showPodAccountCreation'
| 'convertEvmAddress'
| 'convertAddress'
| 'showPortfolio'
| 'showTestNets'
| 'showSwaps'
| 'showLiquidityPoolsOptions'
| 'poolCreationType'

export const flagsConfig: Record<Key, DebugFlagConfig> = {
Expand Down Expand Up @@ -76,6 +80,16 @@ export const flagsConfig: Record<Key, DebugFlagConfig> = {
default: false,
alwaysShow: true,
},
showArbitrum: {
type: 'checkbox',
default: false,
alwaysShow: true,
},
showTestNets: {
type: 'checkbox',
default: isTestEnv,
alwaysShow: true,
},
editPoolConfig: {
type: 'checkbox',
default: false,
Expand All @@ -84,6 +98,10 @@ export const flagsConfig: Record<Key, DebugFlagConfig> = {
type: 'checkbox',
default: false,
},
showLiquidityPoolsOptions: {
type: 'checkbox',
default: false,
},
poolReporting: {
type: 'checkbox',
default: false,
Expand All @@ -110,16 +128,19 @@ export const flagsConfig: Record<Key, DebugFlagConfig> = {
default: false,
alwaysShow: true,
},
convertEvmAddress: {
convertAddress: {
type: 'component',
Component: ConvertEvmAddress,
Component: ConvertAddress,
default: null,
alwaysShow: true,
},
showPortfolio: {
type: 'checkbox',
default: false,
alwaysShow: true,
},
showSwaps: {
type: 'checkbox',
default: false,
},
poolCreationType: {
type: 'select',
Expand Down
Loading
Loading