From f29033021dd3e4bf28250334a0db7b0fba0557aa Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 22 Oct 2024 20:42:57 -0400 Subject: [PATCH 1/4] docs --- docs/demurrage-collateral.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/demurrage-collateral.md b/docs/demurrage-collateral.md index ccb9a7ebd..952f6a0b7 100644 --- a/docs/demurrage-collateral.md +++ b/docs/demurrage-collateral.md @@ -59,16 +59,12 @@ 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. - ### Implementation [DemurrageCollateral.sol](../contracts/plugins/assets/DemurrageCollateral.sol) implements a generalized demurrage collateral plugin that should support almost all use-cases From 61dc3d2f1a0cdd73e9dda5bc44b9bb026984e7c7 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Tue, 22 Oct 2024 20:45:56 -0400 Subject: [PATCH 2/4] new base addresses --- scripts/addresses/8453-tmp-assets-collateral.json | 10 +++++----- .../base-3.4.0/8453-tmp-assets-collateral.json | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/addresses/8453-tmp-assets-collateral.json b/scripts/addresses/8453-tmp-assets-collateral.json index 9b5fcc8af..b761e0e44 100644 --- a/scripts/addresses/8453-tmp-assets-collateral.json +++ b/scripts/addresses/8453-tmp-assets-collateral.json @@ -12,8 +12,8 @@ "saBasUSDC": "0xC19f5d60e2Aca1174f3D5Fe189f0A69afaB76f50", "cUSDCv3": "0xf7a9D27c3B60c78c6F6e2c2d6ED6E8B94b352461", "wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73", - "EURC": "0x7321485aA1D0439296B882bBc85Eb0BD350F8381", - "cbBTC": "0x06f7D10f5842fc5816DF9A9DD65f84481B1490E3" + "DMR100cbBTC": "0x27Bb9158A6727aBdcaF6A1B983FFCA94E41d5616", + "DMR100EURC": "0x3a55cEE81eaDaB7F64430ff0148F547baFD993fb" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -26,7 +26,7 @@ "STG": "0xE3B53AF74a4BF62Ae5511055290838050bf764Df", "cUSDCv3": "0x53f1Df4E5591Ae35Bf738742981669c3767241FA", "wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452", - "EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42", - "cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf" + "DMR100cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", + "DMR100EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42" } -} \ No newline at end of file +} diff --git a/scripts/addresses/base-3.4.0/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.4.0/8453-tmp-assets-collateral.json index 4602fbd2d..b761e0e44 100644 --- a/scripts/addresses/base-3.4.0/8453-tmp-assets-collateral.json +++ b/scripts/addresses/base-3.4.0/8453-tmp-assets-collateral.json @@ -11,7 +11,9 @@ "cbETH": "0x851B461a9744f4c9E996C03072cAB6f44Fa04d0D", "saBasUSDC": "0xC19f5d60e2Aca1174f3D5Fe189f0A69afaB76f50", "cUSDCv3": "0xf7a9D27c3B60c78c6F6e2c2d6ED6E8B94b352461", - "wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73" + "wstETH": "0x8b4374005291B8FCD14C4E947604b2FB3C660A73", + "DMR100cbBTC": "0x27Bb9158A6727aBdcaF6A1B983FFCA94E41d5616", + "DMR100EURC": "0x3a55cEE81eaDaB7F64430ff0148F547baFD993fb" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -23,6 +25,8 @@ "saBasUSDC": "0x6F6f81e5E66f503184f2202D83a79650c3285759", "STG": "0xE3B53AF74a4BF62Ae5511055290838050bf764Df", "cUSDCv3": "0x53f1Df4E5591Ae35Bf738742981669c3767241FA", - "wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452" + "wstETH": "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452", + "DMR100cbBTC": "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf", + "DMR100EURC": "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42" } } From 02ec0097050e549225b1dd4dbb0b78d0f81d4518 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Wed, 23 Oct 2024 17:53:44 -0400 Subject: [PATCH 3/4] verificaton scripts + nits --- contracts/plugins/assets/DemurrageCollateral.sol | 4 ++-- docs/demurrage-collateral.md | 2 ++ scripts/verification/collateral-plugins/verify_arb_100.ts | 2 +- scripts/verification/collateral-plugins/verify_cbbtc_100.ts | 4 ++-- scripts/verification/collateral-plugins/verify_eurc_100.ts | 4 ++-- scripts/verification/collateral-plugins/verify_paxg_100.ts | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/contracts/plugins/assets/DemurrageCollateral.sol b/contracts/plugins/assets/DemurrageCollateral.sol index 8745de362..74e4beceb 100644 --- a/contracts/plugins/assets/DemurrageCollateral.sol +++ b/contracts/plugins/assets/DemurrageCollateral.sol @@ -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} @@ -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 diff --git a/docs/demurrage-collateral.md b/docs/demurrage-collateral.md index 952f6a0b7..e10213c25 100644 --- a/docs/demurrage-collateral.md +++ b/docs/demurrage-collateral.md @@ -65,6 +65,8 @@ This is identical to the calculation for the `refPerTok()` function in the [Demu weight = 1 / (1 - fee) ^ seconds; ``` +`fee()` available on DemurrageCollateral contract + ### Implementation [DemurrageCollateral.sol](../contracts/plugins/assets/DemurrageCollateral.sol) implements a generalized demurrage collateral plugin that should support almost all use-cases diff --git a/scripts/verification/collateral-plugins/verify_arb_100.ts b/scripts/verification/collateral-plugins/verify_arb_100.ts index 44b21a904..0c4a4433f 100644 --- a/scripts/verification/collateral-plugins/verify_arb_100.ts +++ b/scripts/verification/collateral-plugins/verify_arb_100.ts @@ -49,7 +49,7 @@ async function main() { await verifyContract( chainId, - assetCollDeployments.collateral.ARB, + assetCollDeployments.collateral.DMR100ARB, [ { erc20: networkConfig[chainId].tokens.ARB, diff --git a/scripts/verification/collateral-plugins/verify_cbbtc_100.ts b/scripts/verification/collateral-plugins/verify_cbbtc_100.ts index 112a85a28..c1809ce3f 100644 --- a/scripts/verification/collateral-plugins/verify_cbbtc_100.ts +++ b/scripts/verification/collateral-plugins/verify_cbbtc_100.ts @@ -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, diff --git a/scripts/verification/collateral-plugins/verify_eurc_100.ts b/scripts/verification/collateral-plugins/verify_eurc_100.ts index 759cce433..5886dd3e3 100644 --- a/scripts/verification/collateral-plugins/verify_eurc_100.ts +++ b/scripts/verification/collateral-plugins/verify_eurc_100.ts @@ -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, diff --git a/scripts/verification/collateral-plugins/verify_paxg_100.ts b/scripts/verification/collateral-plugins/verify_paxg_100.ts index f99deaba2..cbf0a250d 100644 --- a/scripts/verification/collateral-plugins/verify_paxg_100.ts +++ b/scripts/verification/collateral-plugins/verify_paxg_100.ts @@ -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, From 29f2191c447e1292b7624d81cbf7b5e85d7fe437 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 25 Oct 2024 16:35:07 -0400 Subject: [PATCH 4/4] fix test --- test/scenario/DemurrageCollateral.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/scenario/DemurrageCollateral.test.ts b/test/scenario/DemurrageCollateral.test.ts index 93e428373..f5517836f 100644 --- a/test/scenario/DemurrageCollateral.test.ts +++ b/test/scenario/DemurrageCollateral.test.ts @@ -64,7 +64,7 @@ describeP1(`Demurrage Collateral - P${IMPLEMENTATION}`, () => { coll: DemurrageCollateral, decayedAmt: BigNumber ): Promise => { - 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)) }