From 2af46c050757c7524b6ffde14f9f27102efbf9a8 Mon Sep 17 00:00:00 2001 From: yuchenlintt <80530881+yuchenlintt@users.noreply.github.com> Date: Tue, 24 Aug 2021 06:22:02 -0500 Subject: [PATCH] Add a getShare(token) view to TrueMultiFarm (#890) --- contracts/truefi2/TrueMultiFarm.sol | 8 ++++++++ test/truefi2/TrueMultiFarm.test.ts | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/contracts/truefi2/TrueMultiFarm.sol b/contracts/truefi2/TrueMultiFarm.sol index 37d11ee52..1ed393b2e 100644 --- a/contracts/truefi2/TrueMultiFarm.sol +++ b/contracts/truefi2/TrueMultiFarm.sol @@ -175,6 +175,14 @@ contract TrueMultiFarm is ITrueMultiFarm, UpgradeableClaimable { } } + /* + * What proportional share of rewards get distributed to this token? + * The denominator is visible in the public `shares()` view. + */ + function getShare(IERC20 token) external view returns (uint256) { + return shares.staked[address(token)]; + } + /** * @dev Set shares for farms * Example: setShares([DAI, USDC], [1, 2]) will ensure that 33.(3)% of rewards will go to DAI farm and rest to USDC farm diff --git a/test/truefi2/TrueMultiFarm.test.ts b/test/truefi2/TrueMultiFarm.test.ts index 99a041a88..ad9840ab6 100644 --- a/test/truefi2/TrueMultiFarm.test.ts +++ b/test/truefi2/TrueMultiFarm.test.ts @@ -321,6 +321,11 @@ describe('TrueMultiFarm', () => { await farm.setShares([secondToken.address], [3], txArgs) }) + it('getShare shows pool shares', async () => { + expect(await farm.getShare(firstToken.address)).to.equal(1) + expect(await farm.getShare(secondToken.address)).to.equal(3) + }) + describe('one staker', () => { beforeEach(async () => { await timeTravelTo(provider, start)