-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Taylor Brent <[email protected]>
- Loading branch information
1 parent
63bdb51
commit c5b08d9
Showing
12 changed files
with
490 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Ethena USDe Collateral Plugin | ||
|
||
## Summary | ||
|
||
`USDe` is a synthetic dollar protocol built on Ethereum that derives its value from a delta-neutral basis trade based on funding rates: long ETH-LSD + short ETH. This combined position captures the funding rate on perpetual exchanges, which has been historically positive throughout crypto’s history, which is also used to provision an additional `sUSDe` token. | ||
|
||
This plugin allows `sUSDe` holders to use their tokens as collateral in the Reserve Protocol. | ||
|
||
`sUSDe` is a high-yield (today) ERC4626 vault, most similar to the DAI savings module. The redeemable USDe amount can be obtained by dividing `sUSDe.totalAssets()` by `sUSDe.totalSupply()`. | ||
|
||
`USDe` contract: <https://etherscan.io/address/0x4c9edd5852cd905f086c759e8383e09bff1e68b3#code> | ||
|
||
`sUSDe` contract: <https://etherscan.io/address/0x9D39A5DE30e57443BfF2A8307A4256c8797A3497#code> | ||
|
||
## Implementation | ||
|
||
### Units | ||
|
||
| tok | ref | target | UoA | | ||
| ----- | ---- | ------ | --- | | ||
| sUSDe | USDe | USD | USD | | ||
|
||
### Functions | ||
|
||
#### refPerTok {ref/tok} | ||
|
||
`return shiftl_toFix(erc4626.convertToAssets(oneShare), -refDecimals)` |
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,25 @@ | ||
// SPDX-License-Identifier: BlueOak-1.0.0 | ||
pragma solidity 0.8.19; | ||
|
||
import { CollateralConfig } from "../AppreciatingFiatCollateral.sol"; | ||
import { ERC4626FiatCollateral } from "../ERC4626FiatCollateral.sol"; | ||
|
||
/** | ||
* @title USDe Fiat Collateral | ||
* @notice Collateral plugin for USDe (Ethena) | ||
* tok = sUSDe (ERC4626 vault) | ||
* ref = USDe | ||
* tar = USD | ||
* UoA = USD | ||
*/ | ||
|
||
contract USDeFiatCollateral is ERC4626FiatCollateral { | ||
/// config.erc20 must be sUSDe | ||
/// @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"); | ||
} | ||
} |
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
92 changes: 92 additions & 0 deletions
92
scripts/deployment/phase2-assets/collaterals/deploy_USDe.ts
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,92 @@ | ||
import fs from 'fs' | ||
import hre from 'hardhat' | ||
import { getChainId } from '../../../../common/blockchain-utils' | ||
import { networkConfig } from '../../../../common/configuration' | ||
import { fp } from '../../../../common/numbers' | ||
import { expect } from 'chai' | ||
import { CollateralStatus } from '../../../../common/constants' | ||
import { | ||
getDeploymentFile, | ||
getAssetCollDeploymentFilename, | ||
IAssetCollDeployments, | ||
getDeploymentFilename, | ||
fileExists, | ||
} from '../../common' | ||
import { USDeFiatCollateral } from '../../../../typechain' | ||
import { ContractFactory } from 'ethers' | ||
import { | ||
DELAY_UNTIL_DEFAULT, | ||
PRICE_TIMEOUT, | ||
ORACLE_TIMEOUT, | ||
ORACLE_ERROR, | ||
} from '../../../../test/plugins/individual-collateral/ethena/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 USDe Collateral - sUSDe **************************/ | ||
let collateral: USDeFiatCollateral | ||
|
||
const USDeFiatCollateralFactory: ContractFactory = await hre.ethers.getContractFactory( | ||
'USDeFiatCollateral' | ||
) | ||
|
||
collateral = <USDeFiatCollateral>await USDeFiatCollateralFactory.connect(deployer).deploy( | ||
{ | ||
priceTimeout: PRICE_TIMEOUT.toString(), | ||
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDe, | ||
oracleError: ORACLE_ERROR.toString(), | ||
erc20: networkConfig[chainId].tokens.sUSDe, | ||
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 USDe (sUSDe) Collateral to ${hre.network.name} (${chainId}): ${collateral.address}` | ||
) | ||
await (await collateral.refresh()).wait() | ||
expect(await collateral.status()).to.equal(CollateralStatus.SOUND) | ||
|
||
assetCollDeployments.collateral.sUSDe = collateral.address | ||
assetCollDeployments.erc20s.sUSDe = networkConfig[chainId].tokens.sUSDe | ||
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 | ||
}) |
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,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/ethena/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 sUSDe COllateral **************************/ | ||
await verifyContract( | ||
chainId, | ||
deployments.collateral.sUSDe, | ||
[ | ||
{ | ||
priceTimeout: PRICE_TIMEOUT.toString(), | ||
chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDe, | ||
oracleError: ORACLE_ERROR.toString(), | ||
erc20: networkConfig[chainId].tokens.sUSDe, | ||
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/ethena/USDeFiatCollateral.sol:USDeFiatCollateral' | ||
) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
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.