11import { Address , encodeFunctionData } from "viem" ;
22import { SERVICE_CONFIG } from "../config/env.js" ;
3- import { logger } from "../utils/logger.js" ;
3+ import { baseLogger } from "../utils/logger.js" ;
44import {
55 CdpSliResponse ,
66 SLIAttestation ,
77 StorageProvidersSLIMetric ,
88} from "../utils/types.js" ;
9- import { SLI_ORACLE_ABI } from "./abis/sli-oracle-abi.js" ;
9+ import { SLI_ORACLE_CONTRACT_ABI } from "./abis/sli-oracle-abi.js" ;
1010import { getRpcClient , getWalletClient } from "./blockchain-client.js" ;
1111
12+ const childLogger = baseLogger . child (
13+ { avengers : "assemble" } ,
14+ { msgPrefix : "[SLI Oracle Contract] " } ,
15+ ) ;
16+
1217export async function setSliOnOracleContract (
1318 sliDataForProviders : CdpSliResponse [ ] ,
1419) {
@@ -22,7 +27,7 @@ export async function setSliOnOracleContract(
2227 provider : bigint ;
2328 sli : SLIAttestation ;
2429 } [ ] = sliDataForProviders . map ( ( provider ) => {
25- logger . info (
30+ childLogger . info (
2631 `Preparing SLI data for provider ${ provider . storageProviderId } ` ,
2732 ) ;
2833 const availabilityMetric =
@@ -82,68 +87,73 @@ export async function setSliOnOracleContract(
8287
8388 const encodedCalls = buildedSliData . map ( ( req ) =>
8489 encodeFunctionData ( {
85- abi : SLI_ORACLE_ABI ,
90+ abi : SLI_ORACLE_CONTRACT_ABI ,
8691 functionName : "setSLI" ,
8792 args : [ req . provider , req . sli ] ,
8893 } ) ,
8994 ) ;
9095
91- logger . info ( "Simulating request to oracle contract ..." ) ;
96+ childLogger . info ( "setSLI: Simulating request..." ) ;
9297
9398 const { request } = await rpcClient . simulateContract ( {
9499 address : oracleContractAddress ,
95- abi : SLI_ORACLE_ABI ,
100+ abi : SLI_ORACLE_CONTRACT_ABI ,
96101 functionName : "multicall" ,
97102 args : [ encodedCalls ] ,
98103 account : walletClient . account ,
99104 } ) ;
100105
101- logger . info ( "Simulation successful." ) ;
102-
103- logger . info ( "Sending transaction to oracle contract..." ) ;
106+ childLogger . info ( "setSLI: Sending transaction..." ) ;
104107
105108 const txHash = await walletClient . writeContract ( request ) ;
106109
107- logger . info ( `Transaction sent: ${ txHash } ` ) ;
108- logger . info ( `Waiting for confirmation...` ) ;
110+ childLogger . info (
111+ `setSLI: Transaction sent: ${ txHash } , waiting for confirmation...` ,
112+ ) ;
109113
110114 const receipt = await rpcClient . waitForTransactionReceipt ( {
111115 hash : txHash ,
112116 } ) ;
113117
114- logger . info ( `Transaction executed in block ${ receipt . blockNumber } ` ) ;
118+ childLogger . info (
119+ `setSLI: Transaction executed in block ${ receipt . blockNumber } ` ,
120+ ) ;
115121}
116122
117123export async function getSPEmptyAttestations ( ) : Promise < void > {
118124 const rpcClient = getRpcClient ( ) ;
119125
120- logger . info (
126+ childLogger . info (
121127 "Fetching Attestations from SLI Oracle contract for SP: f03315260" ,
122128 ) ;
123129
124130 const providers = await rpcClient . readContract ( {
125131 address : SERVICE_CONFIG . ORACLE_CONTRACT_ADDRESS as Address ,
126- abi : SLI_ORACLE_ABI ,
132+ abi : SLI_ORACLE_CONTRACT_ABI ,
127133 functionName : "attestations" ,
128134 args : [ 90999 ] ,
129135 } ) ;
130136
131- logger . info ( `Fetched Attestation from SLI Oracle contract: ` + providers ) ;
137+ childLogger . info (
138+ `Fetched Attestation from SLI Oracle contract: ` + providers ,
139+ ) ;
132140}
133141
134142export async function getSPFillAttestations ( ) : Promise < void > {
135143 const rpcClient = getRpcClient ( ) ;
136144
137- logger . info (
145+ childLogger . info (
138146 "Fetching Attestations from SLI Oracle contract for SP: f03315260" ,
139147 ) ;
140148
141149 const providers = await rpcClient . readContract ( {
142150 address : SERVICE_CONFIG . ORACLE_CONTRACT_ADDRESS as Address ,
143- abi : SLI_ORACLE_ABI ,
151+ abi : SLI_ORACLE_CONTRACT_ABI ,
144152 functionName : "attestations" ,
145153 args : [ 3315260 ] ,
146154 } ) ;
147155
148- logger . info ( `Fetched Attestations from SLI Oracle contract: ` + providers ) ;
156+ childLogger . info (
157+ `Fetched Attestations from SLI Oracle contract: ` + providers ,
158+ ) ;
149159}
0 commit comments