Skip to content

Commit

Permalink
get latest prices by subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-trends committed Sep 7, 2023
1 parent c9cb0d1 commit fc5e6a2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions contracts/TrendsSharesHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ contract TrendsSharesHelper {
uint256 earnings;
}

struct SubjectPrice {
bytes32 subject;
uint256 price;
}

function getSharesAndEarnings(address wallet, bytes32[] memory subjects) external view returns (SubjectInfo[] memory) {
SubjectInfo[] memory subjectInfos = new SubjectInfo[](subjects.length);

Expand All @@ -32,4 +37,22 @@ contract TrendsSharesHelper {

return subjectInfos;
}

function getLatestPrices(bytes32[] memory subjects) external view returns (SubjectPrice[] memory) {
SubjectPrice[] memory subjectPrices = new SubjectPrice[](subjects.length);

for (uint i = 0; i < subjects.length; i++) {
bytes32 subject = subjects[i];

uint24 declineRatio = trendsShares.sharesDeclineRatio(subject);
uint256 supply = trendsShares.sharesSupply(subject);

// Assuming amount is 1 to get the current price
uint256 price = trendsShares.getPrice(supply, 1, declineRatio);
subjectPrices[i] = SubjectPrice(subject, price);
}

return subjectPrices;
}

}

0 comments on commit fc5e6a2

Please sign in to comment.