Skip to content

Commit

Permalink
feat(sdk): provide price feed api (stephenh#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Oct 4, 2022
1 parent a1f5a3b commit 8c9e254
Show file tree
Hide file tree
Showing 16 changed files with 676 additions and 19 deletions.
3 changes: 3 additions & 0 deletions protos/processor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ message RecordMetaData {
// These are populated by systems.
string contract_address = 1;
uint64 block_number = 2; // TODO discuss if we need this if we send request per block
string transaction_hash = 6;
int32 transaction_index = 3;
int32 log_index = 4;
string chain_id = 5;

// These are populated by users in meter.
// The metric name and properties
// none for for log
MetricDescriptor descriptor = 8;

// The metric labels provided by users.
Expand Down Expand Up @@ -263,6 +265,7 @@ enum LogLevel {
INFO = 1;
WARNING = 2;
ERROR = 3;
CRITICAL = 4;
}

message LogResult {
Expand Down
3 changes: 2 additions & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0-development",
"scripts": {
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
"compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli",
"compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli && cp src/utils/*.csv lib/utils",
"build": "yarn gen && yarn compile",
"start_ts": "ts-node --files src/processor-runner.ts ../examples/x2y2/src/processor.ts",
"start": "ts-node --files src/processor-runner.ts ../examples/x2y2/dist/lib.js",
Expand All @@ -30,6 +30,7 @@
"bs58": "^5.0.0",
"command-line-args": "^5.2.1",
"command-line-usage": "^6.1.3",
"csv-parse": "^5.3.0",
"ethers": "~5.7.1",
"form-data": "^4.0.0",
"fs-extra": "^10.1.0",
Expand Down
227 changes: 227 additions & 0 deletions sdk/src/abis/EACAggregatorProxy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
[
{
"inputs": [
{ "internalType": "address", "name": "_aggregator", "type": "address" },
{ "internalType": "address", "name": "_accessController", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "int256", "name": "current", "type": "int256" },
{ "indexed": true, "internalType": "uint256", "name": "roundId", "type": "uint256" },
{ "indexed": false, "internalType": "uint256", "name": "updatedAt", "type": "uint256" }
],
"name": "AnswerUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "uint256", "name": "roundId", "type": "uint256" },
{ "indexed": true, "internalType": "address", "name": "startedBy", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "startedAt", "type": "uint256" }
],
"name": "NewRound",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" }
],
"name": "OwnershipTransferRequested",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{ "inputs": [], "name": "acceptOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [],
"name": "accessController",
"outputs": [{ "internalType": "contract AccessControllerInterface", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "aggregator",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_aggregator", "type": "address" }],
"name": "confirmAggregator",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "description",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_roundId", "type": "uint256" }],
"name": "getAnswer",
"outputs": [{ "internalType": "int256", "name": "", "type": "int256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint80", "name": "_roundId", "type": "uint80" }],
"name": "getRoundData",
"outputs": [
{ "internalType": "uint80", "name": "roundId", "type": "uint80" },
{ "internalType": "int256", "name": "answer", "type": "int256" },
{ "internalType": "uint256", "name": "startedAt", "type": "uint256" },
{ "internalType": "uint256", "name": "updatedAt", "type": "uint256" },
{ "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_roundId", "type": "uint256" }],
"name": "getTimestamp",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestAnswer",
"outputs": [{ "internalType": "int256", "name": "", "type": "int256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestRound",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestRoundData",
"outputs": [
{ "internalType": "uint80", "name": "roundId", "type": "uint80" },
{ "internalType": "int256", "name": "answer", "type": "int256" },
{ "internalType": "uint256", "name": "startedAt", "type": "uint256" },
{ "internalType": "uint256", "name": "updatedAt", "type": "uint256" },
{ "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "latestTimestamp",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address payable", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }],
"name": "phaseAggregators",
"outputs": [{ "internalType": "contract AggregatorV2V3Interface", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "phaseId",
"outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_aggregator", "type": "address" }],
"name": "proposeAggregator",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "proposedAggregator",
"outputs": [{ "internalType": "contract AggregatorV2V3Interface", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint80", "name": "_roundId", "type": "uint80" }],
"name": "proposedGetRoundData",
"outputs": [
{ "internalType": "uint80", "name": "roundId", "type": "uint80" },
{ "internalType": "int256", "name": "answer", "type": "int256" },
{ "internalType": "uint256", "name": "startedAt", "type": "uint256" },
{ "internalType": "uint256", "name": "updatedAt", "type": "uint256" },
{ "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proposedLatestRoundData",
"outputs": [
{ "internalType": "uint80", "name": "roundId", "type": "uint80" },
{ "internalType": "int256", "name": "answer", "type": "int256" },
{ "internalType": "uint256", "name": "startedAt", "type": "uint256" },
{ "internalType": "uint256", "name": "updatedAt", "type": "uint256" },
{ "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_accessController", "type": "address" }],
"name": "setController",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_to", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
}
]
6 changes: 6 additions & 0 deletions sdk/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class EthContext extends BaseContext {
block?: Block
trace?: Trace
blockNumber: Long
transactionHash?: string

constructor(chainId: number, block?: Block, log?: Log, trace?: Trace) {
super()
Expand All @@ -31,9 +32,14 @@ export class EthContext extends BaseContext {
this.trace = trace
if (log) {
this.blockNumber = Long.fromNumber(log.blockNumber)
this.transactionHash = log.transactionHash
} else if (block) {
this.blockNumber = Long.fromNumber(block.number)
}
if (trace) {
this.blockNumber = Long.fromNumber(trace.blockNumber)
this.transactionHash = trace.transactionHash
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions sdk/src/gen/processor/protos/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export enum LogLevel {
INFO = 1,
WARNING = 2,
ERROR = 3,
CRITICAL = 4,
UNRECOGNIZED = -1,
}

Expand All @@ -83,6 +84,9 @@ export function logLevelFromJSON(object: any): LogLevel {
case 3:
case "ERROR":
return LogLevel.ERROR;
case 4:
case "CRITICAL":
return LogLevel.CRITICAL;
case -1:
case "UNRECOGNIZED":
default:
Expand All @@ -100,6 +104,8 @@ export function logLevelToJSON(object: LogLevel): string {
return "WARNING";
case LogLevel.ERROR:
return "ERROR";
case LogLevel.CRITICAL:
return "CRITICAL";
case LogLevel.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand Down Expand Up @@ -274,6 +280,7 @@ export interface MetricDescriptor {
export interface RecordMetaData {
contractAddress: string;
blockNumber: Long;
transactionHash: string;
transactionIndex: number;
logIndex: number;
chainId: string;
Expand Down Expand Up @@ -2770,6 +2777,7 @@ function createBaseRecordMetaData(): RecordMetaData {
return {
contractAddress: "",
blockNumber: Long.UZERO,
transactionHash: "",
transactionIndex: 0,
logIndex: 0,
chainId: "",
Expand All @@ -2789,6 +2797,9 @@ export const RecordMetaData = {
if (!message.blockNumber.isZero()) {
writer.uint32(16).uint64(message.blockNumber);
}
if (message.transactionHash !== "") {
writer.uint32(50).string(message.transactionHash);
}
if (message.transactionIndex !== 0) {
writer.uint32(24).int32(message.transactionIndex);
}
Expand Down Expand Up @@ -2826,6 +2837,9 @@ export const RecordMetaData = {
case 2:
message.blockNumber = reader.uint64() as Long;
break;
case 6:
message.transactionHash = reader.string();
break;
case 3:
message.transactionIndex = reader.int32();
break;
Expand Down Expand Up @@ -2863,6 +2877,9 @@ export const RecordMetaData = {
blockNumber: isSet(object.blockNumber)
? Long.fromValue(object.blockNumber)
: Long.UZERO,
transactionHash: isSet(object.transactionHash)
? String(object.transactionHash)
: "",
transactionIndex: isSet(object.transactionIndex)
? Number(object.transactionIndex)
: 0,
Expand All @@ -2889,6 +2906,8 @@ export const RecordMetaData = {
(obj.contractAddress = message.contractAddress);
message.blockNumber !== undefined &&
(obj.blockNumber = (message.blockNumber || Long.UZERO).toString());
message.transactionHash !== undefined &&
(obj.transactionHash = message.transactionHash);
message.transactionIndex !== undefined &&
(obj.transactionIndex = Math.round(message.transactionIndex));
message.logIndex !== undefined &&
Expand All @@ -2914,6 +2933,7 @@ export const RecordMetaData = {
object.blockNumber !== undefined && object.blockNumber !== null
? Long.fromValue(object.blockNumber)
: Long.UZERO;
message.transactionHash = object.transactionHash ?? "";
message.transactionIndex = object.transactionIndex ?? 0;
message.logIndex = object.logIndex ?? 0;
message.chainId = object.chainId ?? "";
Expand Down
Loading

0 comments on commit 8c9e254

Please sign in to comment.