Skip to content

Commit df978a3

Browse files
feat: gnosis deployment (#209)
* first draft immutable borrow contracts * 2nd draft gold stablecoin * first batch of test done * update final hash of vaultManager implementation * feat: gnosis deployment * fix: failing tests --------- Co-authored-by: gs8nrv <[email protected]>
1 parent 0937abd commit df978a3

28 files changed

+7703
-87
lines changed

contracts/agToken/AgTokenSideChainImmutable.sol

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ import "./AgTokenSideChain.sol";
88
/// @author Angle Labs, Inc.
99
/// @notice Contract for immutable Angle's stablecoins
1010
contract AgTokenSideChainImmutable is AgTokenSideChain {
11-
constructor(
12-
string memory name_,
13-
string memory symbol_,
14-
address _treasury
15-
) AgTokenSideChain() initializer {
11+
constructor(string memory name_, string memory symbol_, address _treasury) AgTokenSideChain() initializer {
1612
_initializeBase(name_, symbol_, _treasury);
1713
}
1814

1915
/// @inheritdoc BaseAgTokenSideChain
20-
function _initialize(
21-
string memory name_,
22-
string memory symbol_,
23-
address _treasury
24-
) internal override {}
16+
function _initialize(string memory name_, string memory symbol_, address _treasury) internal override {}
2517
}

contracts/agToken/BaseAgTokenSideChain.sol

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ contract BaseAgTokenSideChain is IAgToken, ERC20PermitUpgradeable {
6868

6969
/// @notice Wraps `_initializeBase` for `BaseAgTokenSideChain` and makes a safety check
7070
/// on `_treasury`
71-
function _initialize(
72-
string memory name_,
73-
string memory symbol_,
74-
address _treasury
75-
) internal virtual initializer {
71+
function _initialize(string memory name_, string memory symbol_, address _treasury) internal virtual initializer {
7672
if (address(ITreasury(_treasury).stablecoin()) != address(this)) revert InvalidTreasury();
7773
_initializeBase(name_, symbol_, _treasury);
7874
}
@@ -84,11 +80,7 @@ contract BaseAgTokenSideChain is IAgToken, ERC20PermitUpgradeable {
8480
/// @param name_ Name of the token
8581
/// @param symbol_ Symbol of the token
8682
/// @param _treasury Reference to the `Treasury` contract associated to this agToken implementation
87-
function _initializeBase(
88-
string memory name_,
89-
string memory symbol_,
90-
address _treasury
91-
) internal virtual {
83+
function _initializeBase(string memory name_, string memory symbol_, address _treasury) internal virtual {
9284
__ERC20Permit_init(name_);
9385
__ERC20_init(name_, symbol_);
9486
treasury = _treasury;
@@ -127,11 +119,7 @@ contract BaseAgTokenSideChain is IAgToken, ERC20PermitUpgradeable {
127119
}
128120

129121
/// @inheritdoc IAgToken
130-
function burnFrom(
131-
uint256 amount,
132-
address burner,
133-
address sender
134-
) external onlyMinter {
122+
function burnFrom(uint256 amount, address burner, address sender) external onlyMinter {
135123
_burnFromNoRedeem(amount, burner, sender);
136124
}
137125

@@ -166,11 +154,7 @@ contract BaseAgTokenSideChain is IAgToken, ERC20PermitUpgradeable {
166154
/// @notice Internal version of the function `burnFromNoRedeem`
167155
/// @param amount Amount to burn
168156
/// @dev It is at the level of this function that allowance checks are performed
169-
function _burnFromNoRedeem(
170-
uint256 amount,
171-
address burner,
172-
address sender
173-
) internal {
157+
function _burnFromNoRedeem(uint256 amount, address burner, address sender) internal {
174158
if (burner != sender) {
175159
uint256 currentAllowance = allowance(burner, sender);
176160
if (currentAllowance < amount) revert BurnAmountExceedsAllowance();

contracts/treasury/Treasury.sol

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,9 @@ contract Treasury is ITreasury, Initializable {
220220
/// @return badDebtValue Value the `badDebt` should have after the call if it was updated
221221
/// @dev This internal function is never to be called alone, and should always be called in conjunction
222222
/// with the `_updateSurplusAndBadDebt` function
223-
function _fetchSurplusFromList(address[] memory vaultManagers)
224-
internal
225-
returns (uint256 surplusBufferValue, uint256 badDebtValue)
226-
{
223+
function _fetchSurplusFromList(
224+
address[] memory vaultManagers
225+
) internal returns (uint256 surplusBufferValue, uint256 badDebtValue) {
227226
badDebtValue = badDebt;
228227
surplusBufferValue = surplusBuffer;
229228
uint256 newSurplus;
@@ -246,10 +245,10 @@ contract Treasury is ITreasury, Initializable {
246245
/// @dev When calling this function, it is possible that there is a positive `surplusBufferValue` and `badDebtValue`,
247246
/// this function tries to reconcile both values and makes sure that we either have surplus or bad debt but not both
248247
/// at the same time
249-
function _updateSurplusAndBadDebt(uint256 surplusBufferValue, uint256 badDebtValue)
250-
internal
251-
returns (uint256, uint256)
252-
{
248+
function _updateSurplusAndBadDebt(
249+
uint256 surplusBufferValue,
250+
uint256 badDebtValue
251+
) internal returns (uint256, uint256) {
253252
if (badDebtValue != 0) {
254253
// If we have bad debt we need to burn stablecoins that accrued to the protocol
255254
// We still need to make sure that we're not burning too much or as much as we can if the debt is big
@@ -336,11 +335,7 @@ contract Treasury is ITreasury, Initializable {
336335
/// and from the flash loan module
337336
/// @dev If the token to recover is the stablecoin, tokens recovered are fetched
338337
/// from the surplus and not from the `surplusBuffer`
339-
function recoverERC20(
340-
address tokenAddress,
341-
address to,
342-
uint256 amountToRecover
343-
) external onlyGovernor {
338+
function recoverERC20(address tokenAddress, address to, uint256 amountToRecover) external onlyGovernor {
344339
// Cannot recover stablecoin if badDebt or tap into the surplus buffer
345340
if (tokenAddress == address(stablecoin)) {
346341
_fetchSurplusFromAll();

contracts/treasury/TreasuryImmutable.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ contract TreasuryImmutable is Treasury {
1717

1818
// =============================== Errors ======================================
1919

20+
error AlreadySetStablecoin();
2021
error InvalidVaultManager();
2122
error InvalidStablecoin();
2223

contracts/vaultManager/VaultManager.sol

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
8484
if (_oracle.treasury() != _treasury) revert InvalidTreasury();
8585
treasury = _treasury;
8686
collateral = _collateral;
87-
_collatBase = 10**(IERC20Metadata(address(collateral)).decimals());
87+
_collatBase = 10 ** (IERC20Metadata(address(collateral)).decimals());
8888
stablecoin = IAgToken(_treasury.stablecoin());
8989
oracle = _oracle;
9090
string memory _name = string.concat("Angle Protocol ", _symbol, " Vault");
@@ -343,7 +343,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
343343

344344
uint256 stablecoinAmountLessFeePaid = (stablecoinAmount *
345345
(BASE_PARAMS - repayFee_) *
346-
(BASE_PARAMS - _borrowFee)) / (BASE_PARAMS**2);
346+
(BASE_PARAMS - _borrowFee)) / (BASE_PARAMS ** 2);
347347
surplus += stablecoinAmount - stablecoinAmountLessFeePaid;
348348
_repayDebt(vaultID, stablecoinAmountLessFeePaid, 0);
349349
}
@@ -365,11 +365,10 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
365365
/// @param liquidator Address of the liquidator which will be performing the liquidation
366366
/// @return liqOpp Description of the opportunity of liquidation
367367
/// @dev This function will revert if it's called on a vault that does not exist
368-
function checkLiquidation(uint256 vaultID, address liquidator)
369-
external
370-
view
371-
returns (LiquidationOpportunity memory liqOpp)
372-
{
368+
function checkLiquidation(
369+
uint256 vaultID,
370+
address liquidator
371+
) external view returns (LiquidationOpportunity memory liqOpp) {
373372
liqOpp = _checkLiquidation(
374373
vaultData[vaultID],
375374
liquidator,
@@ -392,15 +391,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
392391
Vault memory vault,
393392
uint256 oracleValue,
394393
uint256 newInterestAccumulator
395-
)
396-
internal
397-
view
398-
returns (
399-
uint256 healthFactor,
400-
uint256 currentDebt,
401-
uint256 collateralAmountInStable
402-
)
403-
{
394+
) internal view returns (uint256 healthFactor, uint256 currentDebt, uint256 collateralAmountInStable) {
404395
currentDebt = (vault.normalizedDebt * newInterestAccumulator) / BASE_INTEREST;
405396
collateralAmountInStable = (vault.collateralAmount * oracleValue) / _collatBase;
406397
if (currentDebt == 0) healthFactor = type(uint256).max;
@@ -803,7 +794,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
803794
// Checking if we're in a situation where the health factor is an increasing or a decreasing function of the
804795
// amount repaid. In the first case, the health factor is an increasing function which means that the liquidator
805796
// can bring the vault to the target health ratio
806-
if (healthFactor * liquidationDiscount * surcharge >= collateralFactor * BASE_PARAMS**2) {
797+
if (healthFactor * liquidationDiscount * surcharge >= collateralFactor * BASE_PARAMS ** 2) {
807798
// This is the max amount to repay that will bring the person to the target health factor
808799
// Denom is always positive when a vault gets liquidated in this case and when the health factor
809800
// is an increasing function of the amount of stablecoins repaid
@@ -812,7 +803,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
812803
((targetHealthFactor * currentDebt - collateralAmountInStable * collateralFactor) *
813804
BASE_PARAMS *
814805
liquidationDiscount) /
815-
(surcharge * targetHealthFactor * liquidationDiscount - (BASE_PARAMS**2) * collateralFactor);
806+
(surcharge * targetHealthFactor * liquidationDiscount - (BASE_PARAMS ** 2) * collateralFactor);
816807
// Need to check for the dust as liquidating should not leave a dusty amount in the vault
817808
uint256 dustParameter = dustLiquidation;
818809
if (currentDebt * BASE_PARAMS <= maxAmountToRepay * surcharge + dustParameter * BASE_PARAMS) {
@@ -950,11 +941,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
950941
/// @param _dustLiquidation New `dustLiquidation` value
951942
/// @param dustCollateral_ New minimum collateral allowed in a vault after a liquidation
952943
/// @dev dustCollateral_ is in stable value
953-
function setDusts(
954-
uint256 _dust,
955-
uint256 _dustLiquidation,
956-
uint256 dustCollateral_
957-
) external onlyGovernor {
944+
function setDusts(uint256 _dust, uint256 _dustLiquidation, uint256 dustCollateral_) external onlyGovernor {
958945
if (_dust > _dustLiquidation) revert InvalidParameterValue();
959946
dust = _dust;
960947
dustLiquidation = _dustLiquidation;
@@ -982,11 +969,7 @@ contract VaultManager is VaultManagerPermit, IVaultManagerFunctions {
982969
/// @param amount Collateral amount balance of the owner of vaultID increase/decrease
983970
/// @param add Whether the balance should be increased/decreased
984971
/// @param vaultID Vault which sees its collateral amount changed
985-
function _checkpointCollateral(
986-
uint256 vaultID,
987-
uint256 amount,
988-
bool add
989-
) internal virtual {}
972+
function _checkpointCollateral(uint256 vaultID, uint256 amount, bool add) internal virtual {}
990973

991974
/// @notice Get `paused` in storage only if needed
992975
function _paused() internal view virtual returns (bool) {

deploy/0_proxyAdmin.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,33 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
1111
const { deployer } = await ethers.getNamedSigners();
1212
let proxyAdmin: ProxyAdmin;
1313
let guardian: string;
14+
let governor: string;
1415

1516
if (!network.live) {
1617
// If we're in mainnet fork, we're using the `ProxyAdmin` address from mainnet
1718
guardian = CONTRACTS_ADDRESSES[ChainId.MAINNET]?.Guardian!;
19+
governor = CONTRACTS_ADDRESSES[ChainId.MAINNET]?.Governor!;
1820
} else {
1921
// Otherwise, we're using the proxy admin address from the desired network
2022
guardian = CONTRACTS_ADDRESSES[network.config.chainId as ChainId]?.Guardian!;
23+
guardian = '0xf0A31faec2B4fC6396c65B1aF1F6A71E653f11F0';
24+
governor = '0x0F70EeD1Bb51d5eDB1a2E46142638df959bAFD69';
2125
}
22-
26+
/*
2327
console.log(`Now deploying ProxyAdmin on the chain ${network.config.chainId}`);
24-
console.log('Guardian address is ', guardian);
25-
await deploy('ProxyAdminGuardian', {
28+
console.log('Governor address is ', governor);
29+
await deploy('ProxyAdmin', {
2630
contract: 'ProxyAdmin',
2731
from: deployer.address,
2832
log: !argv.ci,
2933
});
30-
const proxyAdminAddress = (await ethers.getContract('ProxyAdminGuardian')).address;
34+
*/
35+
const proxyAdminAddress = (await ethers.getContract('ProxyAdmin')).address;
3136

3237
proxyAdmin = new ethers.Contract(proxyAdminAddress, ProxyAdmin__factory.createInterface(), deployer) as ProxyAdmin;
3338

34-
console.log(`Transferring ownership of the proxy admin to the guardian ${guardian}`);
35-
await (await proxyAdmin.connect(deployer).transferOwnership(guardian)).wait();
39+
console.log(`Transferring ownership of the proxy admin to the governor ${governor}`);
40+
await (await proxyAdmin.connect(deployer).transferOwnership(governor)).wait();
3641
console.log('Success');
3742
};
3843

deploy/2_agTokenImplementation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const argv = yargs.env('').boolean('ci').parseSync();
77
const func: DeployFunction = async ({ deployments, ethers, network }) => {
88
const { deploy } = deployments;
99
const { deployer } = await ethers.getNamedSigners();
10-
const stableName = 'GOLD';
10+
const stableName = 'EUR';
1111

1212
let implementationName: string;
1313
let proxyAdmin: string;
@@ -18,6 +18,7 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
1818
} else {
1919
implementationName = 'AgTokenSideChainMultiBridge';
2020
proxyAdmin = registry(network.config.chainId as ChainId)?.ProxyAdmin!;
21+
proxyAdmin = '0x9a5b060Bd7b8f86c4C0D720a17367729670AfB19';
2122
}
2223

2324
console.log(`Now deploying the implementation for AgToken on ${network.name}`);

deploy/3_treasury.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
1212
const { deployer } = await ethers.getNamedSigners();
1313
let proxyAdmin: string;
1414
let coreBorrow: string;
15-
const stableName = 'GOLD';
15+
const stableName = 'EUR';
1616
const agTokenName = `ag${stableName}`;
1717

1818
const agTokenAddress = (await deployments.get(`AgToken_${stableName}`)).address;
@@ -24,6 +24,8 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
2424
} else {
2525
proxyAdmin = registry(network.config.chainId as ChainId)?.ProxyAdmin!;
2626
coreBorrow = registry(network.config.chainId as ChainId)?.CoreBorrow!;
27+
proxyAdmin = '0x9a5b060Bd7b8f86c4C0D720a17367729670AfB19';
28+
coreBorrow = '0x3E399AE5B4D8bc0021e53b51c8BCdD66DD62c03b';
2729
}
2830

2931
let treasuryImplementation: string;
@@ -61,5 +63,5 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
6163
};
6264

6365
func.tags = ['treasury'];
64-
func.dependencies = ['agTokenImplementation'];
66+
// func.dependencies = ['agTokenImplementation'];
6567
export default func;

deploy/bridges/LayerZeroBridgeToken.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { deployImplem, deployProxy } from '../helpers';
88
const stable = 'EUR';
99

1010
const func: DeployFunction = async ({ ethers, network }) => {
11-
const treasury = await ethers.getContract('Treasury');
11+
const treasury = await ethers.getContract('Treasury_EUR');
1212
const proxyAdmin = await ethers.getContract('ProxyAdmin');
1313

1414
const endpointAddr = (LZ_ENDPOINTS as { [name: string]: string })[network.name];
@@ -24,7 +24,7 @@ const func: DeployFunction = async ({ ethers, network }) => {
2424
`LZ-ag${stable}`,
2525
endpointAddr,
2626
treasury.address,
27-
parseEther('100000'),
27+
parseEther('0'),
2828
]),
2929
);
3030

deploy/bridges/LayerZeroSetSources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const func: DeployFunction = async ({ ethers, network }) => {
1515
avalanche: '0x14C00080F97B9069ae3B4Eb506ee8a633f8F5434',
1616
bsc: '0xe9f183FC656656f1F17af1F2b0dF79b8fF9ad8eD',
1717
celo: '0xf1dDcACA7D17f8030Ab2eb54f2D9811365EFe123',
18+
gnosis: '0xFA5Ed56A203466CbBC2430a43c66b9D8723528E7',
1819
};
1920

2021
const local = OFTs[network.name];

0 commit comments

Comments
 (0)