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

[monsta-dce] monsta-dce voting strategy creation #1286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/strategies/monsta-dce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Monsta DCE Strategy

This custom voting strategy, known as the Monsta DCE Strategy, is designed to determine voting power based on specific criteria. Users must meet certain requirements to have voting power in a snapshot vote.

## Strategy Overview

The Monsta DCE Strategy requires users to hold at least one ERC721 token and have a minimum balance of 5,000,000 of a specified ERC20 token. If users meet these conditions, they will be granted voting power. Otherwise, they will have no voting power.

## Parameters

- ERC721 Token Address: The address of the ERC721 token contract.
- ERC20 Token Address: The address of the ERC20 token contract.
- ERC20 Token Decimals: The number of decimal places used by the ERC20 token.

## Example Setup

Here is an example setup for the Monsta DCE Strategy:

```json
{
"erc721Address": "0x371a31Bf669Df23628E9D8858CB4b4620B491D83",
"erc20Address": "0x8A5d7FCD4c90421d21d30fCC4435948aC3618B2f",
"erc20Decimals": 18
}
21 changes: 21 additions & 0 deletions src/strategies/monsta-dce/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"name": "Monsta DCE Strategy Example",
"strategy": {
"name": "monsta-dce",
"params": {
"erc721Address": "0x371a31Bf669Df23628E9D8858CB4b4620B491D83",
"erc20Address": "0x8A5d7FCD4c90421d21d30fCC4435948aC3618B2f",
"erc20Decimals": 18
}
},
"network": "1",
"addresses": [
"0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11",
"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7",
"0x1E1A51E25f2816335cA436D65e9Af7694BE232ad"
// Add more addresses here for testing if needed
],
"snapshot": 11437846
}
]
57 changes: 57 additions & 0 deletions src/strategies/monsta-dce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { BigNumberish, utils } from 'ethers';

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

'BigNumberish' is declared but its value is never read.

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

Cannot find module 'ethers' or its corresponding type declarations.

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

'erc20Abi' is declared but its value is never read.

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

'erc721Abi' is declared but its value is never read.

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

Expected 3-4 arguments, but got 2.

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

Property 'all' does not exist on type 'Multicaller'. Did you mean 'call'?

Check failure on line 1 in src/strategies/monsta-dce/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

Property 'all' does not exist on type 'Multicaller'. Did you mean 'call'?
import { Multicaller } from '../../utils';

export const author = 'Crypt0MJ';
export const version = '1.0.0';
export const strategyName = 'monsta-dce-strategy';

const erc20Abi = [
'function balanceOf(address account) external view returns (uint256)',
];

const erc721Abi = [
'function balanceOf(address owner) external view returns (uint256)',
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const multi = new Multicaller(network, provider);

const erc20Balances = await multi.all(
addresses.map((address) => [
options.erc20Address,
'balanceOf',
[address],
{ blockTag },
])
);

const erc721Balances = await multi.all(
addresses.map((address) => [
options.erc721Address,
'balanceOf',
[address],
{ blockTag },
])
);

const votingPower = {};
addresses.forEach((address, index) => {
const erc20Balance = utils.formatUnits(erc20Balances[index], options.erc20Decimals);
const erc721Balance = erc721Balances[index];
if (parseFloat(erc20Balance) >= 5000000 && parseFloat(erc721Balance) >= 1) {
votingPower[address] = 1; // You can customize the voting power as needed.
} else {
votingPower[address] = 0; // No voting power if requirements are not met.
}
});

return votingPower;
}
35 changes: 35 additions & 0 deletions src/strategies/monsta-dce/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Monsta DCE Strategy",
"type": "object",
"properties": {
"erc721Address": {
"type": "string",
"title": "ERC721 Contract Address",
"examples": ["e.g. 0x371a31Bf669Df23628E9D8858CB4b4620B491D83"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"erc20Address": {
"type": "string",
"title": "ERC20 Contract Address",
"examples": ["e.g. 0x8A5d7FCD4c90421d21d30fCC4435948aC3618B2f"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"erc20Decimals": {
"type": "number",
"title": "ERC20 Decimals",
"examples": ["e.g. 18"]
}
},
"required": ["erc721Address", "erc20Address", "erc20Decimals"],
"additionalProperties": false
}
}
}
Loading