Skip to content

Commit

Permalink
[realt] feat: realt (#1666)
Browse files Browse the repository at this point in the history
* feat: realt

* feat: skip if address is reALT strategy
  • Loading branch information
neutiyoo authored Dec 27, 2024
1 parent e9efb36 commit f2fd8f1
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ import * as fountainhead from './fountainhead';
import * as naymsStaking from './nayms-staking';
import * as morphoDelegation from './morpho-delegation';
import * as lizcoinStrategy2024 from './lizcoin-strategy-2024';
import * as realt from './realt';

const strategies = {
'delegatexyz-erc721-balance-of': delegatexyzErc721BalanceOf,
Expand Down Expand Up @@ -946,7 +947,8 @@ const strategies = {
fountainhead,
'nayms-staking': naymsStaking,
'morpho-delegation': morphoDelegation,
'lizcoin-strategy-2024': lizcoinStrategy2024
'lizcoin-strategy-2024': lizcoinStrategy2024,
realt
};

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

## Description

The reALT strategy calculates the total balance of a user's holdings in the reALT token and their shares in the reALT Strategy on the Ethereum mainnet.
20 changes: 20 additions & 0 deletions src/strategies/realt/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"name": "Example query",
"strategy": {
"name": "realt",
"params": {
"address": "0xf96798f49936efb1a56f99ceae924b6b8359affb",
"symbol": "reALT",
"decimals": 18
}
},
"network": "1",
"addresses": [
"0x15de7B6a83ee7735EA00Dc4a0506059cDA4Bef49",
"0x16Ce1B15ed1278921d7Cae34Bf60a81227CFC295",
"0x16f665dA6D806760aFC317ee29Ef2feF2Ff4976E"
],
"snapshot": 21488157
}
]
52 changes: 52 additions & 0 deletions src/strategies/realt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { BigNumberish, BigNumber } from '@ethersproject/bignumber';
import { formatUnits } from '@ethersproject/units';
import { Multicaller } from '../../utils';

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

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';
const reAltStrategy = "0x6075546538c3eFbD607ea6aFC24149fCcFb2edF4"; // reALT Strategy Mainnet

Check failure on line 17 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `"0x6075546538c3eFbD607ea6aFC24149fCcFb2edF4"` with `'0x6075546538c3eFbD607ea6aFC24149fCcFb2edF4'`

const balanceOfMulticaller = new Multicaller(network, provider, [

Check failure on line 19 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `network,·provider,·[` with `⏎····network,⏎····provider,`
'function balanceOf(address account) external view returns (uint256)',

Check failure on line 20 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `'function·balanceOf(address·account)·external·view·returns·(uint256)'` with `['function·balanceOf(address·account)·external·view·returns·(uint256)']`
], { blockTag });

Check failure on line 21 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `],·{·blockTag·}` with `··{·blockTag·}⏎··`
addresses.forEach((address) => {
if (address !== reAltStrategy) {
balanceOfMulticaller.call(address, options.address, 'balanceOf', [address]);

Check failure on line 24 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `address` with `⏎········address⏎······`
}
});

const sharesMulticaller = new Multicaller(network, provider, [

Check failure on line 28 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `network,·provider,·[` with `⏎····network,⏎····provider,`
'function shares(address user) external view returns (uint256)',

Check failure on line 29 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `'function·shares(address·user)·external·view·returns·(uint256)'` with `['function·shares(address·user)·external·view·returns·(uint256)']`
], { blockTag });

Check failure on line 30 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `],·{·blockTag·}` with `··{·blockTag·}⏎··`

addresses.forEach((address) =>
sharesMulticaller.call(address, reAltStrategy, 'shares', [address])
);

const [balanceOfResults, sharesResults]: [Record<string, BigNumberish>, Record<string, BigNumberish>] = await Promise.all([

Check failure on line 36 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `Record<string,·BigNumberish>,·Record<string,·BigNumberish>` with `⏎····Record<string,·BigNumberish>,⏎····Record<string,·BigNumberish>⏎··`
balanceOfMulticaller.execute(),
sharesMulticaller.execute()
]);

return Object.fromEntries(
addresses.map((address) => {
const balanceOf = balanceOfResults[address] || BigNumber.from(0);
const shares = sharesResults[address] || BigNumber.from(0);
const totalBalance = BigNumber.from(balanceOf).add(BigNumber.from(shares));

Check failure on line 45 in src/strategies/realt/index.ts

View workflow job for this annotation

GitHub Actions / lint / Lint

Replace `BigNumber.from(shares)` with `⏎········BigNumber.from(shares)⏎······`
return [
address,
parseFloat(formatUnits(totalBalance, options.decimals))
];
})
);
}
34 changes: 34 additions & 0 deletions src/strategies/realt/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$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. reALT"],
"maxLength": 16
},
"address": {
"type": "string",
"title": "Contract address",
"examples": ["e.g. 0xf96798f49936efb1a56f99ceae924b6b8359affb"],
"pattern": "^0x[a-fA-F0-9]{40}$",
"minLength": 42,
"maxLength": 42
},
"decimals": {
"type": "number",
"title": "Decimals",
"examples": ["e.g. 18"],
"minimum": 0
}
},
"required": ["address", "decimals"],
"additionalProperties": false
}
}
}

0 comments on commit f2fd8f1

Please sign in to comment.