-
Notifications
You must be signed in to change notification settings - Fork 135
feat: add USDA plugin and scripts #1215
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Angle USDA Collateral Plugin | ||
|
|
||
| ## Summary | ||
|
|
||
| `USDA` is a stablecoin pegged to the dollar built by [Angle Labs](https://github.com/AngleProtocol). `USDA` holders can stake their stablecoins for `stUSD` in order to earn a native yield. | ||
|
|
||
| This plugin allows `stUSD` holders to use their tokens as collateral in the Reserve Protocol. | ||
|
|
||
| `stUSD` is an ERC4626 vault, most similar to the DAI savings module. The redeemable `USDA` amount can be obtained by dividing `stUSD.totalAssets()` by `stUSD.totalSupply()`. | ||
|
|
||
| `USDA` contract: <https://etherscan.io/address/0x0000206329b97DB379d5E1Bf586BbDB969C63274#code> | ||
|
|
||
| `stUSD` contract: <https://etherscan.io/address/0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776#code> | ||
|
|
||
| ## Implementation | ||
|
|
||
| ### Units | ||
|
|
||
| | tok | ref | target | UoA | | ||
| | ----- | ---- | ------ | --- | | ||
| | stUSD | USDA | USD | USD | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // SPDX-License-Identifier: BlueOak-1.0.0 | ||
| pragma solidity 0.8.19; | ||
|
|
||
| import { CollateralConfig } from "../AppreciatingFiatCollateral.sol"; | ||
| import { ERC4626FiatCollateral } from "../ERC4626FiatCollateral.sol"; | ||
|
|
||
| /** | ||
| * @title USDA Fiat Collateral | ||
| * @notice Collateral plugin for USDA (Angle) | ||
| * tok = stUSD (ERC4626 vault) | ||
| * ref = USDA | ||
| * tar = USD | ||
| * UoA = USD | ||
| */ | ||
|
|
||
| contract USDAFiatCollateral is ERC4626FiatCollateral { | ||
|
pmckelvy1 marked this conversation as resolved.
Outdated
|
||
| /// config.erc20 must be stUSD | ||
| /// @param config.chainlinkFeed Feed units: {UoA/ref} | ||
| /// @param revenueHiding {1} A value like 1e-6 that represents the maximum refPerTok to hide | ||
| constructor(CollateralConfig memory config, uint192 revenueHiding) | ||
| ERC4626FiatCollateral(config, revenueHiding) | ||
| { | ||
| require(config.defaultThreshold != 0, "defaultThreshold zero"); | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looking at the stUSDA ERC4626 contract, and there seems to be an internal accrual happening on any deposit or withdrawal. since this accrual affects the pricePerShare() rate, we should make sure this gets updated on any call to the best way to do this is probably to copy over the refresh call from the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, but wondering if this is really needed for
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but there are state updates performed in the collateral plugin, so we should match that with any necessary state updates in the collateral itself. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import fs from 'fs' | ||
| import hre from 'hardhat' | ||
| import { ContractFactory } from 'ethers' | ||
| import { expect } from 'chai' | ||
| import { getChainId } from '../../../../common/blockchain-utils' | ||
| import { networkConfig } from '../../../../common/configuration' | ||
| import { fp } from '../../../../common/numbers' | ||
| import { CollateralStatus } from '../../../../common/constants' | ||
| import { | ||
| getDeploymentFile, | ||
| getAssetCollDeploymentFilename, | ||
| IAssetCollDeployments, | ||
| getDeploymentFilename, | ||
| fileExists, | ||
| } from '../../common' | ||
| import { USDAFiatCollateral } from '../../../../typechain' | ||
| import { | ||
| DELAY_UNTIL_DEFAULT, | ||
| PRICE_TIMEOUT, | ||
| ORACLE_TIMEOUT, | ||
| ORACLE_ERROR, | ||
| } from '../../../../test/plugins/individual-collateral/angle/constants' | ||
|
|
||
| async function main() { | ||
| // ==== Read Configuration ==== | ||
| const [deployer] = await hre.ethers.getSigners() | ||
|
|
||
| const chainId = await getChainId(hre) | ||
|
|
||
| console.log(`Deploying Collateral to network ${hre.network.name} (${chainId}) | ||
| with burner account: ${deployer.address}`) | ||
|
|
||
| if (!networkConfig[chainId]) { | ||
| throw new Error(`Missing network configuration for ${hre.network.name}`) | ||
| } | ||
|
|
||
| // Get phase1 deployment | ||
| const phase1File = getDeploymentFilename(chainId) | ||
| if (!fileExists(phase1File)) { | ||
| throw new Error(`${phase1File} doesn't exist yet. Run phase 1`) | ||
| } | ||
| // Check previous step completed | ||
| const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) | ||
| const assetCollDeployments = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename) | ||
|
|
||
| const deployedCollateral: string[] = [] | ||
|
|
||
| /******** Deploy USDA Collateral - stUSD **************************/ | ||
| let collateral: USDAFiatCollateral | ||
|
|
||
| const USDAFiatCollateralFactory: ContractFactory = await hre.ethers.getContractFactory( | ||
| 'USDAFiatCollateral' | ||
| ) | ||
|
|
||
| collateral = <USDAFiatCollateral>await USDAFiatCollateralFactory.connect(deployer).deploy( | ||
| { | ||
| priceTimeout: PRICE_TIMEOUT.toString(), | ||
| chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. USDA |
||
| oracleError: ORACLE_ERROR.toString(), | ||
| erc20: networkConfig[chainId].tokens.stUSD, | ||
| maxTradeVolume: fp('1e6').toString(), // $1m, | ||
| oracleTimeout: ORACLE_TIMEOUT.toString(), // 24 hr | ||
| targetName: hre.ethers.utils.formatBytes32String('USD'), | ||
| defaultThreshold: fp('0.01').add(ORACLE_ERROR).toString(), // ~1.5% | ||
| delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), // 72h | ||
| }, | ||
| fp('1e-6').toString() | ||
| ) | ||
|
|
||
| await collateral.deployed() | ||
|
|
||
| console.log( | ||
| `Deployed USDA (stUSD) Collateral to ${hre.network.name} (${chainId}): ${collateral.address}` | ||
| ) | ||
| await (await collateral.refresh()).wait() | ||
| expect(await collateral.status()).to.equal(CollateralStatus.SOUND) | ||
|
|
||
| assetCollDeployments.collateral.stUSD = collateral.address | ||
| assetCollDeployments.erc20s.stUSD = networkConfig[chainId].tokens.stUSD | ||
| deployedCollateral.push(collateral.address.toString()) | ||
|
|
||
| fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) | ||
|
|
||
| console.log(`Deployed collateral to ${hre.network.name} (${chainId}) | ||
| New deployments: ${deployedCollateral} | ||
| Deployment file: ${assetCollDeploymentFilename}`) | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error) | ||
| process.exitCode = 1 | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import hre from 'hardhat' | ||
| import { getChainId } from '../../../common/blockchain-utils' | ||
| import { developmentChains, networkConfig } from '../../../common/configuration' | ||
| import { fp } from '../../../common/numbers' | ||
| import { | ||
| getDeploymentFile, | ||
| getAssetCollDeploymentFilename, | ||
| IAssetCollDeployments, | ||
| } from '../../deployment/common' | ||
| import { verifyContract } from '../../deployment/utils' | ||
| import { | ||
| PRICE_TIMEOUT, | ||
| ORACLE_ERROR, | ||
| ORACLE_TIMEOUT, | ||
| DELAY_UNTIL_DEFAULT, | ||
| } from '../../../test/plugins/individual-collateral/angle/constants' | ||
|
|
||
| let deployments: IAssetCollDeployments | ||
|
|
||
| async function main() { | ||
| // ********** Read config ********** | ||
| const chainId = await getChainId(hre) | ||
| if (!networkConfig[chainId]) { | ||
| throw new Error(`Missing network configuration for ${hre.network.name}`) | ||
| } | ||
|
|
||
| if (developmentChains.includes(hre.network.name)) { | ||
| throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`) | ||
| } | ||
|
|
||
| const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) | ||
| deployments = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename) | ||
|
|
||
| /******** Verify stUSD COllateral **************************/ | ||
| await verifyContract( | ||
| chainId, | ||
| deployments.collateral.stUSD, | ||
| [ | ||
| { | ||
| priceTimeout: PRICE_TIMEOUT.toString(), | ||
| chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. USDA |
||
| oracleError: ORACLE_ERROR.toString(), | ||
| erc20: networkConfig[chainId].tokens.stUSD, | ||
| maxTradeVolume: fp('1e6').toString(), // $1m, | ||
| oracleTimeout: ORACLE_TIMEOUT.toString(), | ||
| targetName: hre.ethers.utils.formatBytes32String('USD'), | ||
| defaultThreshold: fp('0.01').add(ORACLE_ERROR).toString(), | ||
| delayUntilDefault: DELAY_UNTIL_DEFAULT.toString(), | ||
| }, | ||
| fp('1e-6').toString(), | ||
| ], | ||
| 'contracts/plugins/assets/angle/USDAFiatCollateral.sol:USDAFiatCollateral' | ||
| ) | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error) | ||
| process.exitCode = 1 | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.