-
Notifications
You must be signed in to change notification settings - Fork 135
nars - snars - collateral plugin #1217
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
Open
ezequiel-num
wants to merge
4
commits into
reserve-protocol:master
Choose a base branch
from
ezequiel-num:NARS_SNARS_plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6292c0b
nars - snars - collateral plugin
egorbatik 34bec49
fix: config, SnARSFiatCollateral, Deploy SNARS, Tests
egorbatik 8e5470b
feature: Deploy FIAT Collateral
egorbatik 2259af3
fix: Readme, SNARSFiatCollateral, Deploy NARS, SNARS, collateral tests
egorbatik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,32 @@ | ||
| # Collateral Plugins for nARS and snARS | ||
|
|
||
| ## Summary | ||
|
|
||
| This plugin allows `nARS` and `snARS` holders to use their tokens as collateral in the Reserve Protocol. | ||
|
|
||
| As described in the [Num Site](https://new.num.finance/) nTokens are ERC20 tokens, tracking the value of an underlying financial asset. | ||
| Each nToken issued by Num Finance is fully collateralized by an asset in the traditional market. This means that for every nToken in circulation, there is a real-world asset backing it, ensuring the token's value and stability. | ||
|
|
||
| In this particular case we're incorporating through this plugin 2 nTokens. | ||
| - `nARS` is a stablecoin pegged to the `Argentine Peso (ARS)`. | ||
| - `snARS` is the staked version of `nARS`. When users stake their `nARS`, they receive `snARS` in return, which grants them certain benefits in the form of yield or Numun Rewards. | ||
|
|
||
| Staking of `nARS` is possible at: https://numun.fi/ | ||
| Official num website: https://num.finance/ | ||
| nStables documentation: https://docs.nstables.fi/ | ||
|
|
||
| ## Implementation | ||
|
|
||
| ### Units | ||
|
|
||
| | tok | ref | target | UoA | | ||
| | ---- | ---- | ------ | --- | | ||
| | nARS | ARS | ARS | USD | | ||
|
|
||
| | tok | ref | target | UoA | | ||
| | ---- | ---- | ------ | --- | | ||
| | sNARS | ARS | ARS | USD | | ||
|
|
||
| ### claimRewards() | ||
|
|
||
| There are no rewards to claim |
This file contains hidden or 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,21 @@ | ||
| // SPDX-License-Identifier: BlueOak-1.0.0 | ||
| pragma solidity 0.8.19; | ||
|
|
||
| import { CollateralConfig } from "../AppreciatingFiatCollateral.sol"; | ||
| import { ERC4626FiatCollateral } from "../ERC4626FiatCollateral.sol"; | ||
|
|
||
| /** | ||
| * @title SnARSFiatCollateral | ||
| * @notice Collateral plugin for a Num vault with fiat collateral | ||
| * Expected: {tok} != {ref}, {ref} is pegged to {target} unless defaulting, {target} == ARS, {UoA} == USD | ||
| */ | ||
| contract SnARSFiatCollateral is ERC4626FiatCollateral { | ||
| /// config.erc20 must be a Num ERC4626 vault | ||
| /// @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 hidden or 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
83 changes: 83 additions & 0 deletions
83
scripts/deployment/phase2-assets/collaterals/deploy_snARS.ts
This file contains hidden or 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,83 @@ | ||
| import fs from 'fs' | ||
| import hre from 'hardhat' | ||
| import { getChainId } from '../../../../common/blockchain-utils' | ||
| import { networkConfig } from '../../../../common/configuration' | ||
| import { bn, fp } from '../../../../common/numbers' | ||
| import { expect } from 'chai' | ||
| import { CollateralStatus } from '../../../../common/constants' | ||
| import { | ||
| getDeploymentFile, | ||
| getAssetCollDeploymentFilename, | ||
| IAssetCollDeployments, | ||
| getDeploymentFilename, | ||
| fileExists, | ||
| } from '../../common' | ||
| import { priceTimeout } from '../../utils' | ||
| import { SnARSFiatCollateral } from '../../../../typechain' | ||
| import { ContractFactory } from 'ethers' | ||
|
|
||
| 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 snARS Collateral - snARS **************************/ | ||
|
|
||
| const nuARSCollateralFactory: ContractFactory = await hre.ethers.getContractFactory( | ||
| 'FiatCollateral' | ||
| ) | ||
|
|
||
| const collateral = <SnARSFiatCollateral>await nuARSCollateralFactory.connect(deployer).deploy( | ||
| { | ||
| priceTimeout: priceTimeout.toString(), | ||
| chainlinkFeed: networkConfig[chainId].chainlinkFeeds.snARS, | ||
| oracleError: fp('0.005').toString(), // 0.5% | ||
| erc20: networkConfig[chainId].tokens.snARS, | ||
| maxTradeVolume: fp('1e6').toString(), // $1m, | ||
| oracleTimeout: '900', // 15min | ||
| targetName: hre.ethers.utils.formatBytes32String('ARS'), | ||
| defaultThreshold: fp('0.015').toString(), // 2% = 0.5% oracleError + 1% buffer | ||
| delayUntilDefault: bn('86400').toString(), // 24h | ||
| }, | ||
| '0' // revenueHiding = 0 | ||
| ) | ||
| await collateral.deployed() | ||
|
|
||
| console.log(`Deployed snARS to ${hre.network.name} (${chainId}): ${collateral.address}`) | ||
| await (await collateral.refresh()).wait() | ||
| expect(await collateral.status()).to.equal(CollateralStatus.SOUND) | ||
|
|
||
| assetCollDeployments.collateral.snARS = collateral.address | ||
| assetCollDeployments.erc20s.snARS = networkConfig[chainId].tokens.snARS | ||
| 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 hidden or 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,53 @@ | ||
| import hre from 'hardhat' | ||
| import { getChainId } from '../../../common/blockchain-utils' | ||
| import { developmentChains, networkConfig } from '../../../common/configuration' | ||
| import { fp, bn } from '../../../common/numbers' | ||
| import { | ||
| getDeploymentFile, | ||
| getAssetCollDeploymentFilename, | ||
| IAssetCollDeployments, | ||
| } from '../../deployment/common' | ||
| import { priceTimeout, verifyContract } from '../../deployment/utils' | ||
|
|
||
| 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 snARS **************************/ | ||
| await verifyContract( | ||
| chainId, | ||
| deployments.collateral.snARS, | ||
| [ | ||
| { | ||
| priceTimeout: priceTimeout.toString(), | ||
| chainlinkFeed: networkConfig[chainId].chainlinkFeeds.snARS, | ||
| oracleError: fp('0.01').toString(), // 1% | ||
| erc20: networkConfig[chainId].tokens.snARS, | ||
| maxTradeVolume: fp('1e6').toString(), // $1m, | ||
| oracleTimeout: '3600', // 1 hr | ||
| targetName: hre.ethers.utils.formatBytes32String('ARS'), | ||
| defaultThreshold: fp('0.02').toString(), // 2% | ||
| delayUntilDefault: bn('86400').toString(), // 24h | ||
| }, | ||
| '0', // revenueHiding = 0 | ||
| ], | ||
| 'contracts/plugins/assets/num/SnARSFiatCollateral.sol:SnARSFiatCollateral' | ||
| ) | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error) | ||
| process.exitCode = 1 | ||
| }) |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.