-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: realt * feat: skip if address is reALT strategy
- Loading branch information
Showing
5 changed files
with
114 additions
and
1 deletion.
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
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,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. |
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,20 @@ | ||
[ | ||
{ | ||
"name": "Example query", | ||
"strategy": { | ||
"name": "realt", | ||
"params": { | ||
"address": "0xf96798f49936efb1a56f99ceae924b6b8359affb", | ||
"symbol": "reALT", | ||
"decimals": 18 | ||
} | ||
}, | ||
"network": "1", | ||
"addresses": [ | ||
"0x15de7B6a83ee7735EA00Dc4a0506059cDA4Bef49", | ||
"0x16Ce1B15ed1278921d7Cae34Bf60a81227CFC295", | ||
"0x16f665dA6D806760aFC317ee29Ef2feF2Ff4976E" | ||
], | ||
"snapshot": 21488157 | ||
} | ||
] |
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,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 | ||
|
||
const balanceOfMulticaller = new Multicaller(network, provider, [ | ||
'function balanceOf(address account) external view returns (uint256)', | ||
], { blockTag }); | ||
addresses.forEach((address) => { | ||
if (address !== reAltStrategy) { | ||
balanceOfMulticaller.call(address, options.address, 'balanceOf', [address]); | ||
} | ||
}); | ||
|
||
const sharesMulticaller = new Multicaller(network, provider, [ | ||
'function shares(address user) external view returns (uint256)', | ||
], { blockTag }); | ||
|
||
addresses.forEach((address) => | ||
sharesMulticaller.call(address, reAltStrategy, 'shares', [address]) | ||
); | ||
|
||
const [balanceOfResults, sharesResults]: [Record<string, BigNumberish>, Record<string, BigNumberish>] = await Promise.all([ | ||
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)); | ||
return [ | ||
address, | ||
parseFloat(formatUnits(totalBalance, options.decimals)) | ||
]; | ||
}) | ||
); | ||
} |
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,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 | ||
} | ||
} | ||
} |