Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MYSO-26: Improve programmatic lender access #577

Open
asardon opened this issue Jul 21, 2023 · 2 comments · Fixed by #576 or #582
Open

MYSO-26: Improve programmatic lender access #577

asardon opened this issue Jul 21, 2023 · 2 comments · Fixed by #576 or #582
Assignees

Comments

@asardon
Copy link
Member

asardon commented Jul 21, 2023

Description

Currently, lenders need to keep track of their on-chain quote history with event listeners. However, there aren't any getters to easily access the overall on-chain quote history as well as the overall number of on-chain quotes that were added. This can make deleting open on-chain quotes a bit tedious.

Similarly, there's no function to get return the total number of signers on a vault, hence if a lender wants to know the currently active signers they need to iterate over the signer array.

Recommendation

Add a storage append only array that keeps track of all the added on-chain quote hashes as well as the valid until timestamp. Moreover, add a getter to retrieve the total onchain quote historay length as well as the total number of signers.

@asardon asardon linked a pull request Jul 21, 2023 that will close this issue
@asardon asardon linked a pull request Aug 8, 2023 that will close this issue
@asardon
Copy link
Member Author

asardon commented Aug 8, 2023

Implementation

The append only array for on-chain quote hashes is implemented here:

// @dev: on-chain quote history is append only
onChainQuoteHistory[lenderVault].push(
DataTypesPeerToPeer.OnChainQuoteInfo({
quoteHash: onChainQuoteHash,
validUntil: onChainQuote.generalQuoteInfo.validUntil
})
);

The on-chain quote hashes can be retrieved via:

function getOnChainQuoteHistory(
address lenderVault,
uint256 idx
) external view returns (DataTypesPeerToPeer.OnChainQuoteInfo memory) {
if (idx < onChainQuoteHistory[lenderVault].length) {
return onChainQuoteHistory[lenderVault][idx];
} else {
revert Errors.InvalidArrayIndex();
}
}
function getFullOnChainQuoteHistory(
address lenderVault
) external view returns (DataTypesPeerToPeer.OnChainQuoteInfo[] memory) {
return onChainQuoteHistory[lenderVault];
}
function getOnChainQuoteHistoryLength(
address lenderVault
) external view returns (uint256) {
return onChainQuoteHistory[lenderVault].length;
}

The on-chain quote hash history is stored via the following struct which also stores the valid until time to allow lenders to quickly check which on-chain quotes are currently still active:

struct OnChainQuoteInfo {
// hash of on chain quote
bytes32 quoteHash;
// valid until timestamp
uint256 validUntil;
}

@asardon
Copy link
Member Author

asardon commented Aug 8, 2023

Additional Improvements

To minimize the overhead when updating and deleting on-chain quotes, lenders now only need to pass on the quotehash rather than the (old) onChainQuote struct, ie the oldOnChainQuote was removed from the update function:

function deleteOnChainQuote(
address lenderVault,
bytes32 onChainQuoteHash

and similarly, the onChainQuote struct was removed from the delete function:

function deleteOnChainQuote(
address lenderVault,
bytes32 onChainQuoteHash
) external {

Lastly, the number of signers can now be retrieved via:

function totalNumSigners() external view returns (uint256) {
return signers.length;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants