-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement oracle rpc calls #39
Changes from 7 commits
827b90c
2215c57
501eb25
5feae91
6f547be
1ced83a
cf1519c
09a7d83
102864f
706054b
e8976ca
27e95e8
d84a6a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,24 +576,27 @@ export class EboActor { | |
* @param chainId the CAIP-2 compliant chain ID | ||
*/ | ||
private async proposeResponse(chainId: Caip2ChainId): Promise<void> { | ||
const response = await this.buildResponse(chainId); | ||
const responseBody = await this.buildResponse(chainId); | ||
const request = this.getActorRequest(); | ||
|
||
if (this.alreadyProposed(response.epoch, response.chainId, response.block)) { | ||
throw new ResponseAlreadyProposed(response); | ||
if (this.alreadyProposed(responseBody.epoch, responseBody.chainId, responseBody.block)) { | ||
throw new ResponseAlreadyProposed(responseBody); | ||
} | ||
|
||
const response: Response["prophetData"] = { | ||
// TODO: check if this is the correct proposer | ||
proposer: request.prophetData.requester, | ||
requestId: request.id, | ||
response: responseBody, | ||
}; | ||
|
||
try { | ||
await this.protocolProvider.proposeResponse( | ||
this.actorRequest.id, | ||
response.epoch, | ||
response.chainId, | ||
response.block, | ||
); | ||
await this.protocolProvider.proposeResponse(request.prophetData, response); | ||
} catch (err) { | ||
if (err instanceof ContractFunctionRevertedError) { | ||
this.logger.warn( | ||
`Block ${response.block} for epoch ${response.epoch} and ` + | ||
`chain ${response.chainId} was not proposed. Skipping proposal...`, | ||
`Block ${responseBody.block} for epoch ${responseBody.epoch} and ` + | ||
`chain ${responseBody.chainId} was not proposed. Skipping proposal...`, | ||
); | ||
} else { | ||
this.logger.error( | ||
|
@@ -617,15 +620,19 @@ export class EboActor { | |
|
||
if (this.equalResponses(actorResponse, eventResponse.response)) { | ||
this.logger.info(`Response ${event.metadata.responseId} was validated. Skipping...`); | ||
|
||
return; | ||
} | ||
|
||
await this.protocolProvider.disputeResponse( | ||
event.metadata.requestId, | ||
event.metadata.responseId, | ||
event.metadata.response.proposer, | ||
); | ||
const request = this.getActorRequest(); | ||
|
||
const dispute: Dispute["prophetData"] = { | ||
// TODO: check if this is the correct disputer | ||
disputer: this.actorRequest.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
proposer: eventResponse.proposer, | ||
responseId: event.metadata.responseId, | ||
requestId: request.id, | ||
}; | ||
await this.protocolProvider.disputeResponse(request.prophetData, eventResponse, dispute); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class TransactionExecutionError extends Error { | ||
constructor(message = "Transaction failed") { | ||
super(message); | ||
this.name = "TransactionExecutionError"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js"; | ||
import { Timestamp } from "@ebo-agent/shared"; | ||
import { Address } from "viem"; | ||
|
||
|
@@ -73,29 +72,28 @@ export interface IWriteProvider { | |
/** | ||
* Proposes a response to a request. | ||
* | ||
* @param _requestId The ID of the request. | ||
* @param _epoch The epoch of the request. | ||
* @param _chainId The chain ID where the request was made. | ||
* @param _blockNumber The block number associated with the response. | ||
* @param _request The request data. | ||
* @param _response The response data. | ||
* @returns A promise that resolves when the response is proposed. | ||
*/ | ||
proposeResponse( | ||
_requestId: string, | ||
_epoch: bigint, | ||
_chainId: Caip2ChainId, | ||
_blockNumber: bigint, | ||
_request: Request["prophetData"], | ||
_response: Response["prophetData"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a small detail, we want to remove those I think they were left there to be consistent with the methods being defined but not implemented (so the params had to be prefixed with an underscore so ESLint could pass). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
): Promise<void>; | ||
|
||
/** | ||
* Disputes a proposed response. | ||
* | ||
* @param _requestId The ID of the request. | ||
* @param _responseId The ID of the response to dispute. | ||
* @param _proposer The address of the proposer. | ||
* @param _request The request data. | ||
* @param _response The response data. | ||
* @param _dispute The dispute data. | ||
* @returns A promise that resolves when the response is disputed. | ||
*/ | ||
disputeResponse(_requestId: string, _responseId: string, _proposer: Address): Promise<void>; | ||
|
||
disputeResponse( | ||
_request: Request["prophetData"], | ||
_response: Response["prophetData"], | ||
_dispute: Dispute["prophetData"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ got rid of the _ in the whole file--no lint issues |
||
): Promise<void>; | ||
/** | ||
* Pledges support for a dispute. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposer must be the address of the transaction sender as Prophet actually checks that the
sender === propose.proposer
[1].Viem has some methods that might be helpful for this like
getAddresses
[2] [3].[1] https://github.com/defi-wonderland/prophet-core/blob/0954a47f7dbd225ee0d48c9face954a7db6aed30/solidity/contracts/Oracle.sol#L118-L119
[2] https://viem.sh/docs/clients/wallet.html#account-optional
[3] https://viem.sh/docs/actions/wallet/getAddresses.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ I added a new function to protocolProvider to get the writeClient account address, added a new custom error and some tests