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
[defi-app-voting] feat/defi-app-voting #1742
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,8 @@ | ||
| This strategy returns total voting power on Defi App, based on HOME and sHOME | ||
|
|
||
| Here is an example of parameters: | ||
|
|
||
| { | ||
| "lockingContract": "0xC9714F8f036087d801f38C4105194e150d3a1864", | ||
| "homeToken": "0x4BfAa776991E85e5f8b1255461cbbd216cFc714f" | ||
| } |
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,19 @@ | ||
| [ | ||
| { | ||
| "name": "sHOME - Base", | ||
| "strategy": { | ||
| "name": "defi-app-voting", | ||
| "params": { | ||
| "lockingContract": "0xcfb0c58ac2db2269b4a794e615c9f4c559556da0", | ||
| "homeToken": "0xc8688a66f2588ff3064e87e9bad666c281d41af3" | ||
| } | ||
| }, | ||
| "network": "8453", | ||
| "addresses": [ | ||
| "0xFD79F3E5E5641266c46Aa7F19144Ff7F19a637C7", | ||
| "0x4011091Dbe57bd4521F598616fe4BB3978ea3005", | ||
| "0x2eAA7327e9B5Ff46bc2B7452acE9e44A1528eb84" | ||
| ], | ||
| "snapshot": 31224505 | ||
| } | ||
| ] |
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,52 @@ | ||
| import { BigNumberish } from '@ethersproject/bignumber'; | ||
| import { formatUnits } from '@ethersproject/units'; | ||
| import { Multicaller } from '../../utils'; | ||
|
|
||
| export const author = 'JD0x2e'; | ||
| export const version = '0.1.2'; | ||
|
|
||
| const mfdAbi = [ | ||
| 'function getUserLocks(address) view returns (tuple(uint256 amount, uint256 unlockTime, uint256 multiplier, uint256 duration, uint256 lockCreationTime)[])' | ||
| ]; | ||
|
|
||
| const erc20Abi = ['function balanceOf(address) view returns (uint256)']; | ||
|
|
||
| const toJsNum = (bn: BigNumberish) => parseFloat(formatUnits(bn)); | ||
|
|
||
| export async function strategy( | ||
| space, | ||
| network, | ||
| provider, | ||
| addresses, | ||
| options, | ||
| snapshot | ||
| ): Promise<Record<string, number>> { | ||
| const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
|
||
| const MFD_CONTRACT = options.lockingContract; | ||
| const HOME_TOKEN = options.homeToken; | ||
|
|
||
| const locksMulticaller = new Multicaller(network, provider, mfdAbi, { blockTag }); | ||
| const homeMulticaller = new Multicaller(network, provider, erc20Abi, { blockTag }); | ||
|
|
||
| addresses.forEach((address) => { | ||
| locksMulticaller.call(address, MFD_CONTRACT, 'getUserLocks', [address]); | ||
| homeMulticaller.call(address, HOME_TOKEN, 'balanceOf', [address]); | ||
| }); | ||
|
|
||
| const [lockResults, homeBalances] = await Promise.all([ | ||
| locksMulticaller.execute(), | ||
| homeMulticaller.execute() | ||
| ]); | ||
|
|
||
| return Object.fromEntries( | ||
| addresses.map((address) => { | ||
| const locks = lockResults[address] ?? []; | ||
| const sHome = locks.reduce((acc, lock) => acc + toJsNum(lock.amount), 0); | ||
| const home = toJsNum(homeBalances[address] ?? 0); | ||
|
|
||
| const weightedPower = sHome * 0.8 + home * 0.2; | ||
| return [address, weightedPower]; | ||
| }) | ||
| ); | ||
| } |
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
Oops, something went wrong.
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 @JD0x2e Make sure there are no other changes in this file, I think it is lint issue, else everything looks good :)
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.
@ChaituVR I've fixed this