From a966d9f53f1262a186cbcbb313648b0ec2794965 Mon Sep 17 00:00:00 2001 From: David Racero Date: Wed, 28 Oct 2020 18:39:19 +0100 Subject: [PATCH] Added new StringLib library with concat to reuse function in deployment helpers. --- .../deployments/ATokensAndRatesHelper.sol | 9 +++---- .../StableAndVariableTokensHelper.sol | 13 ++++----- contracts/libraries/helpers/StringLib.sol | 8 ++++++ deployed-contracts.json | 27 +++++++++++++++---- package.json | 1 + test/atoken-transfer.spec.ts | 4 +++ test/stable-token.spec.ts | 3 +++ 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 contracts/libraries/helpers/StringLib.sol diff --git a/contracts/deployments/ATokensAndRatesHelper.sol b/contracts/deployments/ATokensAndRatesHelper.sol index 83146959..769b98fc 100644 --- a/contracts/deployments/ATokensAndRatesHelper.sol +++ b/contracts/deployments/ATokensAndRatesHelper.sol @@ -10,6 +10,7 @@ import { DefaultReserveInterestRateStrategy } from '../lendingpool/DefaultReserveInterestRateStrategy.sol'; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; +import {StringLib} from '../libraries/helpers/StringLib.sol'; contract ATokensAndRatesHelper is Ownable { address payable private pool; @@ -27,10 +28,6 @@ contract ATokensAndRatesHelper is Ownable { poolConfigurator = _poolConfigurator; } - function concat(string memory a, string memory b) internal pure returns (string memory) { - return string(abi.encodePacked(a, b)); - } - function initDeployment( address[] calldata tokens, string[] calldata symbols, @@ -47,8 +44,8 @@ contract ATokensAndRatesHelper is Ownable { LendingPool(pool), tokens[i], address(0), - concat('Aave interest bearing ', symbols[i]), - concat('a', symbols[i]), + StringLib.concat('Aave interest bearing ', symbols[i]), + StringLib.concat('a', symbols[i]), incentivesController ) ), diff --git a/contracts/deployments/StableAndVariableTokensHelper.sol b/contracts/deployments/StableAndVariableTokensHelper.sol index 54d6ffcb..9722424e 100644 --- a/contracts/deployments/StableAndVariableTokensHelper.sol +++ b/contracts/deployments/StableAndVariableTokensHelper.sol @@ -6,6 +6,7 @@ import {StableDebtToken} from '../tokenization/StableDebtToken.sol'; import {VariableDebtToken} from '../tokenization/VariableDebtToken.sol'; import {LendingRateOracle} from '../mocks/oracle/LendingRateOracle.sol'; import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol'; +import {StringLib} from '../libraries/helpers/StringLib.sol'; contract StableAndVariableTokensHelper is Ownable { address payable private pool; @@ -17,10 +18,6 @@ contract StableAndVariableTokensHelper is Ownable { addressesProvider = _addressesProvider; } - function concat(string memory a, string memory b) internal pure returns (string memory) { - return string(abi.encodePacked(a, b)); - } - function initDeployment( address[] calldata tokens, string[] calldata symbols, @@ -34,8 +31,8 @@ contract StableAndVariableTokensHelper is Ownable { new StableDebtToken( pool, tokens[i], - concat('Aave stable debt bearing ', symbols[i]), - concat('stableDebt', symbols[i]), + StringLib.concat('Aave stable debt bearing ', symbols[i]), + StringLib.concat('stableDebt', symbols[i]), incentivesController ) ), @@ -43,8 +40,8 @@ contract StableAndVariableTokensHelper is Ownable { new VariableDebtToken( pool, tokens[i], - concat('Aave variable debt bearing ', symbols[i]), - concat('variableDebt', symbols[i]), + StringLib.concat('Aave variable debt bearing ', symbols[i]), + StringLib.concat('variableDebt', symbols[i]), incentivesController ) ) diff --git a/contracts/libraries/helpers/StringLib.sol b/contracts/libraries/helpers/StringLib.sol new file mode 100644 index 00000000..fd4584a0 --- /dev/null +++ b/contracts/libraries/helpers/StringLib.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: agpl-3.0 +pragma solidity ^0.6.8; + +library StringLib { + function concat(string memory a, string memory b) internal pure returns (string memory) { + return string(abi.encodePacked(a, b)); + } +} diff --git a/deployed-contracts.json b/deployed-contracts.json index ef612b08..642cd6a5 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -163,26 +163,25 @@ }, "ReserveLogic": { "buidlerevm": { - "address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c", + "address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "GenericLogic": { "buidlerevm": { - "address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7", + "address": "0x6082731fdAba4761277Fb31299ebC782AD3bCf24", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "ValidationLogic": { "buidlerevm": { - "address": "0xA4765Ff72A9F3CfE73089bb2c3a41B838DF71574", + "address": "0x8456161947DFc1fC159A0B26c025cD2b4bba0c3e", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "LendingPool": { "buidlerevm": { - "address": "0x35c1419Da7cf0Ff885B8Ef8EA9242FEF6800c99b", - "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" } }, "LendingPoolConfigurator": { @@ -247,5 +246,23 @@ "address": "0x1256eBA4d0a7A38D10BaF4F61775ba491Ce7EE25", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } + }, + "MockAToken": { + "buidlerevm": { + "address": "0x77B0b5636fEA30eA79BB65AeCCdb599997A849A8", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + } + }, + "MockStableDebtToken": { + "buidlerevm": { + "address": "0x78Ee8Fb9fE5abD5e347Fc94c2fb85596d1f60e3c", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + } + }, + "MockVariableDebtToken": { + "buidlerevm": { + "address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + } } } diff --git a/package.json b/package.json index fd75fdb8..931b1186 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "test-deploy": "buidler test test/__setup.spec.ts test/test-init.spec.ts", "test-pausable": "buidler test test/__setup.spec.ts test/pausable-functions.spec.ts", "test-permit": "buidler test test/__setup.spec.ts test/atoken-permit.spec.ts", + "test-stable-and-atokens": "buidler test test/__setup.spec.ts test/atoken-transfer.spec.ts test/stable-token.spec.ts", "test-subgraph:scenarios": "buidler --network buidlerevm_docker test test/__setup.spec.ts test/subgraph-scenarios.spec.ts", "dev:coverage": "buidler coverage --network coverage", "dev:deployment": "buidler dev-deployment", diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index 0e207e17..10bf15d4 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -36,6 +36,10 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { await aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit); + const name = await aDai.name(); + + expect(name).to.be.equal('Aave interest bearing DAI'); + const fromBalance = await aDai.balanceOf(users[0].address); const toBalance = await aDai.balanceOf(users[1].address); diff --git a/test/stable-token.spec.ts b/test/stable-token.spec.ts index 422cb352..fea265c6 100644 --- a/test/stable-token.spec.ts +++ b/test/stable-token.spec.ts @@ -34,6 +34,9 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => { daiStableDebtTokenAddress ); + const name = await stableDebtContract.name(); + + expect(name).to.be.equal('Aave stable debt bearing DAI'); await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith( CALLER_MUST_BE_LENDING_POOL );