-
Notifications
You must be signed in to change notification settings - Fork 804
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
first commit #1614
Open
jscrui
wants to merge
1
commit into
snapshot-labs:master
Choose a base branch
from
jscrui:erc20-staked-at
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
first commit #1614
Changes from all commits
Commits
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 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,27 @@ | ||
# Snapshot.org Staking Strategy | ||
|
||
This strategy is designed to calculate the total amount of tokens a user has staked in a staking contract. Originally developed for **Paal**, it can be adapted for use with any other staking contract, provided it is compatible with this structure. | ||
|
||
### Key Features | ||
- Calculates the staked token balance for each user. | ||
- Flexible and adaptable to various staking contracts. | ||
|
||
### Parameters | ||
|
||
{ | ||
"address": "0x85e253162c7e97275b703980f6b6fa8c0469d624", | ||
"symbol": "PAAL", | ||
"decimals": 9 | ||
} | ||
|
||
### Functionality | ||
|
||
This strategy utilizes the `shares()` function in Paal smart contracts, which takes a user's address as a parameter and returns two `uint256` values: `amountOfTokens` (the number of tokens staked) and `initTimestamp` (the timestamp when the staking began). | ||
|
||
Feel free to integrate it into your project if the contract adheres to a similar staking model. | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains 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,21 @@ | ||
[ | ||
{ | ||
"name": "Get staked tokens at", | ||
"strategy": { | ||
"name": "erc20-staked-at", | ||
"params": { | ||
"address": "0x85e253162c7e97275b703980f6b6fa8c0469d624", | ||
"symbol": "PAAL", | ||
"decimals": 9 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x1029898f7D7f8cEf3a347A6D7342Cdf42f11532e", | ||
"0xa57FAe92A541B19Cbc03A8c5fe67FBDdBB53D79e", | ||
"0x29dE41D2a9270241629e94dE3B72985e577D91A9" | ||
], | ||
"snapshot": 20995910 | ||
} | ||
] | ||
|
This file contains 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,44 @@ | ||
|
||
import { multicall } from '../../utils'; | ||
import { formatUnits } from '@ethersproject/units'; | ||
|
||
export const author = 'jscrui'; | ||
export const version = '0.1.1'; | ||
|
||
const abi = ['function shares(address account) view returns (uint256, uint256)']; | ||
|
||
/** | ||
* This strategy is designed to calculate voting power based on | ||
* the Staked ERC20 tokens in a given contract. | ||
*/ | ||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses, | ||
options, | ||
snapshot | ||
) { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
const response = await multicall( | ||
network, | ||
provider, | ||
abi, | ||
addresses.map((address: any) => [ | ||
options.address, | ||
'shares', | ||
[address] | ||
]), | ||
{ blockTag } | ||
); | ||
|
||
return Object.fromEntries( | ||
response.map((value, i) => { | ||
// Format the voting power using the token decimals | ||
const votingPower = parseFloat(formatUnits(value[0], options.decimals)); // Convert using formatUnits | ||
//console.log(`${addresses[i]}: ${votingPower} (${symbol})`); | ||
return [addresses[i], votingPower]; | ||
}) | ||
); | ||
} |
This file contains 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,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/Strategy", | ||
"definitions": { | ||
"Strategy": { | ||
"title": "ERC20 Staked At", | ||
"type": "object", | ||
"properties": { | ||
"symbol": { | ||
"type": "string", | ||
"title": "Symbol", | ||
"examples": ["e.g. PAAL"], | ||
"maxLength": 16 | ||
}, | ||
"address": { | ||
"type": "string", | ||
"title": "Contract address", | ||
"examples": ["e.g. 0x85e253162c7e97275b703980f6b6fa8c0469d624"], | ||
"pattern": "^0x[a-fA-F0-9]{40}$", | ||
"minLength": 42, | ||
"maxLength": 42 | ||
}, | ||
"decimals": { | ||
"type": "number", | ||
"title": "Decimals", | ||
"examples": ["e.g. 9"] | ||
} | ||
}, | ||
"required": ["symbol", "address", "decimals"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains 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.
Hi @jscrui You can use
contract-call
strategy directly in your space instead of a separate strategy