Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
7fc20ca
Merge branch 'develop' into feature/merge-create-loan
elclandestin0 Jun 3, 2021
dfffc22
data provider
elclandestin0 Jun 4, 2021
7c513d1
merge
elclandestin0 Jun 4, 2021
eee923c
fix compilation errors
elclandestin0 Jun 4, 2021
95eb4d5
some changes to dp
elclandestin0 Jun 4, 2021
1ccb5a4
Skelly for ZK CRA
tpscrpt Jun 4, 2021
031cbc3
Borrow function logic done, need to create loan and add configuratio…
tpscrpt Jun 4, 2021
d427b2d
Add snarks lib
tpscrpt Jun 4, 2021
cb26dae
Add documentation and fix using collateralAmount instead of collatera…
tpscrpt Jun 4, 2021
e08f40f
Into one file
tpscrpt Jun 4, 2021
c6eb931
Sample handler
tpscrpt Jun 4, 2021
b206dea
Updaets
tpscrpt Jun 4, 2021
07252f2
More clarity on market unctions
tpscrpt Jun 4, 2021
059c03c
zkCRA test template
elclandestin0 Jun 4, 2021
0d6dcd3
Save
tpscrpt Jun 5, 2021
3b40eea
attempt at fixing comp. errors
elclandestin0 Jun 7, 2021
3f3ed56
Fix compilation errors
tpscrpt Jun 7, 2021
6443352
packed variables
elclandestin0 Jun 8, 2021
08f7020
update test
elclandestin0 Jun 8, 2021
7a0c7c4
got witness, output & proof
elclandestin0 Jun 8, 2021
8c2e977
set config admins
elclandestin0 Jun 9, 2021
3cc58ab
tests almost done
elclandestin0 Jun 10, 2021
e76a85b
update tests
elclandestin0 Jun 10, 2021
3025c2f
ting
tpscrpt Jun 10, 2021
23162c0
Updates
tpscrpt Jun 10, 2021
aa3fe79
data being submitted onchain
elclandestin0 Jun 11, 2021
dadfc00
update tests
elclandestin0 Jun 11, 2021
26992f1
Keys
tpscrpt Jun 11, 2021
8776bb9
Snark proof verifying
tpscrpt Jun 11, 2021
cb7ffd1
YE
tpscrpt Jun 11, 2021
5728e29
Faster tests
tpscrpt Jun 12, 2021
be9bd3d
Progress
tpscrpt Jun 12, 2021
58efe8b
Packing properly hopefully
tpscrpt Jun 12, 2021
fca10a3
Working zk cra
tpscrpt Jun 12, 2021
9d94bfb
fix void signer error
elclandestin0 Jun 12, 2021
c83a425
Merge branch 'develop' into feature/zk-cra
elclandestin0 Jun 21, 2021
fce6a8b
zkcra.json stored in ipfs
elclandestin0 Jun 23, 2021
1f1ee5f
good scores bad scores
elclandestin0 Jun 23, 2021
5044652
ipfs successfully returning source
elclandestin0 Jun 23, 2021
cc8dccf
zkcra create loan changes
elclandestin0 Jun 24, 2021
fa6c4c6
fix errors
elclandestin0 Jun 24, 2021
5c79e38
merge fix
elclandestin0 Jun 24, 2021
40e8a65
market interest calc
elclandestin0 Jun 24, 2021
892e58a
moved init market admins to create loan facet
elclandestin0 Jun 25, 2021
ec8187b
reworked setting provider info
elclandestin0 Jun 25, 2021
c5da9b5
modifyign tests
elclandestin0 Jun 27, 2021
e584254
zkcra working
elclandestin0 Jun 28, 2021
3765885
zkcra updated tests
elclandestin0 Jun 28, 2021
3ab1604
fixing signaturedata datatype
elclandestin0 Jun 28, 2021
ee8c659
require statement
elclandestin0 Jun 28, 2021
e72d8ba
updated w/ noah's comments
elclandestin0 Jun 29, 2021
e9651ab
unused imports fix
elclandestin0 Jun 29, 2021
43e8f23
Revert "unused imports fix"
elclandestin0 Jun 29, 2021
f9b9f51
para programming w/ Noah
elclandestin0 Jun 29, 2021
70aac4e
process request library
elclandestin0 Jun 29, 2021
e8426f0
sample market handler
elclandestin0 Jun 30, 2021
e1e8058
fixed dir structure
elclandestin0 Jun 30, 2021
cbe2e82
ready for deployment
elclandestin0 Jun 30, 2021
90382a7
deployed process request library and teller market handler
elclandestin0 Jun 30, 2021
bfdb832
change to public function
elclandestin0 Jul 1, 2021
020d131
create provider factory
elclandestin0 Jul 1, 2021
1a489ce
deployed provider factory
elclandestin0 Jul 1, 2021
4e9d18c
signer successfully set
elclandestin0 Jul 1, 2021
d6a73af
provider set in market
elclandestin0 Jul 1, 2021
0a35fd5
commitments = number of signatures required
elclandestin0 Jul 2, 2021
55e7edf
end to end testing with good score done
elclandestin0 Jul 2, 2021
35d182b
provider creation with args
elclandestin0 Jul 2, 2021
3a70f50
added provider to request
elclandestin0 Jul 2, 2021
c6bdbf7
end to end testing for bad score completed
elclandestin0 Jul 2, 2021
84f4c23
removed console logs
elclandestin0 Jul 2, 2021
3831705
changed teller interest value
elclandestin0 Jul 5, 2021
82ffaf2
removed market lib
elclandestin0 Jul 5, 2021
0a53985
fix bad score test
elclandestin0 Jul 5, 2021
c6c50a2
update
elclandestin0 Jul 5, 2021
b9d8bc9
market handler updated with new loan calculator
elclandestin0 Jul 5, 2021
0a60b7a
removed useless require statement
elclandestin0 Jul 5, 2021
20aefc5
states file
elclandestin0 Jul 6, 2021
d9aec33
retrieve state's rate
elclandestin0 Jul 6, 2021
2df3405
fix bn error
elclandestin0 Jul 7, 2021
af9c5fa
fix market handling rounding error
elclandestin0 Jul 8, 2021
04087de
Merge pull request #421 from teller-protocol/zk-cra/test-flow
elclandestin0 Jul 9, 2021
996c352
data provider
elclandestin0 Jun 4, 2021
302ea5b
some changes to dp
elclandestin0 Jun 4, 2021
619181e
Skelly for ZK CRA
tpscrpt Jun 4, 2021
3b0459c
Borrow function logic done, need to create loan and add configuratio…
tpscrpt Jun 4, 2021
c724a92
Add snarks lib
tpscrpt Jun 4, 2021
28a7010
Add documentation and fix using collateralAmount instead of collatera…
tpscrpt Jun 4, 2021
34eb446
Into one file
tpscrpt Jun 4, 2021
6a7a0ee
Sample handler
tpscrpt Jun 4, 2021
da73525
Updaets
tpscrpt Jun 4, 2021
3cd3cc2
More clarity on market unctions
tpscrpt Jun 4, 2021
7409780
zkCRA test template
elclandestin0 Jun 4, 2021
402f868
Save
tpscrpt Jun 5, 2021
61faa69
attempt at fixing comp. errors
elclandestin0 Jun 7, 2021
ddbd7ac
Fix compilation errors
tpscrpt Jun 7, 2021
1648bbc
packed variables
elclandestin0 Jun 8, 2021
6bb792e
update test
elclandestin0 Jun 8, 2021
ebcbefb
got witness, output & proof
elclandestin0 Jun 8, 2021
464f372
set config admins
elclandestin0 Jun 9, 2021
f24b050
tests almost done
elclandestin0 Jun 10, 2021
023284a
update tests
elclandestin0 Jun 10, 2021
22080ea
ting
tpscrpt Jun 10, 2021
02dcfa7
Updates
tpscrpt Jun 10, 2021
94be52a
data being submitted onchain
elclandestin0 Jun 11, 2021
b0e6cf5
update tests
elclandestin0 Jun 11, 2021
7307e4d
Keys
tpscrpt Jun 11, 2021
ee9d83d
Snark proof verifying
tpscrpt Jun 11, 2021
1165739
YE
tpscrpt Jun 11, 2021
a37e0fe
Faster tests
tpscrpt Jun 12, 2021
7b6e983
Progress
tpscrpt Jun 12, 2021
3fe5a75
Packing properly hopefully
tpscrpt Jun 12, 2021
66700fa
Working zk cra
tpscrpt Jun 12, 2021
9596241
fix void signer error
elclandestin0 Jun 12, 2021
0aae7a7
zkcra.json stored in ipfs
elclandestin0 Jun 23, 2021
bd6766f
good scores bad scores
elclandestin0 Jun 23, 2021
dbab14a
ipfs successfully returning source
elclandestin0 Jun 23, 2021
b730f9f
zkcra create loan changes
elclandestin0 Jun 24, 2021
4cf9167
fix errors
elclandestin0 Jun 24, 2021
7d71c35
merge fix
elclandestin0 Jun 24, 2021
b7baa43
market interest calc
elclandestin0 Jun 24, 2021
addc0ff
moved init market admins to create loan facet
elclandestin0 Jun 25, 2021
d1fab5e
reworked setting provider info
elclandestin0 Jun 25, 2021
babd58a
modifyign tests
elclandestin0 Jun 27, 2021
b870397
zkcra working
elclandestin0 Jun 28, 2021
268d5c5
zkcra updated tests
elclandestin0 Jun 28, 2021
aae851a
fixing signaturedata datatype
elclandestin0 Jun 28, 2021
420bded
require statement
elclandestin0 Jun 28, 2021
a77ccd9
updated w/ noah's comments
elclandestin0 Jun 29, 2021
852f1ee
Revert "unused imports fix"
elclandestin0 Jun 29, 2021
29b2792
para programming w/ Noah
elclandestin0 Jun 29, 2021
94ac369
process request library
elclandestin0 Jun 29, 2021
fb49df4
sample market handler
elclandestin0 Jun 30, 2021
3587f25
fixed dir structure
elclandestin0 Jun 30, 2021
addb731
ready for deployment
elclandestin0 Jun 30, 2021
6959c2b
deployed process request library and teller market handler
elclandestin0 Jun 30, 2021
d03861b
change to public function
elclandestin0 Jul 1, 2021
4990170
create provider factory
elclandestin0 Jul 1, 2021
a199943
deployed provider factory
elclandestin0 Jul 1, 2021
735c85c
signer successfully set
elclandestin0 Jul 1, 2021
8b14b53
provider set in market
elclandestin0 Jul 1, 2021
f301a6d
commitments = number of signatures required
elclandestin0 Jul 2, 2021
96bef47
end to end testing with good score done
elclandestin0 Jul 2, 2021
351ae5d
provider creation with args
elclandestin0 Jul 2, 2021
805ae56
added provider to request
elclandestin0 Jul 2, 2021
0aa513b
end to end testing for bad score completed
elclandestin0 Jul 2, 2021
c9040de
removed console logs
elclandestin0 Jul 2, 2021
ebef161
changed teller interest value
elclandestin0 Jul 5, 2021
13def46
removed market lib
elclandestin0 Jul 5, 2021
9e2ee4e
fix bad score test
elclandestin0 Jul 5, 2021
688bb99
update
elclandestin0 Jul 5, 2021
50a1f36
market handler updated with new loan calculator
elclandestin0 Jul 5, 2021
c30bc65
removed useless require statement
elclandestin0 Jul 5, 2021
784171e
states file
elclandestin0 Jul 6, 2021
47d4887
retrieve state's rate
elclandestin0 Jul 6, 2021
c6b2a29
fix bn error
elclandestin0 Jul 7, 2021
aeabdd3
fix market handling rounding error
elclandestin0 Jul 8, 2021
6114b1e
created new loan facets
elclandestin0 Jul 29, 2021
ce38b12
Merge remote-tracking branch 'origin/zk-cra/market-handler' into zk-c…
elclandestin0 Jul 29, 2021
b395cd6
Merge pull request #434 from teller-protocol/zk-cra/market-handler
elclandestin0 Jul 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions contracts/lending/ttoken/TToken_V1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol";

