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

Bao app dev lend #43

Merged
merged 28 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
47631a1
Adding Lend page and components
Daizze Jul 12, 2024
f665347
Adjustments supply
Daizze Jul 23, 2024
3fd746e
Adjustments Lend page adding SuppliedCard updates
Daizze Aug 2, 2024
bfcda78
Adding Modals and Debt Card for Lend
Daizze Sep 5, 2024
67fe452
Layout adjustments Supply List
Daizze Sep 5, 2024
893891c
Adjustments showing asset supply and position for assets
Daizze Sep 14, 2024
576d4f8
Adjustments showing correct total supply and position
Daizze Sep 15, 2024
341907f
Adding market header information
Daizze Sep 16, 2024
ee0b5dd
Adding changes DebtCard
Daizze Sep 30, 2024
c3eca70
Bug fixes DebtCard
Daizze Oct 7, 2024
8e2ef6d
feat: styles, config
Haruxe Oct 9, 2024
73b5366
fix: compilation errors, cleanup
Haruxe Oct 9, 2024
bf0b1fc
fix: further styling for markets
Haruxe Oct 9, 2024
95afb55
Adding last modal pages + buttons
Daizze Oct 13, 2024
24d8f68
First change withdrawle amount
Daizze Oct 14, 2024
1bae453
Updating config and adding approval and fixng supply logic to supply …
Daizze Oct 18, 2024
a8ada08
Several fixes updating data
Daizze Oct 21, 2024
cfbc89e
Fixing issues for build
Daizze Oct 23, 2024
0416ed7
Fixing calculations borrow modal
Daizze Oct 24, 2024
32208b1
Minor bugfix typo
Daizze Oct 28, 2024
757a19c
Adjustments for repay in Lend
Daizze Nov 6, 2024
058b563
Adjustments withdraw
Daizze Nov 10, 2024
35864d7
Adjustments front end in modals
Daizze Nov 12, 2024
6a02700
Reenabling DebtCard
Daizze Nov 12, 2024
9dcf662
Minor build fix
Daizze Nov 14, 2024
5ed31b1
Update Nav.tsx
fabiaz84 Nov 14, 2024
565590d
Merge branch 'staging' into bao-app-dev-lend
fabiaz84 Nov 14, 2024
9e7e279
nav fix
fabiaz84 Nov 14, 2024
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
Binary file modified public/images/tokens/USDe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/tokens/weETH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
214 changes: 214 additions & 0 deletions src/bao/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,4 +815,218 @@ export default {
],
},
],
lendMarkets: {
weETH: {
id: 1,
active: true,
name: 'weETH',
desc: 'Wrapped eETH',
comptroller: '0xf55044bb140DD3Eeb7372bd722C323c87d8AE798',
oracle: '0xc7D8b6b170E0FCf4182fa29b47F35F48C402bF0F',
marketAddresses: {
1: '0x353A07b25c84a522356aF2D9a7c0d7FF481733e9',
},
underlyingAddresses: {
1: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
},
assets: [
{
id: 1,
active: true,
marketAddress: {
1: '0x353A07b25c84a522356aF2D9a7c0d7FF481733e9',
},
underlyingAddress: {
1: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
},
underlyingDecimals: 18,
name: 'weETH',
icon: '/images/tokens/weETH.png',
supply: true,
borrow: false,
},
{
id: 2,
active: true,
marketAddress: {
1: '0x085c35278fDC840b9Ca74AAB226bA8E2f95C446F',
},
underlyingAddress: {
1: '0x7945b0A6674b175695e5d1D08aE1e6F13744Abb0',
},
underlyingDecimals: 18,
name: 'BaoUSD',
icon: '/images/tokens/baoUSD.png',
supply: true,
borrow: true,
},
{
id: 3,
active: true,
marketAddress: {
1: '0xdC39e6365AA75D762729513004c956D1475bED20',
},
underlyingAddress: {
1: '0xf4edfad26EE0D23B69CA93112eccE52704E0006f',
},
underlyingDecimals: 18,
name: 'BaoETH',
icon: '/images/tokens/baoETH.png',
supply: true,
borrow: true,
},
{
id: 4,
active: true,
marketAddress: {
1: '0x357FE927DC3Ee1be7ba1423bc5485BC8CD066040',
},
underlyingAddress: {
1: '0xc69Ad9baB1dEE23F4605a82b3354F8E40d1E5966',
},
underlyingDecimals: 18,
name: 'PTweETHJUN',
icon: '/images/tokens/weETH.png',
supply: true,
borrow: false,
},
{
id: 5,
active: true,
marketAddress: {
1: '0x0930B04032E52daBC2324533c015bc27Ad5B35B7',
},
underlyingAddress: {
1: '0x1c085195437738d73d75DC64bC5A3E098b7f93b1',
},
underlyingDecimals: 18,
name: 'PTweETHSEP',
icon: '/images/tokens/weETH.png',
supply: true,
borrow: false,
},
{
id: 6,
active: true,
marketAddress: {
1: '0x672bf1cdE0F352296fA759BefF392997C809cd8a',
},
underlyingAddress: {
1: '0x6ee2b5E19ECBa773a352E5B21415Dc419A700d1d',
},
underlyingDecimals: 18,
name: 'PTweETHDEC',
icon: '/images/tokens/weETH.png',
supply: true,
borrow: false,
},
],
},
USDe: {
id: 1,
active: true,
name: 'USDe',
desc: 'Ethena USDe',
comptroller: '0x46396230c61776A384c1c00c04A9784c4a2F5d8F',
oracle: '0xba2fdeb1d483acbdb196b39473e7af90268afa67',
marketAddresses: {
1: '0x680358d70b34a00f2d661bb4f95E1C14E5Dae93F',
},
underlyingAddresses: {
1: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3',
},
assets: [
{
id: 1,
active: true,
marketAddress: {
1: '0x680358d70b34a00f2d661bb4f95E1C14E5Dae93F',
},
underlyingAddress: {
1: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3',
},
underlyingDecimals: 18,
name: 'USDe',
icon: '/images/tokens/USDe.png',
supply: true,
borrow: false,
},
{
id: 2,
active: true,
marketAddress: {
1: '0xe606AE6d6394a977a8B0926557BF9D291051f989',
},
underlyingAddress: {
1: '0x7945b0A6674b175695e5d1D08aE1e6F13744Abb0',
},
underlyingDecimals: 18,
name: 'BaoUSD',
icon: '/images/tokens/baoUSD.png',
supply: true,
borrow: true,
},
{
id: 3,
active: true,
marketAddress: {
1: '0xDe10BEd5236B786cAA18Ca39FFa5de1b904a8a94',
},
underlyingAddress: {
1: '0xf4edfad26EE0D23B69CA93112eccE52704E0006f',
},
underlyingDecimals: 18,
name: 'BaoETH',
icon: '/images/tokens/baoETH.png',
supply: true,
borrow: true,
},
{
id: 4,
active: true,
marketAddress: {
1: '0xD011778057AA740BB3703Ad4d78b3c79a1aED1cb',
},
underlyingAddress: {
1: '0x9D39A5DE30e57443BfF2A8307A4256c8797A3497',
},
underlyingDecimals: 18,
name: 'sUSDe',
icon: '/images/tokens/sUSDe.png',
supply: true,
borrow: false,
},
{
id: 5,
active: true,
marketAddress: {
1: '0x3d881b3C7B690f05E672cD0F8fCbC0aE3A7292CF',
},
underlyingAddress: {
1: '0xa0021EF8970104c2d008F38D92f115ad56a9B8e1',
},
underlyingDecimals: 18,
name: 'PTUSDeJUL',
icon: '/images/tokens/USDe.png',
supply: true,
borrow: false,
},
{
id: 6,
active: true,
marketAddress: {
1: '0x4cd395CB5edF33b44E73257ee614413f95d1a6cD',
},
underlyingAddress: {
1: '0x6c9f097e044506712B58EAC670c9a5fd4BCceF13',
},
underlyingDecimals: 18,
name: 'PTsUSDeSEP',
icon: '/images/tokens/sUSDe.png',
supply: true,
borrow: false,
},
],
},
},
} as unknown as Config
57 changes: 57 additions & 0 deletions src/bao/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ export interface Config {
}
gauges: SupportedGauge[]
swapTokens: SwapToken[]
assets: Asset[]
lendMarkets: {
[market: string]: LendMarket
}
}

