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

[SERVICES-1740] optimal staking compound #1123

Merged
merged 4 commits into from
Jul 28, 2023

Conversation

claudiulataretu
Copy link
Collaborator

@claudiulataretu claudiulataretu commented Jul 27, 2023

Reasoning

  • staking contracts positions can be compounded directly without rewards harvesting; because investment and rewards are the same type, we can compound the rewards and calculate the optimal frequency for compounding

Proposed Changes

  • add method to compute optimal compound frequency for any staking position expressed in hours and minutes interval

How to test

query OptimalCompound {
	getOptimalCompoundFrequency(
		stakeAddress: "erd1qqqqqqqqqqqqqpgq8w0s682m88xae2ne3qkq7w2h26u5a5c00n4stt02d7",
		amount: "900000000000000000000",
		timeInterval: 365
	) {
		interval
		hours
		minutes
	}
}
  • query should return an OptimalCompound object
{
  "optimalProfit": 114.31687566993836,
  "interval": 34,
  "days": 10,
  "hours": 17,
  "minutes": 38
}

@claudiulataretu claudiulataretu added the feature New feature added label Jul 27, 2023
jacobleygonie
jacobleygonie previously approved these changes Jul 27, 2023
Copy link

@jacobleygonie jacobleygonie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the logic is correct. Added a few comments for possible improvements.

@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Patch coverage: 96.66% and project coverage change: +0.12% 🎉

Comparison is base (13368f2) 56.38% compared to head (64c7258) 56.51%.
Report is 3 commits behind head on development.

Additional details and impacted files
@@               Coverage Diff               @@
##           development    #1123      +/-   ##
===============================================
+ Coverage        56.38%   56.51%   +0.12%     
===============================================
  Files              233      233              
  Lines             7748     7778      +30     
  Branches           518      519       +1     
===============================================
+ Hits              4369     4396      +27     
- Misses            2936     2938       +2     
- Partials           443      444       +1     
Flag Coverage Δ
unittests 56.51% <96.66%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/modules/pair/mocks/pair.constants.ts 62.06% <ø> (ø)
...odules/staking/services/staking.compute.service.ts 82.50% <95.45%> (+4.91%) ⬆️
src/modules/staking/models/staking.model.ts 100.00% <100.00%> (ø)
.../modules/tokens/mocks/token.getter.service.mock.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- iterate over the number of hours in a year

Signed-off-by: Claudiu Lataretu <[email protected]>
- express interval in days hours minutes
- add optimal profit field

Signed-off-by: Claudiu Lataretu <[email protected]>
@claudiulataretu claudiulataretu merged commit 905175a into development Jul 28, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants