Skip to content

Commit

Permalink
Merge pull request #436 from DistributedCollective/merge-dev-to-master
Browse files Browse the repository at this point in the history
Loan token enhancements v1.20.0
  • Loading branch information
tjcloa authored May 6, 2022
2 parents 101c27a + 6b09a19 commit 068ce8a
Show file tree
Hide file tree
Showing 341 changed files with 72,863 additions and 62,931 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
artifacts
build
cache
coverage
types
reports
tmp
26 changes: 13 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
mocha: true, // for test files
"truffle/globals": true, // same as "truffle/truffle": true
},
extends: "prettier",
parserOptions: {
ecmaVersion: 2020,
},
rules: {},
plugins: ["truffle"],
env: {
browser: true,
commonjs: true,
es2021: true,
mocha: true, // for test files
"truffle/globals": true, // same as "truffle/truffle": true
},
extends: "prettier",
parserOptions: {
ecmaVersion: 2020,
},
rules: {},
plugins: ["truffle"],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ignore/
!.gitattributes
!.solhint.json
!.solhintignore
!.eslintignore
ignore
*.txt
*.log
Expand Down
4 changes: 2 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"require": "hardhat/register",
"timeout": 40000
"require": "hardhat/register",
"timeout": 40000
}
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ hardhat-ganache-tests.config.js
cache
brownie-config.yaml
.vscode
abi
abi
types/
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{
"files": ["*.sol", "*.js", "*.test.js", "*.json"],
"options": {
"printWidth": 140,
"printWidth": 99,
"tabWidth": 4,
"useTabs": true,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": true,
"explicitTypes": "always"
Expand Down
10 changes: 9 additions & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
skipFiles: ["mockup", "testhelpers", "openzeppelin", "mixins/EnumerableAddressSet.sol", "node_modules", "interfaces", "events"],
skipFiles: [
"mockup",
"testhelpers",
"openzeppelin",
"mixins/EnumerableAddressSet.sol",
"node_modules",
"interfaces",
"events",
],
};
14 changes: 7 additions & 7 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"max-line-length": ["warn", 140],
"compiler-version": ["warn"]
}
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"max-line-length": ["warn", 140],
"compiler-version": ["warn"]
}
}
2 changes: 1 addition & 1 deletion brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ project_structure:
networks:
default: development
development:
gas_limit: 6800000
gas_limit: 2800000
gas_price: 65000000
reverting_tx_gas_limit: 8000000
default_contract_owner: true
Expand Down
156 changes: 78 additions & 78 deletions contracts/connectors/loantoken/AdvancedToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,92 +19,92 @@ import "./AdvancedTokenStorage.sol";
* its Loan Dai iTokens.
* */
contract AdvancedToken is AdvancedTokenStorage {
using SafeMath for uint256;
using SafeMath for uint256;

/**
* @notice Set an amount as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*
* @param _spender The account address that will be able to spend the tokens.
* @param _value The amount of tokens allowed to spend.
* */
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @notice Set an amount as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*
* @param _spender The account address that will be able to spend the tokens.
* @param _value The amount of tokens allowed to spend.
* */
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}

/**
* @notice The iToken minting process. Meant to issue Loan iTokens.
* Lenders are able to open an iToken position, by minting them.
* This function is called by LoanTokenLogicStandard::_mintToken
* @param _to The recipient of the minted tTokens.
* @param _tokenAmount The amount of iTokens to be minted.
* @param _assetAmount The amount of lended tokens (asset to lend).
* @param _price The price of the lended tokens.
* @return The updated balance of the recipient.
* */
function _mint(
address _to,
uint256 _tokenAmount,
uint256 _assetAmount,
uint256 _price
) internal returns (uint256) {
require(_to != address(0), "15");
/**
* @notice The iToken minting process. Meant to issue Loan iTokens.
* Lenders are able to open an iToken position, by minting them.
* This function is called by LoanTokenLogicStandard::_mintToken
* @param _to The recipient of the minted tTokens.
* @param _tokenAmount The amount of iTokens to be minted.
* @param _assetAmount The amount of lended tokens (asset to lend).
* @param _price The price of the lended tokens.
* @return The updated balance of the recipient.
* */
function _mint(
address _to,
uint256 _tokenAmount,
uint256 _assetAmount,
uint256 _price
) internal returns (uint256) {
require(_to != address(0), "15");

uint256 _balance = balances[_to].add(_tokenAmount);
balances[_to] = _balance;
uint256 _balance = balances[_to].add(_tokenAmount);
balances[_to] = _balance;

totalSupply_ = totalSupply_.add(_tokenAmount);
totalSupply_ = totalSupply_.add(_tokenAmount);

emit Mint(_to, _tokenAmount, _assetAmount, _price);
emit Transfer(address(0), _to, _tokenAmount);
emit Mint(_to, _tokenAmount, _assetAmount, _price);
emit Transfer(address(0), _to, _tokenAmount);

return _balance;
}
return _balance;
}

/**
* @notice The iToken burning process. Meant to destroy Loan iTokens.
* Lenders are able to close an iToken position, by burning them.
* This function is called by LoanTokenLogicStandard::_burnToken
* @param _who The owner of the iTokens to burn.
* @param _tokenAmount The amount of iTokens to burn.
* @param _assetAmount The amount of lended tokens.
* @param _price The price of the lended tokens.
* @return The updated balance of the iTokens owner.
* */
function _burn(
address _who,
uint256 _tokenAmount,
uint256 _assetAmount,
uint256 _price
) internal returns (uint256) {
//bzx compare
//TODO: Unit test
uint256 _balance = balances[_who].sub(_tokenAmount, "16");
/**
* @notice The iToken burning process. Meant to destroy Loan iTokens.
* Lenders are able to close an iToken position, by burning them.
* This function is called by LoanTokenLogicStandard::_burnToken
* @param _who The owner of the iTokens to burn.
* @param _tokenAmount The amount of iTokens to burn.
* @param _assetAmount The amount of lended tokens.
* @param _price The price of the lended tokens.
* @return The updated balance of the iTokens owner.
* */
function _burn(
address _who,
uint256 _tokenAmount,
uint256 _assetAmount,
uint256 _price
) internal returns (uint256) {
//bzx compare
//TODO: Unit test
uint256 _balance = balances[_who].sub(_tokenAmount, "16");

// a rounding error may leave dust behind, so we clear this out
if (_balance <= 10) {
// We can't leave such small balance quantities.
_tokenAmount = _tokenAmount.add(_balance);
_balance = 0;
}
balances[_who] = _balance;
// a rounding error may leave dust behind, so we clear this out
if (_balance <= 10) {
// We can't leave such small balance quantities.
_tokenAmount = _tokenAmount.add(_balance);
_balance = 0;
}
balances[_who] = _balance;

totalSupply_ = totalSupply_.sub(_tokenAmount);
totalSupply_ = totalSupply_.sub(_tokenAmount);

emit Burn(_who, _tokenAmount, _assetAmount, _price);
emit Transfer(_who, address(0), _tokenAmount);
return _balance;
}
emit Burn(_who, _tokenAmount, _assetAmount, _price);
emit Transfer(_who, address(0), _tokenAmount);
return _balance;
}
}
Loading

0 comments on commit 068ce8a

Please sign in to comment.