-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sky staking initial view * fixes * Refactor SwapCard component to simplify description rendering logic * Refactor SwapCard component to simplify description rendering logic
- Loading branch information
1 parent
b203ef7
commit 6cbd6b3
Showing
35 changed files
with
1,553 additions
and
100 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.