Skip to content

Commit

Permalink
Sky USDS staking view (#4027)
Browse files Browse the repository at this point in the history
* Sky staking initial view

* fixes

* Refactor SwapCard component to simplify description rendering logic

* Refactor SwapCard component to simplify description rendering logic
  • Loading branch information
marcinciarka authored Sep 19, 2024
1 parent b203ef7 commit 6cbd6b3
Show file tree
Hide file tree
Showing 35 changed files with 1,553 additions and 100 deletions.
645 changes: 645 additions & 0 deletions blockchain/abi/sky-staking.json

Large diffs are not rendered by default.

66 changes: 0 additions & 66 deletions blockchain/better-calls/sky-swaps.ts

This file was deleted.

163 changes: 163 additions & 0 deletions blockchain/better-calls/sky.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import BigNumber from 'bignumber.js'
import { mainnetContracts } from 'blockchain/contracts/mainnet'
import { getRpcProvider, NetworkIds } from 'blockchain/networks'
import { amountToWad } from 'blockchain/utils'
import { ethers } from 'ethers'
import {
SkyDaiUsds__factory,
SkyMkrSky__factory,
SkyStaking__factory,
SkySusds__factory,
} from 'types/ethers-contracts'

export const skyDaiUsdsSwap = async ({
token,
amount,
signer,
}: {
token: string
amount: BigNumber
signer: ethers.Signer
}) => {
const address = mainnetContracts.sky.daiusds.address
const contract = SkyDaiUsds__factory.connect(address, signer)
const signerAddress = await signer.getAddress()
const contractMethod = token === 'DAI' ? contract.daiToUsds : contract.usdsToDai
return contractMethod(signerAddress, ethers.BigNumber.from(amountToWad(amount).toString()))
}

export const skyMkrSkySwap = async ({
token,
amount,
signer,
}: {
token: string
amount: BigNumber
signer: ethers.Signer
}) => {
const address = mainnetContracts.sky.mkrsky.address
const contract = SkyMkrSky__factory.connect(address, signer)
const signerAddress = await signer.getAddress()
const contractMethod = token === 'MKR' ? contract.mkrToSky : contract.skyToMkr
return contractMethod(signerAddress, ethers.BigNumber.from(amountToWad(amount).toString()))
}

export const skyUsdsSusdsVault = async ({
token,
amount,
signer,
}: {
token: string
amount: BigNumber
signer: ethers.Signer
}) => {
const signerAddress = await signer.getAddress()
const susdsVaultContract = new ethers.Contract(
mainnetContracts.tokens.SUSDS.address,
SkySusds__factory.abi,
signer,
)
if (token === 'USDS') {
return susdsVaultContract['deposit(uint256,address,uint16)'](
ethers.BigNumber.from(amountToWad(amount).toString()),
signerAddress,
ethers.BigNumber.from(1001),
)
}
return susdsVaultContract['withdraw(uint256,address,address)'](
ethers.BigNumber.from(amountToWad(amount).toString()),
signerAddress,
signerAddress,
)
}

export const skyUsdsStake = async ({
action,
amount,
signer,
}: {
action: 'stake' | 'unstake' | 'claim'
amount: BigNumber
signer: ethers.Signer
}) => {
const skyStakingContract = new ethers.Contract(
mainnetContracts.sky.staking.address,
SkyStaking__factory.abi,
signer,
)
if (action === 'stake') {
return skyStakingContract['stake(uint256,uint16)'](
ethers.BigNumber.from(amountToWad(amount).toString()),
ethers.BigNumber.from(1001),
)
}
return skyStakingContract['withdraw(uint256)'](
ethers.BigNumber.from(amountToWad(amount).toString()),
)
}

export const skyUsdsStakeGetRewards = async ({ signer }: { signer: ethers.Signer }) => {
const skyStakingContract = new ethers.Contract(
mainnetContracts.sky.staking.address,
SkyStaking__factory.abi,
signer,
)
return skyStakingContract['getReward()']()
}

export const skyUsdsWalletStakeDetails = async ({ ownerAddress }: { ownerAddress?: string }) => {
const rpcProvider = getRpcProvider(NetworkIds.MAINNET)
if (!ownerAddress) {
return undefined
}
const skyStakingContract = new ethers.Contract(
mainnetContracts.sky.staking.address,
SkyStaking__factory.abi,
rpcProvider,
)
const [balance, earned, rewardRate, totalUSDSLocked] = await Promise.all([
skyStakingContract['balanceOf(address)'](ownerAddress).then(
(tokensStaked: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(tokensStaked, 18))
},
),
skyStakingContract['earned(address)'](ownerAddress).then(
(skyTokensEarned: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(skyTokensEarned, 18))
},
),
skyStakingContract['rewardRate']().then((rewardPercentage: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(rewardPercentage, 18))
}),
skyStakingContract['totalSupply']().then((USDSLocked: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(USDSLocked, 18))
}),
])
return { balance, earned, rewardRate, totalUSDSLocked } as {
balance: BigNumber
earned: BigNumber
rewardRate: BigNumber
totalUSDSLocked: BigNumber
}
}

export const skyUsdsStakeDetails = async () => {
const rpcProvider = getRpcProvider(1)
const skyStakingContract = new ethers.Contract(
mainnetContracts.sky.staking.address,
SkyStaking__factory.abi,
rpcProvider,
)
const [rewardRate, totalUSDSLocked] = await Promise.all([
skyStakingContract['rewardRate']().then((rewardPercentage: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(rewardPercentage, 18))
}),
skyStakingContract['totalSupply']().then((USDSLocked: ethers.BigNumber) => {
return new BigNumber(ethers.utils.formatUnits(USDSLocked, 18))
}),
])
return { rewardRate, totalUSDSLocked } as {
rewardRate: BigNumber
totalUSDSLocked: BigNumber
}
}
1 change: 1 addition & 0 deletions blockchain/contracts/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const arbitrumContracts: MainnetContractsWithOptional = {
daiusds: emptyContractDesc('daiusds'),
mkrsky: emptyContractDesc('mkrsky'),
susds: emptyContractDesc('susds'),
staking: emptyContractDesc('staking'),
},
ajnaERC20PoolFactory: contractDesc(ajnaERC20PoolFactory, arbitrum.ajna.ERC20PoolFactory),
ajnaRedeemer: contractDesc(ajnaReedemer, arbitrum.ajna.AjnaRewardsReedemer),
Expand Down
1 change: 1 addition & 0 deletions blockchain/contracts/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export const baseContracts: MainnetContractsWithOptional = {
daiusds: emptyContractDesc('daiusds'),
mkrsky: emptyContractDesc('mkrsky'),
susds: emptyContractDesc('susds'),
staking: emptyContractDesc('staking'),
},
ajnaERC20PoolFactory: contractDesc(ajnaERC20PoolFactory, base.ajna.ERC20PoolFactory),
ajnaRedeemer: contractDesc(ajnaReedemer, base.ajna.AjnaRewardsReedemer),
Expand Down
1 change: 1 addition & 0 deletions blockchain/contracts/goerli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export const goerliContracts: MainnetContractsWithOptional = {
daiusds: emptyContractDesc('daiusds'),
mkrsky: emptyContractDesc('mkrsky'),
susds: emptyContractDesc('susds'),
staking: emptyContractDesc('staking'),
},
ajnaERC20PoolFactory: contractDesc(ajnaERC20PoolFactory, goerli.ajna.ERC20PoolFactory),
ajnaRedeemer: contractDesc(ajnaReedemer, goerli.ajna.AjnaRewardsReedemer),
Expand Down
2 changes: 2 additions & 0 deletions blockchain/contracts/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import * as operationExecutor from 'blockchain/abi/operation-executor.json'
import * as otcSupport from 'blockchain/abi/otc-support-methods.json'
import * as skyDaiUsds from 'blockchain/abi/sky-dai-usds.json'
import * as skyMkrSky from 'blockchain/abi/sky-mkr-sky.json'
import * as skyStaking from 'blockchain/abi/sky-staking.json'
import * as skySusds from 'blockchain/abi/sky-susds.json'
import * as sparkV3Oracle from 'blockchain/abi/spark-v3-oracle.json'
import * as sparkV3Pool from 'blockchain/abi/spark-v3-pool.json'
Expand Down Expand Up @@ -283,6 +284,7 @@ export const mainnetContracts = {
daiusds: contractDesc(skyDaiUsds, '0x3225737a9Bbb6473CB4a45b7244ACa2BeFdB276A'),
mkrsky: contractDesc(skyMkrSky, '0xBDcFCA946b6CDd965f99a839e4435Bcdc1bc470B'),
susds: contractDesc(skySusds, '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD'),
staking: contractDesc(skyStaking, '0x0650CAF159C5A49f711e8169D4336ECB9b950275'),
},
}

