Skip to content

Commit

Permalink
Merge branch 'demurrage-collateral' into unpriced-collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrent committed Oct 25, 2024
2 parents 3c3641e + 29f2191 commit b5557e8
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions contracts/plugins/assets/DemurrageCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract DemurrageCollateral is FiatCollateral {
using FixLib for uint192;
using OracleLib for AggregatorV3Interface;

uint48 public constant t0 = 1704067200; // {s} Jan 1st 2024 00:00:00 GMT+0000
uint48 public constant T0 = 1704067200; // {s} Jan 1st 2024 00:00:00 GMT+0000

bool internal immutable isFiat;
bool internal immutable targetUnitFeed0; // if true: feed0 is {target/tok}
Expand Down Expand Up @@ -141,7 +141,7 @@ contract DemurrageCollateral is FiatCollateral {
function refPerTok() public view override returns (uint192) {
// Monotonically increasing due to target unit (and reference unit) deflation

uint192 denominator = FIX_ONE.minus(fee).powu(uint48(block.timestamp - t0));
uint192 denominator = FIX_ONE.minus(fee).powu(uint48(block.timestamp - T0));
if (denominator == 0) return FIX_MAX; // TODO

// up-only
Expand Down
8 changes: 3 additions & 5 deletions docs/demurrage-collateral.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ This also means there can be multiple demurrage collateral for a single token. W

Prime basket weights are in units of January 1st 2024 collateral, not today's collateral. It doesn't matter if the collateral wasn't around in Jan 2024 -- when setting the basket weights the setter must take into account how much demurrage has occurred since January 1st 2024.

For example, say an asset has had 2% total demurrage since January 1st 2024 and you want to (on today's date) create a basket of that is worth $1: the correct basket weight to provide to `setPrimeBasket()` would be `1 / (1 - 0.02) = ~1.0204`.

To calculate total demurrage:
This is identical to the calculation for the `refPerTok()` function in the [DemurrageCollateral.sol](../contracts/plugins/assets/DemurrageCollateral.sol) contract, but calculating for an arbitrary timestamp.

```
1 - (1 - per_second_fee) ^ (seconds)
weight = 1 / (1 - fee) ^ seconds;
```

Switching between tiers requires calculating total demurrage for both tiers in order to ensure the basket change does not accidentally appreciate or depreciate the RToken.
`fee()` available on DemurrageCollateral contract

### Implementation

Expand Down
10 changes: 5 additions & 5 deletions scripts/addresses/8453-tmp-assets-collateral.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"saBasUSDC": "0xC19f5d60e2Aca1174f3D5Fe189f0A69afaB76f50",
"cUSDCv3": "0xf7a9D27c3B60c78c6F6e2c2d6ED6E8B94b352461",
"wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73",
"EURC": "0x7321485aA1D0439296B882bBc85Eb0BD350F8381",
"cbBTC": "0x06f7D10f5842fc5816DF9A9DD65f84481B1490E3"
"DMR100cbBTC": "0x27Bb9158A6727aBdcaF6A1B983FFCA94E41d5616",
"DMR100EURC": "0x3a55cEE81eaDaB7F64430ff0148F547baFD993fb"
},
"erc20s": {
"COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0",
Expand All @@ -26,7 +26,7 @@
"STG": "0xE3B53AF74a4BF62Ae5511055290838050bf764Df",
"cUSDCv3": "0x53f1Df4E5591Ae35Bf738742981669c3767241FA",
"wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
"EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
"cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf"
"DMR100cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
"DMR100EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
}
}
}
8 changes: 6 additions & 2 deletions scripts/addresses/base-3.4.0/8453-tmp-assets-collateral.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"cbETH": "0x851B461a9744f4c9E996C03072cAB6f44Fa04d0D",
"saBasUSDC": "0xC19f5d60e2Aca1174f3D5Fe189f0A69afaB76f50",
"cUSDCv3": "0xf7a9D27c3B60c78c6F6e2c2d6ED6E8B94b352461",
"wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73"
"wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73",
"DMR100cbBTC": "0x27Bb9158A6727aBdcaF6A1B983FFCA94E41d5616",
"DMR100EURC": "0x3a55cEE81eaDaB7F64430ff0148F547baFD993fb"
},
"erc20s": {
"COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0",
Expand All @@ -23,6 +25,8 @@
"saBasUSDC": "0x6F6f81e5E66f503184f2202D83a79650c3285759",
"STG": "0xE3B53AF74a4BF62Ae5511055290838050bf764Df",
"cUSDCv3": "0x53f1Df4E5591Ae35Bf738742981669c3767241FA",
"wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452"
"wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
"DMR100cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
"DMR100EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
}
}
2 changes: 1 addition & 1 deletion scripts/verification/collateral-plugins/verify_arb_100.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function main() {

await verifyContract(
chainId,
assetCollDeployments.collateral.ARB,
assetCollDeployments.collateral.DMR100ARB,
[
{
erc20: networkConfig[chainId].tokens.ARB,
Expand Down
4 changes: 2 additions & 2 deletions scripts/verification/collateral-plugins/verify_cbbtc_100.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ async function main() {

const collateral = await hre.ethers.getContractAt(
'ICollateral',
assetCollDeployments.collateral.cbBTC!
assetCollDeployments.collateral.DMR100cbBTC!
)

await verifyContract(
chainId,
assetCollDeployments.collateral.cbBTC,
assetCollDeployments.collateral.DMR100cbBTC,
[
{
erc20: networkConfig[chainId].tokens.cbBTC,
Expand Down
4 changes: 2 additions & 2 deletions scripts/verification/collateral-plugins/verify_eurc_100.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ async function main() {

const collateral = await hre.ethers.getContractAt(
'ICollateral',
assetCollDeployments.collateral.EURC!
assetCollDeployments.collateral.DMR100EURC!
)

await verifyContract(
chainId,
assetCollDeployments.collateral.EURC,
assetCollDeployments.collateral.DMR100EURC,
[
{
erc20: networkConfig[chainId].tokens.EURC,
Expand Down
4 changes: 2 additions & 2 deletions scripts/verification/collateral-plugins/verify_paxg_100.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ async function main() {

const collateral = await hre.ethers.getContractAt(
'ICollateral',
assetCollDeployments.collateral.PAXG!
assetCollDeployments.collateral.DMR100PAXG!
)

await verifyContract(
chainId,
assetCollDeployments.collateral.PAXG,
assetCollDeployments.collateral.DMR100PAXG,
[
{
erc20: networkConfig[chainId].tokens.PAXG,
Expand Down
2 changes: 1 addition & 1 deletion test/scenario/DemurrageCollateral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describeP1(`Demurrage Collateral - P${IMPLEMENTATION}`, () => {
coll: DemurrageCollateral,
decayedAmt: BigNumber
): Promise<BigNumber> => {
const elapsed = (await getLatestBlockTimestamp()) - (await coll.t0())
const elapsed = (await getLatestBlockTimestamp()) - (await coll.T0())
const decayFn = makeDecayFn(await coll.fee())
return fp('1e18').div(decayFn(decayedAmt, elapsed))
}
Expand Down

0 comments on commit b5557e8

Please sign in to comment.