This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 822
[forte-staking] Forte staking strategy #1754
Merged
ChaituVR
merged 13 commits into
snapshot-labs:master
from
oscarsernarosero:forte-staking
Jun 19, 2025
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
025ddfd
finished voting strategy
oscarsernarosero 8d6263c
some refinement
oscarsernarosero 390fcc5
removed package-lock.json
oscarsernarosero 5d2f86b
bumped version
oscarsernarosero 290676a
PR changes
oscarsernarosero 92fe94f
small tweak on calculateVotingPower
oscarsernarosero a1104a1
parameterized the voting power
oscarsernarosero 6bb1721
small renaming
oscarsernarosero cb82041
small tweak to README
oscarsernarosero 39fa807
some updates on the README
oscarsernarosero fd837fa
updated author to myself
oscarsernarosero b617b58
took care of lint errors
oscarsernarosero 0ae4707
Merge branch 'master' into forte-staking
ChaituVR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # forte-staking | ||
|
|
||
| This strategy is for staking $FOR tokes. Voting power is calculated by taking into account the access level and time of staking. | ||
|
|
||
| Here is an example of parameters: | ||
|
|
||
| ```json | ||
| { | ||
| "symbol": "FOR", | ||
| "stakingAddress": "0x6b175474e89094c44da98b954eedeac495271d0f", | ||
| "kycAddress": "0x86f53212865b6fddb99633dc002a7f7aacaaa8db" | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "name": "Example query", | ||
| "strategy": { | ||
| "name": "forte-staking", | ||
| "params": { | ||
| "stakingAddress": "0x249E662fe228Eff1e7dCE7cF3E78dFD481C7Ba3E", | ||
| "kycAddress": "0x86f53212865b6fddb99633dc002a7f7aacaaa8db", | ||
| "symbol": "FORTE" | ||
| } | ||
| }, | ||
| "network": "11155111", | ||
| "addresses": [ | ||
| "0xe5405Dabe7d24F044941cEE4eA73a194659D7bD4", | ||
| "0x9Fb190F6Da7cdDd939bB4f661c134051ecf6A8B5", | ||
| "0x12363F899a1b2039a2A5a1A717be896AFA446382", | ||
| "0xE3D777106b622474a2974839061D652a7Af3C989", | ||
| "0x9B42F52E69C9bA94991A7D7e7aF73b2340a43216", | ||
| "0xd99675E7583e73E8DDC6bdbcbff5321983232763" | ||
| ], | ||
| "snapshot": 8541444 | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { BigNumber } from '@ethersproject/bignumber'; | ||
| import { Multicaller } from '../../utils'; | ||
| import { formatUnits } from '@ethersproject/units'; | ||
|
|
||
| export const author = 'forte'; | ||
| export const version = '0.0.1'; | ||
|
|
||
| type batch = [stakeAmount: BigNumber, timeStamp: BigNumber]; | ||
| const stakeAmount = 0; // index of the stake amount in the batch tuple | ||
| const timeStamp = 1; // index of the timestamp in the batch tuple | ||
|
|
||
| const abiStaking = [ | ||
| 'function getStakedBatches(address _user) external view returns ((uint256, uint256)[] memory)' | ||
| ]; | ||
|
|
||
| const abiKYC = [ | ||
| 'function getAccessLevel(address _account) external view returns (uint8)' | ||
| ]; | ||
|
|
||
| export async function strategy( | ||
| space, | ||
| network, | ||
| provider, | ||
| addresses, | ||
| options, | ||
| snapshot | ||
| ): Promise<Record<string, number>> { | ||
| const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
|
||
| // getting the staked batches | ||
| const stakeCall = new Multicaller(network, provider, abiStaking, { | ||
| blockTag | ||
| }); | ||
| addresses.forEach((address) => | ||
| stakeCall.call(address, options.stakingAddress, 'getStakedBatches', [ | ||
| address | ||
| ]) | ||
| ); | ||
| const stakeResult: Record<string, batch[]> = await stakeCall.execute(); | ||
|
|
||
| // getting the KYC level | ||
| const kycCall = new Multicaller(network, provider, abiKYC, { | ||
| blockTag | ||
| }); | ||
| addresses.forEach((address) => | ||
| kycCall.call(address, options.kycAddress, 'getAccessLevel', [address]) | ||
| ); | ||
| const kycResult: Record<string, number> = await kycCall.execute(); | ||
|
|
||
| // return voting power | ||
| return Object.fromEntries( | ||
| Object.entries(stakeResult).map(([address, rawBatches]) => [ | ||
| address, | ||
| calculateVotingPower(rawBatches, kycResult[address]) | ||
| ]) | ||
| ); | ||
| } | ||
|
|
||
| function calculateVotingPower(rawBatches: batch[], kycLevel: number): number { | ||
| let votingPower: bigint = 0n; | ||
| rawBatches.forEach((batch) => { | ||
|
||
| console.log('batch', batch); | ||
| const today: number = +new Date(); | ||
| const stakeDate: number = +new Date(Number(batch[timeStamp]._hex) * 1000); // * 1000 to convert to ms | ||
| const daysStaked: number = Math.floor( | ||
| (today - stakeDate) / (60 * 60 * 24 * 1000) // (...) / (1 day in ms) | ||
| ); | ||
| const stake: bigint = BigInt(batch[stakeAmount]._hex); | ||
| votingPower += | ||
| (stake * BigInt(4 * (daysStaked > 1 ? daysStaked - 1 : 0))) / 1461n; | ||
| }); | ||
| votingPower = votingPower * BigInt(kycLevel > 2 ? 2 : kycLevel); | ||
| return parseFloat(formatUnits(votingPower)); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$ref": "#/definitions/Strategy", | ||
| "definitions": { | ||
| "Strategy": { | ||
| "title": "Strategy", | ||
| "type": "object", | ||
| "properties": { | ||
| "symbol": { | ||
| "type": "string", | ||
| "title": "Symbol", | ||
| "examples": ["e.g. FOR"], | ||
| "maxLength": 16 | ||
| }, | ||
| "stakingAddress": { | ||
| "type": "string", | ||
| "title": "Contract address", | ||
| "examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
| "pattern": "^0x[a-fA-F0-9]{40}$", | ||
| "minLength": 42, | ||
| "maxLength": 42 | ||
| }, | ||
| "kycAddress": { | ||
| "type": "string", | ||
| "title": "Contract address", | ||
| "examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
| "pattern": "^0x[a-fA-F0-9]{40}$", | ||
| "minLength": 42, | ||
| "maxLength": 42 | ||
| } | ||
| }, | ||
| "required": ["stakingAddress", "kycAddress"], | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a github related to forte 😅 it will help identify you if you want to update this strategy in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 ok I wasn't aware this had the purpose of giving update privileges. I changed it to my GH user