@dolomite-exchange/dolomite-margin
Version:
Ethereum Smart Contracts and TypeScript library used for the DolomiteMargin trading protocol
805 lines (804 loc) • 318 kB
JSON
{
"contractName": "DoubleExponentInterestSetter",
"abi": [
{
"inputs": [
{
"components": [
{
"internalType": "uint128",
"name": "maxAPR",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "coefficients",
"type": "uint128"
}
],
"internalType": "struct DoubleExponentInterestSetter.PolyStorage",
"name": "params",
"type": "tuple"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "uint256",
"name": "borrowWei",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "supplyWei",
"type": "uint256"
}
],
"name": "getInterestRate",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"internalType": "struct Interest.Rate",
"name": "",
"type": "tuple"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getMaxAPR",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getCoefficients",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
],
"metadata": "{\"compiler\":{\"version\":\"0.5.16+commit.9c3226ce\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"components\":[{\"internalType\":\"uint128\",\"name\":\"maxAPR\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"coefficients\",\"type\":\"uint128\"}],\"internalType\":\"struct DoubleExponentInterestSetter.PolyStorage\",\"name\":\"params\",\"type\":\"tuple\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCoefficients\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"borrowWei\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"supplyWei\",\"type\":\"uint256\"}],\"name\":\"getInterestRate\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"}],\"internalType\":\"struct Interest.Rate\",\"name\":\"\",\"type\":\"tuple\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getMaxAPR\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"dYdX * Interest setter that sets interest based on a polynomial of the usage percentage of the market. Interest = C_0 + C_1 * U^(2^0) + C_2 * U^(2^1) + C_3 * U^(2^2) ...\",\"methods\":{\"getCoefficients()\":{\"return\":\"The coefficients\"},\"getInterestRate(address,uint256,uint256)\":{\"return\":\"The interest rate per second (times 10 ** 18)\"},\"getMaxAPR()\":{\"return\":\"The maximum APR\"}},\"title\":\"DoubleExponentInterestSetter\"},\"userdoc\":{\"methods\":{\"getCoefficients()\":{\"notice\":\"Get all of the coefficients of the interest calculation, starting from the coefficient for the first-order utilization variable.\"},\"getInterestRate(address,uint256,uint256)\":{\"notice\":\"Get the interest rate given some borrowed and supplied amounts. The interest function is a polynomial function of the utilization (borrowWei / supplyWei) of the market. * - If borrowWei > supplyWei then the utilization is considered to be equal to 1. - If both are zero, then the utilization is considered to be equal to 0.\"},\"getMaxAPR()\":{\"notice\":\"Get the maximum APR that this interestSetter will return. The actual APY may be higher depending on how often the interest is compounded.\"}}}},\"settings\":{\"compilationTarget\":{\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interestsetters/DoubleExponentInterestSetter.sol\":\"DoubleExponentInterestSetter\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":10000},\"remappings\":[]},\"sources\":{\"/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interestsetters/DoubleExponentInterestSetter.sol\":{\"keccak256\":\"0x4addd530b74b0d284c2497f40c1858812bda24297998091bc769cd2a57e73033\",\"urls\":[\"bzz-raw://c66134e987d91850eb438e9a5e59cf6877b6d00b8e78d38e69028c1d052c7dc6\",\"dweb:/ipfs/QmXwEeX8mPVmKzZfs4MX3KwHNvEazYfQks8YgPTG9YHozW\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IInterestSetter.sol\":{\"keccak256\":\"0x546825f65490a30e29d0f6446acec49c1e895ce6b33d48ca5c05092725a63a57\",\"urls\":[\"bzz-raw://6ad3013aed985bdf6e6234ae0f7f37e6bba76c3470c33bfa24678cf19b3b412c\",\"dweb:/ipfs/QmfYaSBzxGpgiHoR7ontMJY66S5L26XwkLYoEuzsEjpbQH\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Decimal.sol\":{\"keccak256\":\"0xd9a348c2b1eec076609ba12bbec6b9c2e4ea135790a7ef4f5411feb050af2144\",\"urls\":[\"bzz-raw://d5bcff29e47d5cd02d7a9966e9f44c46ccbb4f0e4adfc4b0b86646880677db39\",\"dweb:/ipfs/QmRKfJD4FFM1AvTynSFNx1NcDg94o9SAcjz7dvMaJCfecp\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/DolomiteMarginMath.sol\":{\"keccak256\":\"0x53f205f6a779d579be29faa9412c806a892b3e605fff092dfd9d14d936fa019f\",\"urls\":[\"bzz-raw://0ff936f89602a63b8e6a4eb4ce8f87673c0f45b7ce29694920905a3f0b5a6a69\",\"dweb:/ipfs/QmbYME9BeEvPC1ndV8EaUDX5fDMghLc3rocNUxFtgHmg8m\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Interest.sol\":{\"keccak256\":\"0x141a0ecb4a746f0e5767df4b99dbe33c6362df507ae9d5c02da1c1c17bc26df3\",\"urls\":[\"bzz-raw://9ff03e64a8ce5231acde07788624bf8c7a8ff55d90b157fa32f62fa887a0eff0\",\"dweb:/ipfs/QmUVxxWeE954RDXbmHJAYnHsXcit6rSXGqZUigu8t9oH2z\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Require.sol\":{\"keccak256\":\"0x05a2a90b41b6a5f42f0a72da63d015fb0b406a9ba2172823352e522e8bf3a606\",\"urls\":[\"bzz-raw://19883f0c6d33266f756ec5c3d17539524aa24b993c46c33f8400801d09373a6c\",\"dweb:/ipfs/QmYX2fwK3vQQDSZLMrc5wMfeb8RWrcC9CGX8XECLty8QDk\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Time.sol\":{\"keccak256\":\"0x87ee8d3c1d6e315a116426d8c8fc6f083e220fd14dda27fad4e8d7cab3dc7305\",\"urls\":[\"bzz-raw://7c20f2c52da682c3b5917fb6a19e81f43699b1d13c62b569ed723f34da72e766\",\"dweb:/ipfs/QmbXWYXi67nHBVNDKYUpo2E9ZaEVcHLvmXQkpYLMm1d5Vm\"]},\"/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Types.sol\":{\"keccak256\":\"0xe1bab8c8799d83e86c7a49aaf815d8e3bc8d09562d46d44d921500db5e98de0e\",\"urls\":[\"bzz-raw://8ea3d0cc4fdab6dd9bba545a792170f939b342d8d1a7051c1c6365009af72658\",\"dweb:/ipfs/QmaLJgbavu88eEit6JPqfWnw6NmGBDZfveMXxumgWywBFG\"]},\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0x640b6dee7a4b830bdfd52b5031a07fc2b12209f5b2e29e5d364a7d37f69d8076\",\"urls\":[\"bzz-raw://31113152e1ddb78fe7a4197f247591ca894e93f916867beb708d8e747b6cc74f\",\"dweb:/ipfs/QmbZaJyXdpsYGykVhHH9qpVGQg9DGCxE2QufbCUy3daTgq\"]}},\"version\":1}",
"bytecode": "0x608060405234801561001057600080fd5b5060405161072738038061072783398101604081905261002f91610117565b60208101516000906001600160801b03165b8015610059576101008106919091019060081c610041565b50606481146100835760405162461bcd60e51b815260040161007a90610176565b60405180910390fd5b508051600080546020909301516001600160801b03908116600160801b029281166001600160801b0319909416939093179092161790556101d8565b6000604082840312156100d157600080fd5b6100db6040610186565b905060006100e98484610106565b82525060206100fa84848301610106565b60208301525092915050565b8051610111816101c1565b92915050565b60006040828403121561012957600080fd5b600061013584846100bf565b949350505050565b600061014a601c836101ac565b7f436f656666696369656e7473206d7573742073756d20746f2031303000000000815260200192915050565b602080825281016101118161013d565b6040518181016001600160401b03811182821017156101a457600080fd5b604052919050565b90815260200190565b6001600160801b031690565b6101ca816101b5565b81146101d557600080fd5b50565b610540806101e76000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80631e68607a14610046578063afd4c8d614610064578063e8177dcf14610079575b600080fd5b61004e610099565b60405161005b919061049b565b60405180910390f35b61006c6100b1565b60405161005b919061046c565b61008c61008736600461032d565b61013e565b60405161005b919061048d565b6000546fffffffffffffffffffffffffffffffff1690565b604080516010808252610220820190925260609182919060208201610200803883395050600080549293509170010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1690505b801561013657610100810683838151811061011d57fe5b602090810291909101015260019091019060081c610106565b508152905090565b6101466102ed565b826101605750604080516020810190915260008152610280565b610168610300565b50604080518082019091526000546fffffffffffffffffffffffffffffffff8082168084527001000000000000000000000000000000009092041660208301528385106101d45760405180602001604052806301e1338083816101c757fe5b0481525092505050610280565b60208201516effffffffffffffffffffffffffffff600882901c169060ff16670de0b6b3a7640000908102906000908790610215908a63ffffffff61028716565b8161021c57fe5b0490505b60ff8316801561023f57818102830192508381141561023f5750610259565b5060089290921c91670de0b6b3a764000090800204610220565b6040805160208101909152806b0a3098c68eb9427db8000000848702049052955050505050505b9392505050565b600082610296575060006102e7565b828202828482816102a357fe5b04146102e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102db9061047d565b60405180910390fd5b90505b92915050565b6040518060200160405280600081525090565b604080518082019091526000808252602082015290565b80356102e7816104dd565b80356102e7816104f4565b60008060006060848603121561034257600080fd5b600061034e8686610317565b935050602061035f86828701610322565b925050604061037086828701610322565b9150509250925092565b6000610386838361045d565b505060200190565b6000610399826104af565b6103a381856104b3565b93506103ae836104a9565b8060005b838110156103dc5781516103c6888261037a565b97506103d1836104a9565b9250506001016103b2565b509495945050505050565b60006103f46021836104b3565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f81527f7700000000000000000000000000000000000000000000000000000000000000602082015260400192915050565b80516020830190610457848261045d565b50505050565b610466816104da565b82525050565b60208082528101610280818461038e565b602080825281016102e7816103e7565b602081016102e78284610446565b602081016102e7828461045d565b60200190565b5190565b90815260200190565b600073ffffffffffffffffffffffffffffffffffffffff82166102e7565b90565b6104e6816104bc565b81146104f157600080fd5b50565b6104e6816104da56fea365627a7a723158209e96ff507b912983dadfb6f0862171e8629e68b0f97e759b2c4c3d6817e61b046c6578706572696d656e74616cf564736f6c63430005100040",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c80631e68607a14610046578063afd4c8d614610064578063e8177dcf14610079575b600080fd5b61004e610099565b60405161005b919061049b565b60405180910390f35b61006c6100b1565b60405161005b919061046c565b61008c61008736600461032d565b61013e565b60405161005b919061048d565b6000546fffffffffffffffffffffffffffffffff1690565b604080516010808252610220820190925260609182919060208201610200803883395050600080549293509170010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1690505b801561013657610100810683838151811061011d57fe5b602090810291909101015260019091019060081c610106565b508152905090565b6101466102ed565b826101605750604080516020810190915260008152610280565b610168610300565b50604080518082019091526000546fffffffffffffffffffffffffffffffff8082168084527001000000000000000000000000000000009092041660208301528385106101d45760405180602001604052806301e1338083816101c757fe5b0481525092505050610280565b60208201516effffffffffffffffffffffffffffff600882901c169060ff16670de0b6b3a7640000908102906000908790610215908a63ffffffff61028716565b8161021c57fe5b0490505b60ff8316801561023f57818102830192508381141561023f5750610259565b5060089290921c91670de0b6b3a764000090800204610220565b6040805160208101909152806b0a3098c68eb9427db8000000848702049052955050505050505b9392505050565b600082610296575060006102e7565b828202828482816102a357fe5b04146102e4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102db9061047d565b60405180910390fd5b90505b92915050565b6040518060200160405280600081525090565b604080518082019091526000808252602082015290565b80356102e7816104dd565b80356102e7816104f4565b60008060006060848603121561034257600080fd5b600061034e8686610317565b935050602061035f86828701610322565b925050604061037086828701610322565b9150509250925092565b6000610386838361045d565b505060200190565b6000610399826104af565b6103a381856104b3565b93506103ae836104a9565b8060005b838110156103dc5781516103c6888261037a565b97506103d1836104a9565b9250506001016103b2565b509495945050505050565b60006103f46021836104b3565b7f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f81527f7700000000000000000000000000000000000000000000000000000000000000602082015260400192915050565b80516020830190610457848261045d565b50505050565b610466816104da565b82525050565b60208082528101610280818461038e565b602080825281016102e7816103e7565b602081016102e78284610446565b602081016102e7828461045d565b60200190565b5190565b90815260200190565b600073ffffffffffffffffffffffffffffffffffffffff82166102e7565b90565b6104e6816104bc565b81146104f157600080fd5b50565b6104e6816104da56fea365627a7a723158209e96ff507b912983dadfb6f0862171e8629e68b0f97e759b2c4c3d6817e61b046c6578706572696d656e74616cf564736f6c63430005100040",
"sourceMap": "1190:5111:10:-;;;1790:553;8:9:-1;5:2;;;30:1;27;20:12;5:2;1790:553:10;;;;;;;;;;;;;;;;;;;;;2007:19;;;;1927:25;;-1:-1:-1;1984:42:10;1966:201;2040:17;;1966:201;;2153:3;2138:12;:18;2117:39;;;;;1538:1;2071:21;1966:201;;;;1403:3;2197:17;:28;2176:103;;;;-1:-1:-1;2176:103:10;;;;;;;;;;;;;;;;;-1:-1:-1;2318:18:10;;:9;:18;;;;;;;-1:-1:-1;2318:18:10;;;-1:-1:-1;2318:18:10;;;;;;;;;;-1:-1:-1;2318:18:10;;;;1190:5111;;59:514:-1;;188:4;176:9;171:3;167:19;163:30;160:2;;;206:1;203;196:12;160:2;224:20;239:4;224:20;;;215:29;-1:-1;296:1;328:60;384:3;364:9;328:60;;;303:86;;-1:-1;458:2;491:60;547:3;523:22;;;491:60;;;484:4;477:5;473:16;466:86;410:153;154:419;;;;;580:134;658:13;;676:33;658:13;676:33;;;643:71;;;;;721:321;;865:2;853:9;844:7;840:23;836:32;833:2;;;881:1;878;871:12;833:2;916:1;933:93;1018:7;998:9;933:93;;;923:103;827:215;-1:-1;;;;827:215;1050:328;;1210:67;1274:2;1269:3;1210:67;;;1310:30;1290:51;;1369:2;1360:12;;1196:182;-1:-1;;1196:182;1386:407;1577:2;1591:47;;;1562:18;;1652:131;1562:18;1652:131;;1800:256;1862:2;1856:9;1888:17;;;1984:22;;;-1:-1;1948:34;;1945:62;1942:2;;;2020:1;2017;2010:12;1942:2;2036;2029:22;1840:216;;-1:-1;1840:216;2064:163;2167:19;;;2216:4;2207:14;;2160:67;2235:113;-1:-1;2297:46;;2280:68;2355:117;2424:24;2442:5;2424:24;;;2417:5;2414:35;2404:2;;2463:1;2460;2453:12;2404:2;2398:74;;;1190:5111:10;;;;;;",
"deployedSourceMap": "1190:5111:10:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;1190:5111:10;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5202:121;;;:::i;:::-;;;;;;;;;;;;;;;;5527:772;;;:::i;:::-;;;;;;;;2845:2145;;;;;;;;;:::i;:::-;;;;;;;;5202:121;5270:7;5300:16;;;5202:121;:::o;5527:772::-;5721:17;;;5735:2;5721:17;;;;;;;;;5601:16;;;;5721:17;;;;17:15:-1;;105:10;5721:17:10;88:34:-1;-1:-1;;5794:23:10;5872:22;;5695:43;;-1:-1:-1;5794:23:10;5872:22;;;;;;-1:-1:-1;5831:240:10;5908:17;;5831:240;;6026:3;6011:12;:18;5985:6;5992:15;5985:23;;;;;;;;;;;;;;;;;:44;6043:17;;;;;1538:1;5939:21;5831:240;;;-1:-1:-1;6228:31:10;;6235:6;-1:-1:-1;5527:772:10;:::o;2845:2145::-;3006:20;;:::i;:::-;3046:14;3042:107;;-1:-1:-1;3083:55:10;;;;;;;;;-1:-1:-1;3083:55:10;;3076:62;;3042:107;3159:20;;:::i;:::-;-1:-1:-1;3159:32:10;;;;;;;;;3182:9;3159:32;;;;;;;;;;;;;;;;;3241:22;;;3237:140;;3286:80;;;;;;;;1489:18;3325:6;:26;;;;;;3286:80;;;3279:87;;;;;;3237:140;3451:14;;;;3528:21;1538:1;3528:21;;;;;3492:26;;1437:8;3492:26;;;;3428:20;;3724:9;;3702:19;;3711:9;3702:19;:8;:19;:::i;:::-;:31;;;;;;3681:52;;3788:896;3879:28;;;3968:16;;3964:402;;4178:10;4164:11;:24;4154:34;;;;4292:12;4277:11;:27;4273:79;;;4328:5;;;4273:79;-1:-1:-1;1538:1:10;4652:21;;;;;1437:8;4567:23;;;:30;3788:896;;;4883:100;;;;;;;;;;4937:34;4918:15;;;:54;4883:100;;4876:107;-1:-1:-1;;;;;;2845:2145:10;;;;;;:::o;2159:459:150:-;2217:7;2458:6;2454:45;;-1:-1:-1;2487:1:150;2480:8;;2454:45;2521:5;;;2525:1;2521;:5;:1;2544:5;;;;;:10;2536:56;;;;;;;;;;;;;;;;;;;;;;2610:1;-1:-1:-1;2159:459:150;;;;;:::o;1190:5111:10:-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;-1:-1:-1;1190:5111:10;;;;;;;;:::o;5:130:-1:-;72:20;;97:33;72:20;97:33;;142:130;209:20;;234:33;209:20;234:33;;279:491;;;;417:2;405:9;396:7;392:23;388:32;385:2;;;433:1;430;423:12;385:2;468:1;485:53;530:7;510:9;485:53;;;475:63;;447:97;575:2;593:53;638:7;629:6;618:9;614:22;593:53;;;583:63;;554:98;683:2;701:53;746:7;737:6;726:9;722:22;701:53;;;691:63;;662:98;379:391;;;;;;778:173;;865:46;907:3;899:6;865:46;;;-1:-1;;940:4;931:14;;858:93;990:690;;1135:54;1183:5;1135:54;;;1202:86;1281:6;1276:3;1202:86;;;1195:93;;1309:56;1359:5;1309:56;;;1385:7;1413:1;1398:260;1423:6;1420:1;1417:13;1398:260;;;1490:6;1484:13;1511:63;1570:3;1555:13;1511:63;;;1504:70;;1591:60;1644:6;1591:60;;;1581:70;-1:-1;;1445:1;1438:9;1398:260;;;-1:-1;1671:3;;1114:566;-1:-1;;;;;1114:566;1689:370;;1849:67;1913:2;1908:3;1849:67;;;1949:34;1929:55;;2018:3;2013:2;2004:12;;1997:25;2050:2;2041:12;;1835:224;-1:-1;;1835:224;2118:319;2324:23;;2257:4;2248:14;;;2353:63;2252:3;2324:23;2353:63;;;2277:145;2230:207;;;;2444:103;2517:24;2535:5;2517:24;;;2512:3;2505:37;2499:48;;;2674:361;2842:2;2856:47;;;2827:18;;2917:108;2827:18;3011:6;2917:108;;3042:407;3233:2;3247:47;;;3218:18;;3308:131;3218:18;3308:131;;3456:305;3620:2;3605:18;;3634:117;3609:9;3724:6;3634:117;;3768:213;3886:2;3871:18;;3900:71;3875:9;3944:6;3900:71;;3988:151;4112:4;4103:14;;4060:79;4146:137;4249:12;;4220:63;4406:178;4524:19;;;4573:4;4564:14;;4517:67;4764:91;;4935:42;4924:54;;4826:24;4907:76;4990:72;5052:5;5035:27;5069:117;5138:24;5156:5;5138:24;;;5131:5;5128:35;5118:2;;5177:1;5174;5167:12;5118:2;5112:74;;5193:117;5262:24;5280:5;5262:24;",
"source": "/*\n\n Copyright 2019 dYdX Trading Inc.\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\npragma solidity ^0.5.7;\npragma experimental ABIEncoderV2;\n\nimport { SafeMath } from \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport { IInterestSetter } from \"../../protocol/interfaces/IInterestSetter.sol\";\nimport { Interest } from \"../../protocol/lib/Interest.sol\";\nimport { DolomiteMarginMath } from \"../../protocol/lib/DolomiteMarginMath.sol\";\n\n\n/**\n * @title DoubleExponentInterestSetter\n * @author dYdX\n *\n * Interest setter that sets interest based on a polynomial of the usage percentage of the market.\n * Interest = C_0 + C_1 * U^(2^0) + C_2 * U^(2^1) + C_3 * U^(2^2) ...\n */\ncontract DoubleExponentInterestSetter is\n IInterestSetter\n{\n using DolomiteMarginMath for uint256;\n using SafeMath for uint256;\n\n // ============ Constants ============\n\n uint256 constant PERCENT = 100;\n\n uint256 constant BASE = 10 ** 18;\n\n uint256 constant SECONDS_IN_A_YEAR = 60 * 60 * 24 * 365;\n\n uint256 constant BYTE = 8;\n\n // ============ Structs ============\n\n struct PolyStorage {\n uint128 maxAPR;\n uint128 coefficients;\n }\n\n // ============ Storage ============\n\n PolyStorage g_storage;\n\n // ============ Constructor ============\n\n constructor(\n PolyStorage memory params\n )\n public\n {\n // verify that all coefficients add up to 100%\n uint256 sumOfCoefficients = 0;\n for (\n uint256 coefficients = params.coefficients;\n coefficients != 0;\n coefficients >>= BYTE\n ) {\n sumOfCoefficients += coefficients % 256;\n }\n require(\n sumOfCoefficients == PERCENT,\n \"Coefficients must sum to 100\"\n );\n\n // store the params\n g_storage = params;\n }\n\n // ============ Public Functions ============\n\n /**\n * Get the interest rate given some borrowed and supplied amounts. The interest function is a\n * polynomial function of the utilization (borrowWei / supplyWei) of the market.\n *\n * - If borrowWei > supplyWei then the utilization is considered to be equal to 1.\n * - If both are zero, then the utilization is considered to be equal to 0.\n *\n * @return The interest rate per second (times 10 ** 18)\n */\n function getInterestRate(\n address /* token */,\n uint256 borrowWei,\n uint256 supplyWei\n )\n external\n view\n returns (Interest.Rate memory)\n {\n if (borrowWei == 0) {\n return Interest.Rate({\n value: 0\n });\n }\n\n PolyStorage memory s = g_storage;\n uint256 maxAPR = s.maxAPR;\n\n if (borrowWei >= supplyWei) {\n return Interest.Rate({\n value: maxAPR / SECONDS_IN_A_YEAR\n });\n }\n\n // process the first coefficient\n uint256 coefficients = s.coefficients;\n uint256 result = uint8(coefficients) * BASE;\n coefficients >>= BYTE;\n\n // initialize polynomial as the utilization\n // no safeDiv since supplyWei must be non-zero at this point\n uint256 polynomial = BASE.mul(borrowWei) / supplyWei;\n\n // for each non-zero coefficient...\n while (true) {\n // gets the lowest-order byte\n uint256 coefficient = uint256(uint8(coefficients));\n\n // if non-zero, add to result\n if (coefficient != 0) {\n // no safeAdd since there are at most 16 coefficients\n // no safeMul since (coefficient < 256 && polynomial <= 10**18)\n result += coefficient * polynomial;\n\n // break if this is the last non-zero coefficient\n if (coefficient == coefficients) {\n break;\n }\n }\n\n // double the order of the polynomial term\n // no safeMul since polynomial <= 10^18\n // no safeDiv since the divisor is a non-zero constant\n polynomial = polynomial * polynomial / BASE;\n\n // move to next coefficient\n coefficients >>= BYTE;\n }\n\n // normalize the result\n // no safeMul since result fits within 72 bits and maxAPR fits within 128 bits\n // no safeDiv since the divisor is a non-zero constant\n return Interest.Rate({\n value: result * maxAPR / (SECONDS_IN_A_YEAR * BASE * PERCENT)\n });\n }\n\n /**\n * Get the maximum APR that this interestSetter will return. The actual APY may be higher\n * depending on how often the interest is compounded.\n *\n * @return The maximum APR\n */\n function getMaxAPR()\n external\n view\n returns (uint256)\n {\n return g_storage.maxAPR;\n }\n\n /**\n * Get all of the coefficients of the interest calculation, starting from the coefficient for\n * the first-order utilization variable.\n *\n * @return The coefficients\n */\n function getCoefficients()\n external\n view\n returns (uint256[] memory)\n {\n // allocate new array with maximum of 16 coefficients\n uint256[] memory result = new uint256[](16);\n\n // add the coefficients to the array\n uint256 numCoefficients = 0;\n for (\n uint256 coefficients = g_storage.coefficients;\n coefficients != 0;\n coefficients >>= BYTE\n ) {\n result[numCoefficients] = coefficients % 256;\n numCoefficients++;\n }\n\n // modify result.length to match numCoefficients\n /* solium-disable-next-line security/no-inline-assembly */\n assembly {\n mstore(result, numCoefficients)\n }\n\n return result;\n }\n}\n",
"sourcePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interestsetters/DoubleExponentInterestSetter.sol",
"ast": {
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/external/interestsetters/DoubleExponentInterestSetter.sol",
"exportedSymbols": {
"DoubleExponentInterestSetter": [
3640
]
},
"id": 3641,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 3373,
"literals": [
"solidity",
"^",
"0.5",
".7"
],
"nodeType": "PragmaDirective",
"src": "603:23:10"
},
{
"id": 3374,
"literals": [
"experimental",
"ABIEncoderV2"
],
"nodeType": "PragmaDirective",
"src": "627:33:10"
},
{
"absolutePath": "@openzeppelin/contracts/math/SafeMath.sol",
"file": "@openzeppelin/contracts/math/SafeMath.sol",
"id": 3376,
"nodeType": "ImportDirective",
"scope": 3641,
"sourceUnit": 37366,
"src": "662:69:10",
"symbolAliases": [
{
"foreign": 3375,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/interfaces/IInterestSetter.sol",
"file": "../../protocol/interfaces/IInterestSetter.sol",
"id": 3378,
"nodeType": "ImportDirective",
"scope": 3641,
"sourceUnit": 24790,
"src": "732:80:10",
"symbolAliases": [
{
"foreign": 3377,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/Interest.sol",
"file": "../../protocol/lib/Interest.sol",
"id": 3380,
"nodeType": "ImportDirective",
"scope": 3641,
"sourceUnit": 27751,
"src": "813:59:10",
"symbolAliases": [
{
"foreign": 3379,
"local": null
}
],
"unitAlias": ""
},
{
"absolutePath": "/home/cdc218/projects/dolomite-protocol-v2/contracts/protocol/lib/DolomiteMarginMath.sol",
"file": "../../protocol/lib/DolomiteMarginMath.sol",
"id": 3382,
"nodeType": "ImportDirective",
"scope": 3641,
"sourceUnit": 26239,
"src": "873:79:10",
"symbolAliases": [
{
"foreign": 3381,
"local": null
}
],
"unitAlias": ""
},
{
"baseContracts": [
{
"arguments": null,
"baseName": {
"contractScope": null,
"id": 3383,
"name": "IInterestSetter",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 24789,
"src": "1235:15:10",
"typeDescriptions": {
"typeIdentifier": "t_contract$_IInterestSetter_$24789",
"typeString": "contract IInterestSetter"
}
},
"id": 3384,
"nodeType": "InheritanceSpecifier",
"src": "1235:15:10"
}
],
"contractDependencies": [
24789
],
"contractKind": "contract",
"documentation": "@title DoubleExponentInterestSetter\n@author dYdX\n * Interest setter that sets interest based on a polynomial of the usage percentage of the market.\nInterest = C_0 + C_1 * U^(2^0) + C_2 * U^(2^1) + C_3 * U^(2^2) ...",
"fullyImplemented": true,
"id": 3640,
"linearizedBaseContracts": [
3640,
24789
],
"name": "DoubleExponentInterestSetter",
"nodeType": "ContractDefinition",
"nodes": [
{
"id": 3387,
"libraryName": {
"contractScope": null,
"id": 3385,
"name": "DolomiteMarginMath",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 26238,
"src": "1263:18:10",
"typeDescriptions": {
"typeIdentifier": "t_contract$_DolomiteMarginMath_$26238",
"typeString": "library DolomiteMarginMath"
}
},
"nodeType": "UsingForDirective",
"src": "1257:37:10",
"typeName": {
"id": 3386,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1286:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
}
},
{
"id": 3390,
"libraryName": {
"contractScope": null,
"id": 3388,
"name": "SafeMath",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 37365,
"src": "1305:8:10",
"typeDescriptions": {
"typeIdentifier": "t_contract$_SafeMath_$37365",
"typeString": "library SafeMath"
}
},
"nodeType": "UsingForDirective",
"src": "1299:27:10",
"typeName": {
"id": 3389,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1318:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
}
},
{
"constant": true,
"id": 3393,
"name": "PERCENT",
"nodeType": "VariableDeclaration",
"scope": 3640,
"src": "1376:30:10",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 3391,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1376:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": {
"argumentTypes": null,
"hexValue": "313030",
"id": 3392,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1403:3:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_100_by_1",
"typeString": "int_const 100"
},
"value": "100"
},
"visibility": "internal"
},
{
"constant": true,
"id": 3398,
"name": "BASE",
"nodeType": "VariableDeclaration",
"scope": 3640,
"src": "1413:32:10",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 3394,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1413:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": {
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_rational_1000000000000000000_by_1",
"typeString": "int_const 1000000000000000000"
},
"id": 3397,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"hexValue": "3130",
"id": 3395,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1437:2:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_10_by_1",
"typeString": "int_const 10"
},
"value": "10"
},
"nodeType": "BinaryOperation",
"operator": "**",
"rightExpression": {
"argumentTypes": null,
"hexValue": "3138",
"id": 3396,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1443:2:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_18_by_1",
"typeString": "int_const 18"
},
"value": "18"
},
"src": "1437:8:10",
"typeDescriptions": {
"typeIdentifier": "t_rational_1000000000000000000_by_1",
"typeString": "int_const 1000000000000000000"
}
},
"visibility": "internal"
},
{
"constant": true,
"id": 3407,
"name": "SECONDS_IN_A_YEAR",
"nodeType": "VariableDeclaration",
"scope": 3640,
"src": "1452:55:10",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 3399,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1452:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": {
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_rational_31536000_by_1",
"typeString": "int_const 31536000"
},
"id": 3406,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_rational_86400_by_1",
"typeString": "int_const 86400"
},
"id": 3404,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_rational_3600_by_1",
"typeString": "int_const 3600"
},
"id": 3402,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"hexValue": "3630",
"id": 3400,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1489:2:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_60_by_1",
"typeString": "int_const 60"
},
"value": "60"
},
"nodeType": "BinaryOperation",
"operator": "*",
"rightExpression": {
"argumentTypes": null,
"hexValue": "3630",
"id": 3401,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1494:2:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_60_by_1",
"typeString": "int_const 60"
},
"value": "60"
},
"src": "1489:7:10",
"typeDescriptions": {
"typeIdentifier": "t_rational_3600_by_1",
"typeString": "int_const 3600"
}
},
"nodeType": "BinaryOperation",
"operator": "*",
"rightExpression": {
"argumentTypes": null,
"hexValue": "3234",
"id": 3403,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1499:2:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_24_by_1",
"typeString": "int_const 24"
},
"value": "24"
},
"src": "1489:12:10",
"typeDescriptions": {
"typeIdentifier": "t_rational_86400_by_1",
"typeString": "int_const 86400"
}
},
"nodeType": "BinaryOperation",
"operator": "*",
"rightExpression": {
"argumentTypes": null,
"hexValue": "333635",
"id": 3405,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1504:3:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_365_by_1",
"typeString": "int_const 365"
},
"value": "365"
},
"src": "1489:18:10",
"typeDescriptions": {
"typeIdentifier": "t_rational_31536000_by_1",
"typeString": "int_const 31536000"
}
},
"visibility": "internal"
},
{
"constant": true,
"id": 3410,
"name": "BYTE",
"nodeType": "VariableDeclaration",
"scope": 3640,
"src": "1514:25:10",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 3408,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1514:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": {
"argumentTypes": null,
"hexValue": "38",
"id": 3409,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1538:1:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_8_by_1",
"typeString": "int_const 8"
},
"value": "8"
},
"visibility": "internal"
},
{
"canonicalName": "DoubleExponentInterestSetter.PolyStorage",
"id": 3415,
"members": [
{
"constant": false,
"id": 3412,
"name": "maxAPR",
"nodeType": "VariableDeclaration",
"scope": 3415,
"src": "1617:14:10",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint128",
"typeString": "uint128"
},
"typeName": {
"id": 3411,
"name": "uint128",
"nodeType": "ElementaryTypeName",
"src": "1617:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint128",
"typeString": "uint128"
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 3414,
"name": "coefficients",
"nodeType": "VariableDeclaration",
"scope": 3415,
"src": "1641:20:10",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint128",
"typeString": "uint128"
},
"typeName": {
"id": 3413,
"name": "uint128",
"nodeType": "ElementaryTypeName",
"src": "1641:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint128",
"typeString": "uint128"
}
},
"value": null,
"visibility": "internal"
}
],
"name": "PolyStorage",
"nodeType": "StructDefinition",
"scope": 3640,
"src": "1588:80:10",
"visibility": "public"
},
{
"constant": false,
"id": 3417,
"name": "g_storage",
"nodeType": "VariableDeclaration",
"scope": 3640,
"src": "1716:21:10",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_struct$_PolyStorage_$3415_storage",
"typeString": "struct DoubleExponentInterestSetter.PolyStorage"
},
"typeName": {
"contractScope": null,
"id": 3416,
"name": "PolyStorage",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 3415,
"src": "1716:11:10",
"typeDescriptions": {
"typeIdentifier": "t_struct$_PolyStorage_$3415_storage_ptr",
"typeString": "struct DoubleExponentInterestSetter.PolyStorage"
}
},
"value": null,
"visibility": "internal"
},
{
"body": {
"id": 3457,
"nodeType": "Block",
"src": "1862:481:10",
"statements": [
{
"assignments": [
3423
],
"declarations": [
{
"constant": false,
"id": 3423,
"name": "sumOfCoefficients",
"nodeType": "VariableDeclaration",
"scope": 3457,
"src": "1927:25:10",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName": {
"id": 3422,
"name": "uint256",
"nodeType": "ElementaryTypeName",
"src": "1927:7:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"value": null,
"visibility": "internal"
}
],
"id": 3425,
"initialValue": {
"argumentTypes": null,
"hexValue": "30",
"id": 3424,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "1955:1:10",
"subdenomination": null,
"typeDescriptions": {
"typeIdentifier": "t_rational_0_by_1",
"typeString": "int_const 0"
},
"value": "0"
},
"nodeType": "VariableDeclarationStatement",
"src": "1927:29:10"
},
{
"body": {
"id": 3444,
"nodeType": "Block",
"src": "2103:64:10",
"statements": [
{
"expression": {
"argumentTypes": null,
"id": 3442,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftHandSide": {
"argumentTypes": null,
"id": 3438,
"name": "sumOfCoefficients",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 3423,
"src": "2117:17:10",
"typeDescriptions": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"nodeType": "Assignment",
"operator": "+=",
"rightHandSide": {
"argumentTypes": null,
"commonType": {
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"id": 3441,
"isConstant": false,
"isLValue": false,
"isPure": false,
"lValueRequested": false,
"leftExpression": {
"argumentTypes": null,
"id": 3439,
"name": "coefficients",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 3427,