Expand Down
1 change: 1 addition & 0 deletions blockchain/contracts/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const optimismContracts: OptimismContracts = {
daiusds: emptyContractDesc('daiusds'),
mkrsky: emptyContractDesc('mkrsky'),
susds: emptyContractDesc('susds'),
staking: emptyContractDesc('staking'),
},
morphoBlue: contractDesc(morphoBlue, optimism.morphoblue.MorphoBlue),
adaptiveCurveIrm: contractDesc(morphoBlue, optimism.morphoblue.AdaptiveCurveIrm),
Expand Down
5 changes: 2 additions & 3 deletions blockchain/networks/networks-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { ContractDesc } from 'features/web3Context'
import { GraphQLClient } from 'graphql-request'
import type { Abi } from 'helpers/types/Abi.types'
import { keyBy, memoize } from 'lodash'
import { env } from 'process'
import arbitrumMainnetBadge from 'public/static/img/network_icons/arbitrum_badge_mainnet.svg'
import arbitrumMainnetIcon from 'public/static/img/network_icons/arbitrum_mainnet.svg'
import baseMainnetBadge from 'public/static/img/network_icons/base_badge_mainnet.svg'
Expand Down Expand Up @@ -80,10 +79,10 @@ export function contractDesc(
return { abi, address, genesisBlock }
}

