|
| 1 | +import { BigNumberish } from '@ethersproject/bignumber'; |
| 2 | +import { formatUnits } from '@ethersproject/units'; |
| 3 | +import { Multicaller } from '../../utils'; |
| 4 | + |
| 5 | +export const author = 'Tarnadas'; |
| 6 | +export const version = '0.1.0'; |
| 7 | + |
| 8 | +const ORDERLY_OMNIVAULT_ADDRESS = '0x7819704B69a38fD63Cc768134b8410dc08B987D0'; |
| 9 | +const ORDERLY_DECIMALS = 18; |
| 10 | + |
| 11 | +const abi = [ |
| 12 | + 'function getStakingInfo(address _user) external view returns (uint256 orderBalance, uint256 esOrderBalance)' |
| 13 | +]; |
| 14 | + |
| 15 | +export async function strategy( |
| 16 | + space, |
| 17 | + network, |
| 18 | + provider, |
| 19 | + addresses: string[], |
| 20 | + options, |
| 21 | + snapshot: number | 'latest' |
| 22 | +): Promise<Record<string, number>> { |
| 23 | + const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; |
| 24 | + |
| 25 | + const multi = new Multicaller(network, provider, abi, { |
| 26 | + blockTag |
| 27 | + }); |
| 28 | + |
| 29 | + addresses.forEach((address) => |
| 30 | + multi.call(address, ORDERLY_OMNIVAULT_ADDRESS, 'getStakingInfo', [address]) |
| 31 | + ); |
| 32 | + |
| 33 | + const result: Record<string, [BigNumberish, BigNumberish]> = |
| 34 | + await multi.execute(); |
| 35 | + |
| 36 | + return Object.fromEntries( |
| 37 | + Object.entries(result).map(([address, stakingInfo]) => { |
| 38 | + const orderBalance = stakingInfo[0]; |
| 39 | + const esOrderBalance = stakingInfo[1]; |
| 40 | + const totalScore = |
| 41 | + parseFloat(formatUnits(orderBalance, ORDERLY_DECIMALS)) + |
| 42 | + parseFloat(formatUnits(esOrderBalance, ORDERLY_DECIMALS)); |
| 43 | + return [address, totalScore]; |
| 44 | + }) |
| 45 | + ); |
| 46 | +} |
0 commit comments