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

Add RichQuack Staking amount strategy [richquack-staked-amount] #1121

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
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ import * as izumiVeiZi from './izumi-veizi';
import * as lqtyProxyStakers from './lqty-proxy-stakers';
import * as echelonWalletPrimeAndCachedKeyGated from './echelon-wallet-prime-and-cached-key-gated';
import * as rdntCapitalVoting from './rdnt-capital-voting';
import * as richquackStakedAmount from './richquack-staked-amount';

const strategies = {
'izumi-veizi': izumiVeiZi,
Expand Down Expand Up @@ -874,7 +875,8 @@ const strategies = {
'lqty-proxy-stakers': lqtyProxyStakers,
'echelon-wallet-prime-and-cached-key-gated':
echelonWalletPrimeAndCachedKeyGated,
'rdnt-capital-voting': rdntCapitalVoting
'rdnt-capital-voting': rdntCapitalVoting,
'richquack-staked-amount': richquackStakedAmount,
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
17 changes: 17 additions & 0 deletions src/strategies/richquack-staked-amount/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# richquack-staked-amount

This strategy returns voting power for RichQuack stakers.

The voting power is based on the amount of staked tokensbalance, rather than delegated voting power.

## Params

- `stakingAddress` - (**Required**, `string`) Address of RichQuack Staking contract

Here is an example of parameters:

```json
{
"stakingAddress": "0x24E1FB7a781d255EdC40e80C89d9289dC61925F2",
}
```
20 changes: 20 additions & 0 deletions src/strategies/richquack-staked-amount/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "Example query",
"strategy": {
"name": "richquack-staked-amount",
"params": {
"stakingAddress": "0x24E1FB7a781d255EdC40e80C89d9289dC61925F2"
}
},
"network": "56",
"addresses": [
"0x8575697851F5A11494a725FF43534e859BF49710",
"0xB4433e91F287a6E116aBaF413E64B4E0697DdCce",
"0x4089bd5C7544de334b0FBc125654cEFBB9B62cDE",
"0xc2d06aD1063d895405f2243D0c79b15e676b9Db0",
"0x523D44c7E7557C724b34BABba2A931410634173B"
],
"snapshot": 27084195
}
]
57 changes: 57 additions & 0 deletions src/strategies/richquack-staked-amount/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { BigNumberish } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

export const author = 'ephdtrg';
export const version = '0.1.0';

const abi = [
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address'
}
],
name: 'stakeInfo',
outputs: [
{
internalType: 'uint256',
name: 'level',
type: 'uint256'
},
{
internalType: 'uint256',
name: 'totalStakedForUser',
type: 'uint256'
}
],
stateMutability: 'view',
type: 'function'
}
];

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, abi, { blockTag });
addresses.forEach((address) =>
multi.call(address, options.stakingAddress, 'stakeInfo', [address])
);
const result: Record<string, BigNumberish> = await multi.execute();

return Object.fromEntries(
Object.entries(result).map(([address]) => [
address,
parseFloat(formatUnits(result[address][0], 18))
])
Comment on lines +43 to +55
Copy link
Member

Choose a reason for hiding this comment

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

Hi @ephdtrg i think contract-call strategy should work for you, can try?

Copy link
Author

Choose a reason for hiding this comment

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

Hi, @ChaituVR ! Thank you for response

Do you mean to use existing contract-call strategy for this workflow, instead of writing new strategy, correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yep @ephdtrg Can use it in your space directly :)

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for suggestion @ChaituVR !
Was not aware of this strategy, will check it out and close this PR if it works as intended :)

);
}
22 changes: 22 additions & 0 deletions src/strategies/richquack-staked-amount/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"stakingAddress": {
"type": "string",
"title": "Staking address",
"examples": ["e.g. 0x24E1FB7a781d255EdC40e80C89d9289dC61925F2"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
}
},
"required": ["stakingAddress"],
"additionalProperties": false
}
}
}