export interface SwapToken {
Expand All @@ -241,3 +245,56 @@ export interface SwapToken {
},
]
}

export interface LendMarket {
id: number
active: boolean
comptroller: string
oracle: string
name: string
desc: string
marketAddresses: {
[network: number]: string
}
underlyingAddresses: {
[network: number]: string
}
assets: Asset[]
}

export interface ActiveLendMarket {
marketAddress: string
marketContract: Cether | Ctoken
underlyingAddress: string
underlyingContract?: Erc20
}

export interface Asset {
id: number
active: boolean
marketAddress: {
[network: number]: string
}
underlyingAddress: {
[network: number]: string
}
underlyingDecimals: number
name: string
icon: string
supply: boolean
borrow: boolean
}

export type Balance = {
address: string
symbol: string
balance: BigNumber
decimals: number
}

export type TotalSupply = {
address: string
symbol: string
totalSupply: BigNumber
decimals: number
}
9 changes: 7 additions & 2 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
children?: ReactNode
size?: ButtonSize
fullWidth?: boolean
width?: string | boolean
pendingTx?: string | boolean
txHash?: string
inline?: boolean
Expand All @@ -28,7 +29,10 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ children, className = '', size = 'md', fullWidth = false, pendingTx, txHash, inline, text, href, disabled, ...rest }, ref) => {
(
{ children, className = '', size = 'md', fullWidth = false, width = false, pendingTx, txHash, inline, text, href, disabled, ...rest },
ref,
) => {
const ButtonChild = useMemo(() => {
if (href) {
return (
Expand All @@ -55,8 +59,9 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
Size[size],
inline ? 'inline-block' : 'flex',
fullWidth ? 'w-full' : '',
width ? width : 'w-fit',
disabled ? 'cursor-not-allowed opacity-50' : '',
`relative flex w-fit items-center justify-center overflow-hidden glassmorphic-card border border-baoWhite border-opacity-20
`relative flex items-center justify-center overflow-hidden glassmorphic-card border border-baoWhite border-opacity-20
bg-baoWhite bg-opacity-5 px-4 py-2 font-bakbak text-lg text-baoWhite duration-300 hover:border-baoRed hover:bg-baoRed hover:bg-opacity-20`,
className,
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const Header: FC = () => {
<MobileNavLink href='/swap'>SWAP</MobileNavLink>
<MobileNavLink href='/earn'>EARN</MobileNavLink>
<MobileNavLink href='/vebao'>VEBAO</MobileNavLink>
<MobileNavLink href='/lend'>LEND</MobileNavLink>
</div>
</Popover.Panel>
</>
Expand Down
1 change: 1 addition & 0 deletions src/components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Nav: FC<NavLinkProps> = ({ href, exact }) => {
['2', 'SWAP', '/swap'],
['3', 'EARN', '/earn'],
['4', 'VEBAO', '/vebao'],
['5', 'LEND', '/lend'],
]

return (
Expand Down
57 changes: 57 additions & 0 deletions src/hooks/lend/useAccountBalances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import useBao from '@/hooks/base/useBao'
import { useWeb3React } from '@web3-react/core'
import { useQuery } from '@tanstack/react-query'
import { providerKey } from '@/utils/index'
import { Contract } from '@ethersproject/contracts'
import { Erc20__factory } from '@/typechain/factories'
import MultiCall from '@/utils/multicall'
import Config from '@/bao/lib/config'
import { Balance } from '@/bao/lib/types'
import { useTxReceiptUpdater } from '@/hooks/base/useTransactionProvider'

export const useAccountBalances = (marketName: string): Balance[] => {
const bao = useBao()
const { account, library, chainId } = useWeb3React()
const enabled = !!bao && !!account && !!chainId && !!marketName
const { data: balances, refetch } = useQuery(
['@/hooks/lend/useAccountBalance', providerKey(library, account, chainId), { enabled, marketName }],
async () => {
const tokens = Config.lendMarkets[marketName].assets.map(asset => asset.underlyingAddress[chainId])
const contracts: Contract[] = tokens.filter(address => address !== 'ETH').map(address => Erc20__factory.connect(address, library))

const res = MultiCall.parseCallResults(
await bao.multicall.call(
MultiCall.createCallContext(
contracts.map(
contract =>
contract && {
ref: contract.address,
contract,
calls: [{ method: 'symbol' }, { method: 'decimals' }, { method: 'balanceOf', params: [account] }],
},
),
),
),
)
const ethBalance = await library.getBalance(account)

return tokens.map(address => {
const symbol = res[address] ? res[address][0].values[0] : 'ETH'
const decimals = res[address] ? res[address][1].values[0] : 18
const balance = res[address] ? res[address][2].values[0] : ethBalance
return { address, symbol, balance, decimals }
})
},
{
enabled,
},
)

const _refetch = () => {
if (enabled) refetch()
}

useTxReceiptUpdater(_refetch)

return balances
}
Loading
Loading