Skip to content

Commit

Permalink
Earn protocol WIP #21 (#560)
Browse files Browse the repository at this point in the history
Co-authored-by: sebastianPiekarczyk <sebastian@oazoapps.com>
  • Loading branch information
marcinciarka and piekczyk authored Nov 7, 2024
1 parent 6034d72 commit 3b3ab7e
Show file tree
Hide file tree
Showing 45 changed files with 667 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const NavigationWrapper: FC = () => {
id: 'explore',
itemsList: [
{
url: '/user-activity',
url: '/earn/user-activity',
id: 'user-activity',
title: 'User activity',
description: 'Text for user activity',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { portfolioRewardsHandler } from '@/app/server-handlers/portfolio/portfolio-rewards-handler'
import { portfolioWalletAssetsHandler } from '@/app/server-handlers/portfolio/portfolio-wallet-assets-handler'
import { getUserPositions } from '@/app/server-handlers/sdk/get-user-positions'
import { getVaultsList } from '@/app/server-handlers/sdk/get-vaults-list'
import { PortfolioPageView } from '@/components/layout/PortfolioPageView/PortfolioPageView'

type PortfolioPageProps = {
params: {
wallet_address: string
walletAddress: string
}
}

const PortfolioPage = async ({ params }: PortfolioPageProps) => {
const walletAddress = params.wallet_address
const { walletAddress } = params

const [walletData, { vaults }] = await Promise.all([
const [walletData, { vaults }, positions] = await Promise.all([
portfolioWalletAssetsHandler(walletAddress),
await getVaultsList(),
await getUserPositions({ walletAddress }),
])
const rewardsData = portfolioRewardsHandler(walletAddress)

return (
<PortfolioPageView
positions={positions ?? []}
walletAddress={walletAddress}
walletData={walletData}
rewardsData={rewardsData}
Expand Down
2 changes: 1 addition & 1 deletion apps/earn-protocol/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function HomePage() {
}}
>
<Text as="p" variant="p2">
I love you ❤️❤️
I love you ❤️
<br /> <br />
BTW you are probably looking for the{' '}
<Link href="/earn" style={{ display: 'inline', color: 'var(--color-text-link)' }}>
Expand Down
37 changes: 37 additions & 0 deletions apps/earn-protocol/app/server-handlers/sdk/get-user-positions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { sdkSupportedNetworks } from '@summerfi/app-types'
import { type IArmadaPosition } from '@summerfi/sdk-client-react'
import { Address, getChainInfoByChainId, User, Wallet } from '@summerfi/sdk-common'

import { backendSDK } from '@/app/server-handlers/sdk/sdk-backend-client'

export async function getUserPositions({ walletAddress }: { walletAddress: string }) {
try {
const userPositionsAllNetworksCalls = await Promise.all(
sdkSupportedNetworks.map(async (chainId) => {
const chainInfo = getChainInfoByChainId(chainId)

const wallet = Wallet.createFrom({
address: Address.createFromEthereum({
value: walletAddress.toLowerCase(),
}),
})
const user = User.createFrom({
chainInfo,
wallet,
})

return await backendSDK.armada.users.getUserPositions({
user,
})
}),
)

const positionsList = userPositionsAllNetworksCalls
.filter(Boolean)
.reduce((acc, position) => [...acc, ...position], [])

return positionsList as IArmadaPosition[] | undefined
} catch (error) {
throw new Error(`Failed to get users positions: ${error}`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const NavigationWrapper: FC = () => {
id: 'explore',
itemsList: [
{
url: '/user-activity',
url: '/earn/user-activity',
id: 'user-activity',
title: 'User activity',
description: 'Text for user activity',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { type FC } from 'react'
import { TabBar } from '@summerfi/app-earn-ui'
import { type SDKVaultsListType } from '@summerfi/app-types'
import { type IArmadaPosition } from '@summerfi/sdk-client-react'

import { type PortfolioRewardsRawData } from '@/app/server-handlers/portfolio/portfolio-rewards-handler'
import { type PortfolioAssetsResponse } from '@/app/server-handlers/portfolio/portfolio-wallet-assets-handler'
Expand All @@ -17,19 +18,21 @@ interface PortfolioPageViewProps {
walletData: PortfolioAssetsResponse
rewardsData: PortfolioRewardsRawData[]
vaultsList: SDKVaultsListType
positions: IArmadaPosition[]
}

export const PortfolioPageView: FC<PortfolioPageViewProps> = ({
walletAddress,
walletData,
rewardsData,
vaultsList,
positions,
}) => {
const tabs = [
{
id: 'overview',
label: 'Overview',
content: <PortfolioOverview vaultsList={vaultsList} />,
content: <PortfolioOverview positions={positions} vaultsList={vaultsList} />,
},
{
id: 'wallet',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import {
type SDKUsersActivityType,
type SDKVaultishType,
type SDKVaultsListType,
type SDKVaultType,
type UsersActivity,
} from '@summerfi/app-types'
import { type IArmadaPosition, SDKContextProvider } from '@summerfi/sdk-client-react'
Expand All @@ -19,7 +19,7 @@ export const VaultManageView = ({
topDepositors,
viewWalletAddress,
}: {
vault: SDKVaultishType
vault: SDKVaultType
vaults: SDKVaultsListType
position: IArmadaPosition
userActivity: UsersActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ import {
import {
type DropdownOption,
type SDKUsersActivityType,
type SDKVaultishType,
type SDKVaultsListType,
type SDKVaultType,
type TokenSymbolsList,
type UsersActivity,
} from '@summerfi/app-types'
import { formatCryptoBalance } from '@summerfi/app-utils'
import { type IArmadaPosition } from '@summerfi/sdk-client-react'
import { capitalize } from 'lodash-es'

import { vaultExposureRawData } from '@/components/layout/VaultOpenView/mocks'
import { TransactionHashPill } from '@/components/molecules/TransactionHashPill/TransactionHashPill'
import { HistoricalYieldChart } from '@/components/organisms/Charts/HistoricalYieldChart'
import { RebalancingActivity } from '@/components/organisms/RebalancingActivity/RebalancingActivity'
import { UserActivity } from '@/components/organisms/UserActivity/UserActivity'
import { VaultExposure } from '@/components/organisms/VaultExposure/VaultExposure'
import { TransactionAction } from '@/constants/transaction-actions'
import { RebalancingActivity } from '@/features/rebalance-activity/components/RebalancingActivity/RebalancingActivity'
import { UserActivity } from '@/features/user-activity/components/UserActivity/UserActivity'
import { VaultExposure } from '@/features/vault-exposure/components/VaultExposure/VaultExposure'
import { useAmount } from '@/hooks/use-amount'
import { useClient } from '@/hooks/use-client'
import { useTransaction } from '@/hooks/use-transaction'
Expand All @@ -45,7 +44,7 @@ export const VaultManageViewComponent = ({
topDepositors,
viewWalletAddress,
}: {
vault: SDKVaultishType
vault: SDKVaultType
vaults: SDKVaultsListType
position: IArmadaPosition
userActivity: UsersActivity
Expand Down Expand Up @@ -181,7 +180,7 @@ export const VaultManageViewComponent = ({
}
defaultExpanded
>
<VaultExposure rawData={vaultExposureRawData} />
<VaultExposure vault={vault} />
</Expander>
<Expander
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import {
type SDKUsersActivityType,
type SDKVaultishType,
type SDKVaultsListType,
type SDKVaultType,
type UsersActivity,
} from '@summerfi/app-types'
import { SDKContextProvider } from '@summerfi/sdk-client-react'
Expand All @@ -17,7 +17,7 @@ export const VaultOpenView = ({
userActivity,
topDepositors,
}: {
vault: SDKVaultishType
vault: SDKVaultType
vaults: SDKVaultsListType
userActivity: UsersActivity
topDepositors: SDKUsersActivityType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ import {
import {
type DropdownOption,
type SDKUsersActivityType,
type SDKVaultishType,
type SDKVaultsListType,
type SDKVaultType,
type TokenSymbolsList,
type UsersActivity,
} from '@summerfi/app-types'
import { formatCryptoBalance } from '@summerfi/app-utils'
import { capitalize } from 'lodash-es'

import { detailsLinks, vaultExposureRawData } from '@/components/layout/VaultOpenView/mocks'
import { detailsLinks } from '@/components/layout/VaultOpenView/mocks'
import { VaultOpenHeaderBlock } from '@/components/layout/VaultOpenView/VaultOpenHeaderBlock'
import { VaultSimulationGraph } from '@/components/layout/VaultOpenView/VaultSimulationGraph'
import { TransactionHashPill } from '@/components/molecules/TransactionHashPill/TransactionHashPill'
import { HistoricalYieldChart } from '@/components/organisms/Charts/HistoricalYieldChart'
import { RebalancingActivity } from '@/components/organisms/RebalancingActivity/RebalancingActivity'
import { UserActivity } from '@/components/organisms/UserActivity/UserActivity'
import { VaultExposure } from '@/components/organisms/VaultExposure/VaultExposure'
import { TransactionAction } from '@/constants/transaction-actions'
import { RebalancingActivity } from '@/features/rebalance-activity/components/RebalancingActivity/RebalancingActivity'
import { UserActivity } from '@/features/user-activity/components/UserActivity/UserActivity'
import { VaultExposure } from '@/features/vault-exposure/components/VaultExposure/VaultExposure'
import { useAmount } from '@/hooks/use-amount'
import { useClient } from '@/hooks/use-client'
import { usePosition } from '@/hooks/use-position'
Expand All @@ -44,7 +44,7 @@ export const VaultOpenViewComponent = ({
userActivity,
topDepositors,
}: {
vault: SDKVaultishType
vault: SDKVaultType
vaults: SDKVaultsListType
userActivity: UsersActivity
topDepositors: SDKUsersActivityType
Expand Down Expand Up @@ -172,7 +172,7 @@ export const VaultOpenViewComponent = ({
}
defaultExpanded
>
<VaultExposure rawData={vaultExposureRawData} />
<VaultExposure vault={vault} />
</Expander>
<Expander
title={
Expand Down
49 changes: 0 additions & 49 deletions apps/earn-protocol/components/layout/VaultOpenView/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
import { type VaultExposureRawData } from '@/components/organisms/VaultExposure/VaultExposure'

export const vaultExposureRawData: VaultExposureRawData[] = [
{
vault: {
label: 'MKR Blended',
primaryToken: 'USDC',
secondaryToken: 'DAI',
},
allocation: '0.32',
currentApy: '0.103',
liquidity: '43000000',
type: 'Fixed yield',
},
{
vault: {
label: 'MKR Blended',
primaryToken: 'USDC',
secondaryToken: 'DAI',
},
allocation: '0.32',
currentApy: '0.103',
liquidity: '43000000',
type: 'Isolated landing',
},
{
vault: {
label: 'MKR Blended',
primaryToken: 'USDC',
secondaryToken: 'DAI',
},
allocation: '0.32',
currentApy: '0.103',
liquidity: '43000000',
type: 'Lending',
},
{
vault: {
label: 'MKR Blended',
primaryToken: 'USDC',
secondaryToken: 'DAI',
},
allocation: '0.32',
currentApy: '0.103',
liquidity: '43000000',
type: 'Basic Trading',
},
]

export const detailsLinks = [
{
label: 'How it all works',
Expand Down
56 changes: 0 additions & 56 deletions apps/earn-protocol/components/organisms/VaultExposure/mapper.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Card, DataBlock, Text, WithArrow } from '@summerfi/app-earn-ui'
import { type SDKVaultsListType } from '@summerfi/app-types'
import { type IArmadaPosition } from '@summerfi/sdk-client-react'
import Link from 'next/link'

import { MockedLineChart } from '@/components/organisms/Charts/MockedLineChart'
Expand Down Expand Up @@ -54,7 +55,12 @@ const dataBlocks = [
},
]

export const PortfolioOverview = ({ vaultsList }: { vaultsList: SDKVaultsListType }) => {
type PortfolioOverviewProps = {
vaultsList: SDKVaultsListType
positions: IArmadaPosition[]
}

export const PortfolioOverview = ({ vaultsList, positions }: PortfolioOverviewProps) => {
return (
<div>
<div
Expand Down Expand Up @@ -88,6 +94,7 @@ export const PortfolioOverview = ({ vaultsList }: { vaultsList: SDKVaultsListTyp
</Card>
<NewsAndUpdates items={dummyNewsAndUpdatesItems} />
<CryptoUtilities />
<pre>{JSON.stringify(positions, null, 2)}</pre>
</div>
</div>
)
Expand Down
Loading

0 comments on commit 3b3ab7e

Please sign in to comment.