// Interfaces
import { ITToken } from "./ITToken.sol";
import { ICErc20 } from "../../shared/interfaces/ICErc20.sol";

// Libraries
import {
IERC20,
SafeERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
Expand Down Expand Up @@ -444,8 +446,10 @@ contract TToken_V1 is ITToken, ReentryMods {
}

/**
* @notice it retrieves the value in the underlying tokens
*
* @notice it retrives the value in the underlying tokens
* @param amount the amount of underlying
* @param rate the rate the underlying is exchanging at
* @return value_ the value of the underlying
*/
function _valueInUnderlying(uint256 amount, uint256 rate)
internal
Expand Down
26 changes: 26 additions & 0 deletions contracts/lending/ttoken/storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

struct Store {
ERC20 underlying;
address strategy;
uint256 totalBorrowed;
uint256 totalRepaid;
uint256 totalInterestRepaid;
uint8 decimals;
bool restricted;
}

bytes32 constant POSITION = keccak256("ttoken.storage.position");

/**
* @notice it saves the Store struct in a hashed slot
*/
function store() pure returns (Store storage s_) {
bytes32 position = POSITION;
assembly {
s_.slot := position
}
}
21 changes: 21 additions & 0 deletions contracts/lending/ttoken/strategies/compound/storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ICErc20 } from "../../../../shared/interfaces/ICErc20.sol";

