@andrekorol/kollateral-contracts
Version:
Kollateral protocol, the flash loan building block
1,139 lines (1,138 loc) • 354 kB
JSON
{
"contractName": "CollateralizedToken",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "minter",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "tokenAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "kTokenAmount",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "redeemer",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "tokenAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "kTokenAmount",
"type": "uint256"
}
],
"name": "Redeem",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "subtractedValue",
"type": "uint256"
}
],
"name": "decreaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "addedValue",
"type": "uint256"
}
],
"name": "increaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "kTokenAmount",
"type": "uint256"
}
],
"name": "redeem",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenAmount",
"type": "uint256"
}
],
"name": "redeemUnderlying",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "nativeAmount",
"type": "uint256"
}
],
"name": "nativeAmountToUnderlyingAmount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "underlyingAmount",
"type": "uint256"
},
{
"internalType": "bool",
"name": "ceil",
"type": "bool"
}
],
"name": "underlyingAmountToNativeAmount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "isUnderlyingEther",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalReserve",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOfUnderlying",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "underlying",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.7.3+commit.9bfce1f6\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"minter\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"tokenAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"kTokenAmount\",\"type\":\"uint256\"}],\"name\":\"Mint\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"redeemer\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"tokenAmount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"kTokenAmount\",\"type\":\"uint256\"}],\"name\":\"Redeem\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOfUnderlying\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"subtractedValue\",\"type\":\"uint256\"}],\"name\":\"decreaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"addedValue\",\"type\":\"uint256\"}],\"name\":\"increaseAllowance\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"isUnderlyingEther\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"nativeAmount\",\"type\":\"uint256\"}],\"name\":\"nativeAmountToUnderlyingAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"kTokenAmount\",\"type\":\"uint256\"}],\"name\":\"redeem\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenAmount\",\"type\":\"uint256\"}],\"name\":\"redeemUnderlying\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalReserve\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"underlying\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"underlyingAmount\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"ceil\",\"type\":\"bool\"}],\"name\":\"underlyingAmountToNativeAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{\"allowance(address,address)\":{\"details\":\"See {IERC20-allowance}.\"},\"approve(address,uint256)\":{\"details\":\"See {IERC20-approve}. Requirements: - `spender` cannot be the zero address.\"},\"balanceOf(address)\":{\"details\":\"See {IERC20-balanceOf}.\"},\"decimals()\":{\"details\":\"Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` (`505 / 10 ** 2`). Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is called. NOTE: This information is only used for _display_ purposes: it in no way affects any of the arithmetic of the contract, including {IERC20-balanceOf} and {IERC20-transfer}.\"},\"decreaseAllowance(address,uint256)\":{\"details\":\"Atomically decreases the allowance granted to `spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements: - `spender` cannot be the zero address. - `spender` must have allowance for the caller of at least `subtractedValue`.\"},\"increaseAllowance(address,uint256)\":{\"details\":\"Atomically increases the allowance granted to `spender` by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements: - `spender` cannot be the zero address.\"},\"name()\":{\"details\":\"Returns the name of the token.\"},\"symbol()\":{\"details\":\"Returns the symbol of the token, usually a shorter version of the name.\"},\"totalSupply()\":{\"details\":\"See {IERC20-totalSupply}.\"},\"transfer(address,uint256)\":{\"details\":\"See {IERC20-transfer}. Requirements: - `recipient` cannot be the zero address. - the caller must have a balance of at least `amount`.\"},\"transferFrom(address,address,uint256)\":{\"details\":\"See {IERC20-transferFrom}. Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {ERC20}. Requirements: - `sender` and `recipient` cannot be the zero address. - `sender` must have a balance of at least `amount`. - the caller must have allowance for ``sender``'s tokens of at least `amount`.\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/Users/andrekorol/src/kollateral/protocol/contracts/token/CollateralizedToken.sol\":\"CollateralizedToken\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol\":{\"keccak256\":\"0x5ced249631b5dfe431f449d725d9f318b01ab0785306ca5e73cdf43760ab271a\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://3f3aef65abfcc02e451ad27a849caba0e6375abb26e28e7605928d19d561c3dd\",\"dweb:/ipfs/QmY5zMeH5x3QMS5xkxkY3DH4SDPWLGJyfPk1R8wPJXH9vr\"]},\"/Users/andrekorol/src/kollateral/protocol/contracts/token/CollateralizedToken.sol\":{\"keccak256\":\"0xfaaaa4324c6cc78d9d1268426eb04fe41d8584ade05bbf22eac4875ecdf174d7\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://1e4149a0ecd14003c261b2243adfc19d7a009c83c32341ebdd6a8929c0bdd14d\",\"dweb:/ipfs/QmQbySda22WBU4oycYfrTye1RsJuz1Ub74ksoST7PeegHW\"]},\"/Users/andrekorol/src/kollateral/protocol/contracts/token/UnlimitedApprovalErc20.sol\":{\"keccak256\":\"0x407178fcd78f0a19d705e64aaaa26ae997d228f077f3cf6833f9f3eb31c72308\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://097906cbe6f8f35ba1763bd122d551ec302f45cf677021bbcdb8a55c706940d9\",\"dweb:/ipfs/QmVh7kcUWsXt3QApppB1njhGHfzdP813KSTUF6bh3VCmMM\"]},\"@openzeppelin/contracts/GSN/Context.sol\":{\"keccak256\":\"0x910a2e625b71168563edf9eeef55a50d6d699acfe27ceba3921f291829a8f938\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://248246ac66e6479dce1ad7d4945ec5540c98ceb09881e93c93f7c48d5772925c\",\"dweb:/ipfs/QmXr8tmUiZgEYid6ixeeBRmTdUnASWjKzhP3KRxMPy8fRt\"]},\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0xba96bc371ba999f452985a98717cca1e4c4abb598dc038a9a9c3db08129b1ba4\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://26e50e3f7b6482fb6f598f2e006994a74aa492687daa4b3eee7fd4fb5398ce7f\",\"dweb:/ipfs/QmZudqoPSkA4USLMFsBBmt19dDPZFS8aaAmL5R7pECXu6t\"]},\"@openzeppelin/contracts/token/ERC20/ERC20.sol\":{\"keccak256\":\"0x482b6d82ba1c9c73758ae15068a438361d4187b7a4e342db17ef0f828cb5e21a\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://89725e56bc9c6cfb69521ceaa4a489561b928e930b71e30db85b24024c1c2c03\",\"dweb:/ipfs/QmNvpotZA1Fe48msV6TShSTVxeQ2dkaDS9MTKP4bNxyUG3\"]},\"@openzeppelin/contracts/token/ERC20/IERC20.sol\":{\"keccak256\":\"0xbd74f587ab9b9711801baf667db1426e4a03fd2d7f15af33e0e0d0394e7cef76\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://2d0913dfbfce90d170df0d496ad7596c0778518e5fa7aba6c32562522546f66b\",\"dweb:/ipfs/QmR6B8nLj2PJf5e1JWD9Nk7ErkAwkqUwadCnvE82FJr1RU\"]},\"@openzeppelin/contracts/utils/ReentrancyGuard.sol\":{\"keccak256\":\"0x1153f6dd334c01566417b8c551122450542a2b75a2bbb379d59a8c320ed6da28\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://002b4e5c26a2a069ba42486b83bf9c4b5461f3d5def32f9ef52b0aef8905d6d2\",\"dweb:/ipfs/QmPG44XDF4npiqRzzGvqJroDtUKfcR78wcreQ9bXa6guW6\"]}},\"version\":1}",
"bytecode": "0x",
"deployedBytecode": "0x",
"immutableReferences": {},
"generatedSources": [],
"deployedGeneratedSources": [],
"sourceMap": "",
"deployedSourceMap": "",
"source": "/*\n\n Copyright 2020 Kollateral LLC.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\n// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.7.0;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"../common/utils/ExtendedMath.sol\";\nimport \"./UnlimitedApprovalErc20.sol\";\n\nabstract contract CollateralizedToken is\n UnlimitedApprovalErc20,\n ReentrancyGuard,\n ExtendedMath\n{\n using SafeMath for uint256;\n\n event Mint(address minter, uint256 tokenAmount, uint256 kTokenAmount);\n event Redeem(address redeemer, uint256 tokenAmount, uint256 kTokenAmount);\n\n address internal _underlying;\n\n constructor(address underlying) {\n _underlying = underlying;\n }\n\n /*\n * BALANCE UPDATE\n */\n\n function redeem(uint256 kTokenAmount) external returns (bool) {\n require(totalSupply() > 0, \"CollateralizedToken: no supply\");\n return\n redeemInternal(\n nativeAmountToUnderlyingAmount(kTokenAmount),\n kTokenAmount\n );\n }\n\n function redeemUnderlying(uint256 tokenAmount) external returns (bool) {\n require(totalReserve() > 0, \"CollateralizedToken: no reserve\");\n return\n redeemInternal(\n tokenAmount,\n underlyingAmountToNativeAmountInternal(tokenAmount, true, false)\n );\n }\n\n function mintInternal(uint256 amount) internal nonReentrant returns (bool) {\n uint256 kTokenAmount;\n if (totalReserve().sub(amount) > 0) {\n kTokenAmount = underlyingAmountToNativeAmountInternal(\n amount,\n false,\n true\n );\n } else {\n kTokenAmount = amount;\n }\n _mint(msg.sender, kTokenAmount);\n emit Mint(msg.sender, amount, kTokenAmount);\n\n return true;\n }\n\n function redeemInternal(uint256 tokenAmount, uint256 kTokenAmount)\n internal\n nonReentrant\n returns (bool)\n {\n _burn(msg.sender, kTokenAmount);\n require(\n transferUnderlying(msg.sender, tokenAmount),\n \"CollateralizedToken: token transfer failed\"\n );\n emit Redeem(msg.sender, tokenAmount, kTokenAmount);\n\n return true;\n }\n\n function transferUnderlying(address to, uint256 amount)\n internal\n virtual\n returns (bool);\n\n /*\n * VIEWS\n */\n\n function nativeAmountToUnderlyingAmount(uint256 nativeAmount)\n public\n view\n returns (uint256)\n {\n if (totalSupply() == 0) {\n return 0;\n }\n\n return nativeAmount.mul(totalReserve()).div(totalSupply());\n }\n\n function underlyingAmountToNativeAmount(uint256 underlyingAmount, bool ceil)\n public\n view\n returns (uint256)\n {\n return\n underlyingAmountToNativeAmountInternal(\n underlyingAmount,\n ceil,\n false\n );\n }\n\n function underlyingAmountToNativeAmountInternal(\n uint256 underlyingAmount,\n bool ceil,\n bool subtractDeposit\n ) internal view returns (uint256) {\n if (totalReserve() == 0) {\n return 0;\n }\n\n /* mint() pulls in funds before calling mintInternal() - normalize for pre-funding amount */\n uint256 adjustedTotalReserve = subtractDeposit\n ? totalReserve().sub(underlyingAmount)\n : totalReserve();\n\n /* round mint() down and redeemUnderlying() up to avoid over-ownership exploits */\n return\n divAndRound(\n underlyingAmount.mul(totalSupply()),\n adjustedTotalReserve,\n ceil\n );\n }\n\n function isUnderlyingEther() public view virtual returns (bool);\n\n function totalReserve() public view virtual returns (uint256);\n\n function balanceOfUnderlying(address owner) public view returns (uint256) {\n return nativeAmountToUnderlyingAmount(balanceOf(owner));\n }\n\n function underlying() public view returns (address) {\n return _underlying;\n }\n}\n",
"sourcePath": "/Users/andrekorol/src/kollateral/protocol/contracts/token/CollateralizedToken.sol",
"ast": {
"absolutePath": "/Users/andrekorol/src/kollateral/protocol/contracts/token/CollateralizedToken.sol",
"exportedSymbols": {
"CollateralizedToken": [
5197
],
"Context": [
5279
],
"ERC20": [
6087
],
"ExtendedMath": [
1506
],
"IERC20": [
6165
],
"ReentrancyGuard": [
6295
],
"SafeMath": [
5584
],
"UnlimitedApprovalErc20": [
5256
]
},
"id": 5198,
"license": "Apache-2.0",
"nodeType": "SourceUnit",
"nodes": [
{
"id": 4896,
"literals": [
"solidity",
"^",
"0.7",
".0"
],
"nodeType": "PragmaDirective",
"src": "640:23:36"
},
{
"absolutePath": "@openzeppelin/contracts/math/SafeMath.sol",
"file": "@openzeppelin/contracts/math/SafeMath.sol",
"id": 4897,
"nodeType": "ImportDirective",
"scope": 5198,
"sourceUnit": 5585,
"src": "665:51:36",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "@openzeppelin/contracts/utils/ReentrancyGuard.sol",
"file": "@openzeppelin/contracts/utils/ReentrancyGuard.sol",
"id": 4898,
"nodeType": "ImportDirective",
"scope": 5198,
"sourceUnit": 6296,
"src": "717:59:36",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol",
"file": "../common/utils/ExtendedMath.sol",
"id": 4899,
"nodeType": "ImportDirective",
"scope": 5198,
"sourceUnit": 1507,
"src": "777:42:36",
"symbolAliases": [],
"unitAlias": ""
},
{
"absolutePath": "/Users/andrekorol/src/kollateral/protocol/contracts/token/UnlimitedApprovalErc20.sol",
"file": "./UnlimitedApprovalErc20.sol",
"id": 4900,
"nodeType": "ImportDirective",
"scope": 5198,
"sourceUnit": 5257,
"src": "820:38:36",
"symbolAliases": [],
"unitAlias": ""
},
{
"abstract": true,
"baseContracts": [
{
"baseName": {
"id": 4901,
"name": "UnlimitedApprovalErc20",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5256,
"src": "905:22:36",
"typeDescriptions": {
"typeIdentifier": "t_contract$_UnlimitedApprovalErc20_$5256",
"typeString": "contract UnlimitedApprovalErc20"
}
},
"id": 4902,
"nodeType": "InheritanceSpecifier",
"src": "905:22:36"
},
{
"baseName": {
"id": 4903,
"name": "ReentrancyGuard",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 6295,
"src": "933:15:36",
"typeDescriptions": {
"typeIdentifier": "t_contract$_ReentrancyGuard_$6295",
"typeString": "contract ReentrancyGuard"
}
},
"id": 4904,
"nodeType": "InheritanceSpecifier",
"src": "933:15:36"
},
{
"baseName": {
"id": 4905,
"name": "ExtendedMath",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 1506,
"src": "954:12:36",
"typeDescriptions": {
"typeIdentifier": "t_contract$_ExtendedMath_$1506",
"typeString": "contract ExtendedMath"
}
},
"id": 4906,
"nodeType": "InheritanceSpecifier",
"src": "954:12:36"
}
],
"contractDependencies": [
1506,
5256,
5279,
6087,
6165,
6295
],
"contractKind": "contract",
"fullyImplemented": false,
"id": 5197,
"linearizedBaseContracts": [
5197,
1506,
6295,
5256,
6087,
6165,
5279
],
"name": "CollateralizedToken",
"nodeType": "ContractDefinition",
"nodes": [
{
"id": 4909,
"libraryName": {
"id": 4907,
"name": "SafeMath",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 5584,
"src": "979:8:36",
"typeDescriptions": {
"typeIdentifier": "t_contract$_SafeMath_$5584",
"typeString": "library SafeMath"
}
},
"nodeType": "UsingForDirective",
"src": "973:27:36",
"typeName": {
"id": 4908,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "992:7:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
}
},
{
"anonymous": false,
"id": 4917,
"name": "Mint",
"nodeType": "EventDefinition",
"parameters": {
"id": 4916,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4911,
"indexed": false,
"mutability": "mutable",
"name": "minter",
"nodeType": "VariableDeclaration",
"scope": 4917,
"src": "1017:14:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"typeName": {
"id": 4910,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "1017:7:36",
"stateMutability": "nonpayable",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"visibility": "internal"
},
{
"constant": false,
"id": 4913,
"indexed": false,
"mutability": "mutable",
"name": "tokenAmount",
"nodeType": "VariableDeclaration",
"scope": 4917,
"src": "1033:19:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4912,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1033:7:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
},
{
"constant": false,
"id": 4915,
"indexed": false,
"mutability": "mutable",
"name": "kTokenAmount",
"nodeType": "VariableDeclaration",
"scope": 4917,
"src": "1054:20:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4914,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1054:7:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
}
],
"src": "1016:59:36"
},
"src": "1006:70:36"
},
{
"anonymous": false,
"id": 4925,
"name": "Redeem",
"nodeType": "EventDefinition",
"parameters": {
"id": 4924,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4919,
"indexed": false,
"mutability": "mutable",
"name": "redeemer",
"nodeType": "VariableDeclaration",
"scope": 4925,
"src": "1094:16:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"typeName": {
"id": 4918,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "1094:7:36",
"stateMutability": "nonpayable",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"visibility": "internal"
},
{
"constant": false,
"id": 4921,
"indexed": false,
"mutability": "mutable",
"name": "tokenAmount",
"nodeType": "VariableDeclaration",
"scope": 4925,
"src": "1112:19:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4920,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1112:7:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
},
{
"constant": false,
"id": 4923,
"indexed": false,
"mutability": "mutable",
"name": "kTokenAmount",
"nodeType": "VariableDeclaration",
"scope": 4925,
"src": "1133:20:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 4922,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1133:7:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
}
],
"src": "1093:61:36"
},
"src": "1081:74:36"
},
{
"constant": false,
"id": 4927,
"mutability": "mutable",
"name": "_underlying",
"nodeType": "VariableDeclaration",
"scope": 5197,
"src": "1161:28:36",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"typeName": {
"id": 4926,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "1161:7:36",
"stateMutability": "nonpayable",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"visibility": "internal"
},
{
"body": {
"id": 4936,
"nodeType": "Block",
"src": "1228:41:36",
"statements": [
{
"expression": {
"id": 4934,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"id": 4932,
"name": "_underlying",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4927,
"src": "1238:11:36",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"nodeType": "Assignment",
"operator": "=",
"rightHandSide": {
"id": 4933,
"name": "underlying",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4929,
"src": "1252:10:36",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"src": "1238:24:36",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"id": 4935,
"nodeType": "ExpressionStatement",
"src": "1238:24:36"
}
]
},
"id": 4937,
"implemented": true,
"kind": "constructor",
"modifiers": [],
"name": "",
"nodeType": "FunctionDefinition",
"parameters": {
"id": 4930,
"nodeType": "ParameterList",
"parameters": [
{
"constant": false,
"id": 4929,
"mutability": "mutable",
"name": "underlying",
"nodeType": "VariableDeclaration",
"scope": 4937,
"src": "1208:18:36",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
},
"typeName": {
"id": 4928,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "1208:7:36",
"stateMutability": "nonpayable",
"typeDescriptions": {
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"visibility": "internal"
}
],
"src": "1207:20:36"
},
"returnParameters": {
"id": 4931,
"nodeType": "ParameterList",
"parameters": [],
"src": "1228:0:36"
},
"scope": 5197,
"src": "1196:73:36",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "internal"
},
{
"body": {
"id": 4959,
"nodeType": "Block",
"src": "1375:226:36",
"statements": [
{
"expression": {
"arguments": [
{
"commonType": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"id": 4948,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression": {
"arguments": [],
"expression": {
"argumentTypes": [],
"id": 4945,
"name": "totalSupply",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 5673,
"src": "1393:11:36",
"typeDescriptions": {
"typeIdentifier": "t_function_internal_view$__$returns$_t_uint256_$",
"typeString": "function () view returns (uint256)"
}
},
"id": 4946,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "1393:13:36",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "BinaryOperation",
"operator": ">",
"rightExpression": {
"hexValue": "30",
"id": 4947,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1409:1:36",
"typeDescriptions": {
"typeIdentifier": "t_rational_0_by_1",
"typeString": "int_const 0"
},
"value": "0"
},
"src": "1393:17:36",
"typeDescriptions": {
"typeIdentifier": "t_bool",
"typeString": "bool"
}
},
{
"hexValue": "436f6c6c61746572616c697a6564546f6b656e3a206e6f20737570706c79",
"id": 4949,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "string",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1412:32:36",
"typeDescriptions": {
"typeIdentifier": "t_stringliteral_772cc97f39593e560676bdf1c5edd13e2266c876d2b90f9f9b1c71a1f64f4b51",
"typeString": "literal_string \"CollateralizedToken: no supply\""
},
"value": "CollateralizedToken: no supply"
}
],
"expression": {
"argumentTypes": [
{
"typeIdentifier": "t_bool",
"typeString": "bool"
},
{
"typeIdentifier": "t_stringliteral_772cc97f39593e560676bdf1c5edd13e2266c876d2b90f9f9b1c71a1f64f4b51",
"typeString": "literal_string \"CollateralizedToken: no supply\""
}
],
"id": 4944,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
-18,
-18
],
"referencedDeclaration": -18,
"src": "1385:7:36",
"typeDescriptions": {
"typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$",
"typeString": "function (bool,string memory) pure"
}
},
"id": 4950,
"isConstant": false,
"isLValue": false,
"isPure": false,
"kind": "functionCall",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "1385:60:36",
"tryCall": false,
"typeDescriptions": {
"typeIdentifier": "t_tuple$__$",
"typeString": "tuple()"
}
},
"id": 4951,
"nodeType": "ExpressionStatement",
"src": "1385:60:36"
},
{
"expression": {
"arguments": [
{
"arguments": [
{
"id": 4954,
"name": "kTokenAmount",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4939,
"src": "1537:12:36",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
}
],
"expression": {
"argumentTypes": [
{