export function emptyContractDesc(contractName: string): ContractDesc & { genesisBlock: number } {
export function emptyContractDesc(_contractName: string): ContractDesc & { genesisBlock: number } {
// not every contract is available on every network
// hence this function is used to return an empty contract
env.NODE_ENV === 'development' && console.warn('Contract not set:', contractName)
// env.NODE_ENV === 'development' && console.warn('Contract not set:', contractName)
return { abi: {}, address: '', genesisBlock: 0 }
}

Expand Down
1 change: 1 addition & 0 deletions components/context/PreloadAppDataContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function PreloadAppDataContextProvider({ children }: PropsWithChildren<{}
LendingProtocol.AaveV2,
LendingProtocol.AaveV3,
LendingProtocol.Maker,
LendingProtocol.Sky,
...(MorphoSafetySwitch ? [] : [LendingProtocol.MorphoBlue]),
LendingProtocol.SparkV3,
]}`,
Expand Down
1 change: 1 addition & 0 deletions features/omni-kit/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const paybackAllAmountAllowanceMaxMultiplier: Record<LendingProtocol, Big
maker: one,
morphoblue: one,
sparkv3: one,
sky: one,
ajna: one.plus(protocols.ajna.ajnaPaybackAllWithdrawAllValueOffset),
}

Expand Down
1 change: 1 addition & 0 deletions features/omni-kit/helpers/getOmniProtocolUrlMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const getOmniProtocolUrlMap = (protocol: LendingProtocol) => {
[LendingProtocol.Ajna]: protocol,
[LendingProtocol.MorphoBlue]: protocol,
[LendingProtocol.Maker]: protocol,
[LendingProtocol.Sky]: protocol,
}

return protocolUrlMap[protocol]
Expand Down
3 changes: 3 additions & 0 deletions features/productHub/helpers/getGenericPositionUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export function getGenericPositionUrl({
secondaryToken,
aaveLikeProduct: 'aave',
})
case LendingProtocol.Sky:
if (label === 'SSR') return '/earn/ssr/'
return '/'
case LendingProtocol.Maker:
if (label === 'DSR') return '/earn/dsr/'

Expand Down
29 changes: 17 additions & 12 deletions features/productHub/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,26 @@ export const productHubTestNetworkFilter: GenericMultiselectOption[] = [

export const productHubProtocolFilter: GenericMultiselectOption[] = [
{
label: lendingProtocolsByName[LendingProtocol.AaveV2].label,
value: lendingProtocolsByName[LendingProtocol.AaveV2].name,
image: lendingProtocolsByName[LendingProtocol.AaveV2].icon,
label: lendingProtocolsByName[LendingProtocol.Sky].label,
value: lendingProtocolsByName[LendingProtocol.Sky].name,
image: lendingProtocolsByName[LendingProtocol.Sky].icon,
},
{
label: lendingProtocolsByName[LendingProtocol.AaveV3].label,
value: lendingProtocolsByName[LendingProtocol.AaveV3].name,
image: lendingProtocolsByName[LendingProtocol.AaveV3].icon,
},
{
label: lendingProtocolsByName[LendingProtocol.MorphoBlue].label,
value: lendingProtocolsByName[LendingProtocol.MorphoBlue].name,
image: lendingProtocolsByName[LendingProtocol.MorphoBlue].icon,
featureFlag: FeaturesEnum.MorphoBlue,
},
{
label: lendingProtocolsByName[LendingProtocol.SparkV3].label,
value: lendingProtocolsByName[LendingProtocol.SparkV3].name,
image: lendingProtocolsByName[LendingProtocol.SparkV3].icon,
},
{
label: lendingProtocolsByName[LendingProtocol.Ajna].label,
value: lendingProtocolsByName[LendingProtocol.Ajna].name,
Expand All @@ -114,15 +125,9 @@ export const productHubProtocolFilter: GenericMultiselectOption[] = [
image: lendingProtocolsByName[LendingProtocol.Maker].icon,
},
{
label: lendingProtocolsByName[LendingProtocol.MorphoBlue].label,
value: lendingProtocolsByName[LendingProtocol.MorphoBlue].name,
image: lendingProtocolsByName[LendingProtocol.MorphoBlue].icon,
featureFlag: FeaturesEnum.MorphoBlue,
},
{
label: lendingProtocolsByName[LendingProtocol.SparkV3].label,
value: lendingProtocolsByName[LendingProtocol.SparkV3].name,
image: lendingProtocolsByName[LendingProtocol.SparkV3].icon,
label: lendingProtocolsByName[LendingProtocol.AaveV2].label,
value: lendingProtocolsByName[LendingProtocol.AaveV2].name,
image: lendingProtocolsByName[LendingProtocol.AaveV2].icon,
},
]

Expand Down
1 change: 1 addition & 0 deletions features/refinance/components/RefinancePortfolioBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const RefinancePortfolioBanner: FC<RefinancePortfolioBannerProps> = ({ po
</Text>
),
[LendingProtocol.Ajna]: null,
[LendingProtocol.Sky]: null,
[LendingProtocol.AaveV3]: (
<Text as="span" variant="boldParagraph3" color="primary100">
{tPortfolio('refinance.banner.default', {
Expand Down
1 change: 1 addition & 0 deletions features/refinance/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,5 @@ export const refinanceCustomProductHubFiltersOptions = {
},
[LendingProtocol.AaveV2]: undefined,
[LendingProtocol.Ajna]: undefined,
[LendingProtocol.Sky]: undefined,
}
Loading

0 comments on commit 6cbd6b3

Please sign in to comment.