struct Store {
ICErc20 cToken;
uint16 balanceRatioMax;
uint16 balanceRatioMin;
}

bytes32 constant POSITION = keccak256(
"ttoken.strategy.compound.storage.position"
);

function store() pure returns (Store storage s_) {
bytes32 position = POSITION;
assembly {
s_.slot := position
}
}
2 changes: 1 addition & 1 deletion contracts/lending/ttoken/token-storage.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

struct Store {
// The underlying asset of the tToken
Expand Down
54 changes: 29 additions & 25 deletions contracts/market/CreateLoanFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
ReentryMods
} from "../contexts2/access-control/reentry/ReentryMods.sol";
import { RolesMods } from "../contexts2/access-control/roles/RolesMods.sol";
import { AUTHORIZED } from "../shared/roles.sol";
import { AUTHORIZED, ADMIN } from "../shared/roles.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// Libraries
import { LibLoans } from "./libraries/LibLoans.sol";
import { LibEscrow } from "../escrow/libraries/LibEscrow.sol";
import { LibCollateral } from "./libraries/LibCollateral.sol";
import { LibConsensus } from "./libraries/LibConsensus.sol";
import { LendingLib } from "../lending/libraries/LendingLib.sol";
import {
PlatformSettingsLib
Expand All @@ -30,6 +30,9 @@ import {
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { NumbersLib } from "../shared/libraries/NumbersLib.sol";
import { NFTLib } from "../nft/libraries/NFTLib.sol";
import { Verifier } from "./cra/verifier.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { ProcessRequestLib } from "./cra/ProcessRequestLib.sol";

// Interfaces
import { ILoansEscrow } from "../escrow/escrow/ILoansEscrow.sol";
Expand All @@ -43,11 +46,13 @@ import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol";

// Storage
import {
LoanRequest,
LoanRequestWithResponse,
LoanStatus,
LoanTerms,
Loan,
MarketStorageLib
MarketStorageLib,
Signature,
DataProviderSignature
} from "../storage/market.sol";
import { AppStorageLib } from "../storage/app.sol";

Expand All @@ -70,7 +75,10 @@ contract CreateLoanFacet is RolesMods, ReentryMods, PausableMods {
* @notice Creates the loan from requests and validator responses then calling the main function.
* @param request Struct of the protocol loan request
*/
modifier __createLoan(LoanRequest calldata request, bool withNFT) {
modifier __createLoan(
LoanRequestWithResponse calldata request,
bool withNFT
) {
Loan storage loan = CreateLoanLib.createLoan(request, withNFT);

_;
Expand All @@ -86,7 +94,7 @@ contract CreateLoanFacet is RolesMods, ReentryMods, PausableMods {
* @param nftIDs IDs of TellerNFTs to use for the loan
*/
function takeOutLoanWithNFTs(
LoanRequest calldata request,
LoanRequestWithResponse calldata request,
uint16[] calldata nftIDs
) external paused(LibLoans.ID, false) __createLoan(request, true) {
// Get the ID of the newly created loan
Expand Down Expand Up @@ -133,7 +141,7 @@ contract CreateLoanFacet is RolesMods, ReentryMods, PausableMods {
* @param collateralAmount Amount of collateral required for the loan
*/
function takeOutLoan(
LoanRequest calldata request,
LoanRequestWithResponse calldata request,
address collateralToken,
uint256 collateralAmount
)
Expand Down Expand Up @@ -193,27 +201,25 @@ contract CreateLoanFacet is RolesMods, ReentryMods, PausableMods {
}

library CreateLoanLib {
function createLoan(LoanRequest calldata request, bool withNFT)
function createLoan(LoanRequestWithResponse calldata request, bool withNFT)
internal
returns (Loan storage loan)
{
// Perform loan request checks
require(
msg.sender == request.request.borrower,
"Teller: not loan requester"
);
require(
PlatformSettingsLib.getMaximumLoanDurationValue() >=
request.request.duration,
"Teller: max loan duration exceeded"
);

// Get consensus values from request
(
uint16 interestRate,
uint16 collateralRatio,
uint256 maxLoanAmount
) = LibConsensus.processLoanTerms(request);
uint16 interestRate = 15000;
uint16 collateralRatio = 5000;
uint256 maxLoanAmount = 25000;
// (
// uint16 interestRate,
// uint16 collateralRatio,
// uint256 maxLoanAmount
// ) = ProcessRequestLib.processMarketRequest(request);

// Perform loan value checks
require(
Expand All @@ -229,6 +235,7 @@ library CreateLoanLib {

// Get and increment new loan ID
uint256 loanID = CreateLoanLib.newID();

// Set loan data based on terms
loan = LibLoans.loan(loanID);
loan.id = uint128(loanID);
Expand Down Expand Up @@ -261,23 +268,20 @@ library CreateLoanLib {
* @return id_ the new ID requested, which stores it in the loan data
*/
function newID() internal returns (uint256 id_) {
Counters.Counter storage counter = MarketStorageLib.store()
Counters.Counter storage counter = MarketStorageLib
.store()
.loanIDCounter;
id_ = Counters.current(counter);
Counters.increment(counter);
}

function currentID() internal view returns (uint256 id_) {
Counters.Counter storage counter = MarketStorageLib.store()
Counters.Counter storage counter = MarketStorageLib
.store()
.loanIDCounter;
id_ = Counters.current(counter);
}

/**
* @notice it creates a new loan escrow contract
* @param loanID the ID that identifies the loan
* @return escrow_ the loanEscrow that gets created
*/
function createEscrow(uint256 loanID) internal returns (address escrow_) {
// Create escrow
escrow_ = AppStorageLib.store().loansEscrowBeacon.cloneProxy("");
Expand Down
Loading