@@ -7,7 +7,7 @@ import { MulticallWrapper } from 'ethers-multicall-provider'
7
7
const EthDater = require ( 'ethereum-block-by-date' )
8
8
9
9
const ethersProvider = MulticallWrapper . wrap ( new ethers . JsonRpcProvider (
10
- 'https://ethereum.publicnode.com '
10
+ 'https://lb.nodies.app/v1/5e9daed367d1454fab7c75f0ec8aceff '
11
11
) )
12
12
console . info ( 'ethersProvider:' , ethersProvider )
13
13
@@ -49,6 +49,9 @@ async function loadVotingEscrowData() {
49
49
} )
50
50
const csvRows = [ ]
51
51
52
+ const votingEscrowAtBlockArray = await getVotingEscrowAtBlockArray ( blockPerWeekArray , ethAddress )
53
+ // console.debug('votingEscrowAtBlockArray:', votingEscrowAtBlockArray)
54
+
52
55
// Iterate every week from the week of [Sun May-29-2022 → Sun Jun-05-2022] until now
53
56
const weekEndDate : Date = new Date ( '2022-06-05T00:00:00Z' )
54
57
console . info ( 'weekEndDate:' , weekEndDate )
@@ -65,7 +68,7 @@ async function loadVotingEscrowData() {
65
68
// console.debug('blockByDate:', blockByDate)
66
69
67
70
// Get Citizen's voting escrow at the current block
68
- const votingEscrowWei : number = await getVotingEscrowAtBlock ( ethAddress , blockByDate . block )
71
+ const votingEscrowWei : number = votingEscrowAtBlockArray [ weekNumber - 1 ]
69
72
console . info ( 'votingEscrowWei:' , votingEscrowWei )
70
73
const votingEscrowEther : string = ethers . formatUnits ( votingEscrowWei )
71
74
console . info ( 'votingEscrowEther:' , votingEscrowEther )
@@ -108,7 +111,20 @@ async function getBlockPerWeekArray() {
108
111
return Promise . all ( calls )
109
112
}
110
113
111
- async function getVotingEscrowAtBlock ( ethAddress : string , blockNumber : number ) : Promise < number > {
112
- console . info ( 'getVotingEscrowAtBlock' )
113
- return await votingEscrowContract . balanceOfAt ( ethAddress , blockNumber )
114
+ /**
115
+ * Multicall for getting the voting-escrow balance for the block
116
+ * each week's block number.
117
+ */
118
+ async function getVotingEscrowAtBlockArray ( blockPerWeekArray : any , ethAddress : string ) {
119
+ console . info ( 'getVotingEscrowAtBlockArray' , ethAddress )
120
+
121
+ // Populate an Array with one call per block number
122
+ const calls : any = [ ]
123
+ blockPerWeekArray . forEach ( ( element : any ) => {
124
+ // console.debug('element:', element)
125
+ calls . push ( votingEscrowContract . balanceOfAt ( ethAddress , element . block ) )
126
+ } )
127
+ // console.debug('calls.length:', calls.length)
128
+
129
+ return Promise . all ( calls )
114
130
}
0 commit comments