@@ -976,7 +976,6 @@ let provideCONET
976976let lesteningBlock = false
977977let epoch = 0
978978let needUpgradeVer = 0
979- let claimedCntpInChristmas2024Event = 0
980979
981980const listenProfileVer = async ( ) => {
982981 epoch = await provideCONET . getBlockNumber ( )
@@ -999,13 +998,13 @@ const listenProfileVer = async () => {
999998
1000999 runningList . push ( getBalanceOfMonitoredWallets ( ) )
10011000
1002- runningList . push ( getClaimedCntpReward ( ) )
1001+ runningList . push ( getHistoricBalance ( ) )
10031002
10041003 await Promise . all ( runningList )
10051004
10061005 const cmd = {
10071006 cmd : 'assets' ,
1008- data : [ profiles , RefereesList , leaderboardData , assetOracle , CoNET_Data ?. monitoredWallets , claimedCntpInChristmas2024Event ]
1007+ data : [ profiles , RefereesList , leaderboardData , assetOracle , CoNET_Data ?. monitoredWallets ]
10091008 }
10101009
10111010 sendState ( 'toFrontEnd' , cmd )
@@ -1019,90 +1018,72 @@ const listenProfileVer = async () => {
10191018 selectLeaderboard ( epoch )
10201019}
10211020
1022- function isSpecificTime ( ) {
1023- const targetDate = new Date ( "2024-12-20T00:00:00-08:00" ) ; // PST is UTC-8
1024- const currentDate = new Date ( ) ;
1021+ const getHistoricBalance = async ( ) => {
1022+ if ( ! CoNET_Data ?. profiles ) {
1023+ return logger ( `getHistoricBalance Error! CoNET_Data.profiles empty Error!` )
1024+ }
10251025
1026- const targetDatePST = new Date (
1027- targetDate . toLocaleString ( "en-US" , { timeZone : "America/Los_Angeles" } )
1028- ) ;
1026+ const profiles = CoNET_Data . profiles
1027+ const daysInChart = generateDaysArrayForBalanceChart ( ) ;
10291028
1030- // Convert current date to PST
1031- const currentDatePST = new Date (
1032- currentDate . toLocaleString ( "en-US" , { timeZone : "America/Los_Angeles" } )
1033- ) ;
1029+ const runningList : any [ ] = [ ]
10341030
1035- return targetDatePST . getTime ( ) <= currentDatePST . getTime ( ) ;
1031+ for ( let profile of profiles ) {
1032+ const promise = getHistoricCntpBalance ( profile , daysInChart )
1033+ runningList . push ( promise )
1034+ }
1035+
1036+ await Promise . all ( runningList )
10361037}
10371038
1039+ const getHistoricCntpBalance = async ( profile : profile , daysInChart : number [ ] ) => {
1040+ const provideCONET = new ethers . JsonRpcProvider ( conet_rpc ) ;
1041+ const wallet = new ethers . Wallet ( profile . privateKeyArmor , provideCONET )
1042+ const contract = new ethers . Contract ( cCNTP_new_Addr , blast_CNTPAbi , wallet )
10381043
1039- const getClaimedCntpReward = async ( ) => {
1040- const provider = new ethers . JsonRpcProvider ( conet_rpc ) ;
1041-
1042- const christmas2024Contract = new ethers . Contract (
1043- christmas2024ContractAddress ,
1044- christmas2024Abi ,
1045- provider
1046- ) ;
1044+ const runningList : any [ ] = [ ]
10471045
1048- try {
1049- const claimedCntp = await christmas2024Contract . claimedCNTP ( )
1050- claimedCntpInChristmas2024Event = Number ( claimedCntp ) / Math . pow ( 10 , 18 )
1051- } catch ( error ) {
1052- claimedCntpInChristmas2024Event = 0
1053- }
1054- }
1046+ for ( let timestamp of daysInChart ) {
1047+ const promise = getBalanceByTimestamp (
1048+ contract ,
1049+ wallet . address ,
1050+ timestamp
1051+ ) ;
10551052
1056- const getProfileAvailableCntpReward = async ( cmd ) => {
1057- if ( ! isSpecificTime ( ) ) return ;
1053+ runningList . push ( promise ) ;
1054+ }
10581055
1059- const walletAddress = cmd . data [ 0 ] ;
1056+ profile . historicBalance = [ ] ;
10601057
1061- if ( ! CoNET_Data || ! walletAddress ) {
1062- cmd . err = "FAILURE" ;
1063- return returnUUIDChannel ( cmd ) ;
1064- }
1058+ const balances = await Promise . all ( runningList ) ;
10651059
1066- const provider = new ethers . JsonRpcProvider ( conet_rpc ) ;
1067-
1068- const christmas2024Contract = new ethers . Contract (
1069- christmas2024ContractAddress ,
1070- christmas2024Abi ,
1071- provider
1072- ) ;
1060+ balances . forEach ( ( balance , index ) => {
1061+ const balanceObj = {
1062+ timestamp : daysInChart [ index ] ,
1063+ balance : ethers . formatEther ( balance ) ,
1064+ } ;
10731065
1074- try {
1075- const claimableCntp = await christmas2024Contract . showClaimableCNTP ( walletAddress )
1076- cmd . data = [ Number ( claimableCntp ) ] ;
1077- } catch ( err ) {
1078- logger ( `error getting available CNTP reward` , err ) ;
1079- cmd . err = "FAILURE" ;
1080- }
1066+ if ( ! profile . historicBalance )
1067+ profile . historicBalance = [ ] ;
10811068
1082- return returnUUIDChannel ( cmd ) ;
1069+ profile . historicBalance . push ( balanceObj ) ;
1070+ } ) ;
10831071}
10841072
1085- const claimChristmasReward = async ( cmd : any ) => {
1086- if ( ! isSpecificTime ( ) ) return ;
1073+ function isSpecificTime ( ) {
1074+ const targetDate = new Date ( "2024-12-20T00:00:00-08:00" ) ; // PST is UTC-8
1075+ const currentDate = new Date ( ) ;
10871076
1088- const walletAddressTmp = cmd . data [ 0 ] ;
1089- const walletAddress = ethers . getAddress ( walletAddressTmp ) ;
1077+ const targetDatePST = new Date (
1078+ targetDate . toLocaleString ( "en-US" , { timeZone : "America/Los_Angeles" } )
1079+ ) ;
10901080
1091- try {
1092- const url = `${ apiv4_endpoint } christmas2024` ;
1093- const result : any = await postToEndpoint ( url , true , { walletAddress } ) ;
1094-
1095- if ( ! result ) {
1096- cmd . err = "FAILURE"
1097- }
1098- else if ( result . status === 200 ) {
1099- cmd . data [ 0 ] = result ;
1100- }
1101- } catch ( err ) {
1102- cmd . err = "FAILURE"
1103- }
1081+ // Convert current date to PST
1082+ const currentDatePST = new Date (
1083+ currentDate . toLocaleString ( "en-US" , { timeZone : "America/Los_Angeles" } )
1084+ ) ;
11041085
1105- return returnUUIDChannel ( cmd ) ;
1086+ return targetDatePST . getTime ( ) <= currentDatePST . getTime ( ) ;
11061087}
11071088
11081089const checkProfileVersion = async ( wallet ) => {
@@ -2398,6 +2379,7 @@ const getBalanceByTimestamp = async (erc20Contract, walletAddress: string, times
23982379 return balance
23992380 } catch ( ex ) {
24002381 console . log ( "historic balance error" , ex ) ;
2382+ return 0
24012383 }
24022384}
24032385
@@ -2421,11 +2403,11 @@ const getBlockByTimestamp = async (
24212403 let earliestBlock = await provider . getBlock ( 0 ) ;
24222404
24232405 // Ensure the target timestamp is valid
2424- if ( targetTimestamp < earliestBlock . timestamp ) {
2406+ if ( targetTimestamp < earliestBlock . timestamp * 1000 ) {
24252407 throw new Error ( "Timestamp is earlier than the first block" ) ;
24262408 }
24272409
2428- if ( targetTimestamp > latestBlock . timestamp ) {
2410+ if ( targetTimestamp > latestBlock . timestamp * 1000 ) {
24292411 throw new Error ( "Timestamp is in the future" ) ;
24302412 }
24312413
0 commit comments