Skip to content

Commit

Permalink
feat(x/oracle): store price timestamp (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyncz authored Nov 25, 2024
1 parent 866c106 commit da453f7
Show file tree
Hide file tree
Showing 36 changed files with 470 additions and 294 deletions.
87 changes: 54 additions & 33 deletions proto/archway/callback/v1/callback.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,63 @@ option go_package = "github.com/archway-network/archway/x/callback/types";

// Callback defines the callback structure.
message Callback {
// contract_address is the address of the contract which is requesting the callback (bech32 encoded).
string contract_address = 1;
// job_id is an identifier the callback requestor can pass in to identify the callback when it happens.
uint64 job_id = 2;
// callback_height is the height at which the callback is executed.
int64 callback_height = 3;
// fee_split is the breakdown of the fees paid by the contract to reserve the callback
CallbackFeesFeeSplit fee_split = 4;
// reserved_by is the address which reserved the callback (bech32 encoded).
string reserved_by = 5;
// callback_gas_limit is the maximum gas that can be consumed by this callback.
uint64 max_gas_limit = 6;
// contract_address is the address of the contract which is requesting the
// callback (bech32 encoded).
string contract_address = 1;
// job_id is an identifier the callback requestor can pass in to identify the
// callback when it happens.
uint64 job_id = 2;
// callback_height is the height at which the callback is executed.
int64 callback_height = 3;
// fee_split is the breakdown of the fees paid by the contract to reserve the
// callback
CallbackFeesFeeSplit fee_split = 4;
// reserved_by is the address which reserved the callback (bech32 encoded).
string reserved_by = 5;
// callback_gas_limit is the maximum gas that can be consumed by this
// callback.
uint64 max_gas_limit = 6;
}

// CallbackFeesFeeSplit is the breakdown of all the fees that need to be paid by the contract to reserve a callback
// CallbackFeesFeeSplit is the breakdown of all the fees that need to be paid by
// the contract to reserve a callback
message CallbackFeesFeeSplit {
// transaction_fees is the transaction fees for the callback based on its gas consumption
cosmos.base.v1beta1.Coin transaction_fees = 1;
// block_reservation_fees is the block reservation fees portion of the callback reservation fees
cosmos.base.v1beta1.Coin block_reservation_fees = 2;
// future_reservation_fees is the future reservation fees portion of the callback reservation fees
cosmos.base.v1beta1.Coin future_reservation_fees = 3;
// surplus_fees is any extra fees passed in for the registration of the callback
cosmos.base.v1beta1.Coin surplus_fees = 4;
}
// transaction_fees is the transaction fees for the callback based on its gas
// consumption
cosmos.base.v1beta1.Coin transaction_fees = 1;
// block_reservation_fees is the block reservation fees portion of the
// callback reservation fees
cosmos.base.v1beta1.Coin block_reservation_fees = 2;
// future_reservation_fees is the future reservation fees portion of the
// callback reservation fees
cosmos.base.v1beta1.Coin future_reservation_fees = 3;
// surplus_fees is any extra fees passed in for the registration of the
// callback
cosmos.base.v1beta1.Coin surplus_fees = 4;
}

// Params defines the module parameters.
message Params {
// callback_gas_limit is the maximum gas that can be consumed by a callback.
uint64 callback_gas_limit = 1;
// max_block_reservation_limit is the maximum number of callbacks which can be registered in a given block.
uint64 max_block_reservation_limit = 2;
// max_future_reservation_limit is the maximum number of blocks in the future that a contract can request a callback in.
uint64 max_future_reservation_limit = 3;
// block_reservation_fee_multiplier is used to calculate a part of the reservation fees which will need to be paid when requesting the callback.
string block_reservation_fee_multiplier = 4 [(cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
// future_reservation_fee_multiplier is used to calculate a part of the reservation fees which will need to be paid while requesting the callback.
string future_reservation_fee_multiplier = 5 [(cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false];
}
// callback_gas_limit is the maximum gas that can be consumed by a callback.
uint64 callback_gas_limit = 1;
// max_block_reservation_limit is the maximum number of callbacks which can be
// registered in a given block.
uint64 max_block_reservation_limit = 2;
// max_future_reservation_limit is the maximum number of blocks in the future
// that a contract can request a callback in.
uint64 max_future_reservation_limit = 3;
// block_reservation_fee_multiplier is used to calculate a part of the
// reservation fees which will need to be paid when requesting the callback.
string block_reservation_fee_multiplier = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// future_reservation_fee_multiplier is used to calculate a part of the
// reservation fees which will need to be paid while requesting the callback.
string future_reservation_fee_multiplier = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
6 changes: 4 additions & 2 deletions proto/archway/callback/v1/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ option go_package = "github.com/archway-network/archway/x/callback/types";
enum ModuleErrors {
// ERR_UNKNOWN is the default error code
ERR_UNKNOWN = 0;
// ERR_OUT_OF_GAS is the error code when the contract callback exceeds the gas limit allowed by the module
// ERR_OUT_OF_GAS is the error code when the contract callback exceeds the gas
// limit allowed by the module
ERR_OUT_OF_GAS = 1;
// ERR_CONTRACT_EXECUTION_FAILED is the error code when the contract callback execution fails
// ERR_CONTRACT_EXECUTION_FAILED is the error code when the contract callback
// execution fails
ERR_CONTRACT_EXECUTION_FAILED = 2;
}
86 changes: 47 additions & 39 deletions proto/archway/callback/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,62 @@ import "cosmos_proto/cosmos.proto";

// CallbackRegisteredEvent is emitted when a callback is registered.
message CallbackRegisteredEvent {
// contract_address is the address of the contract for which callback is being registered (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// callback_height is the height at which the callback is executed.
int64 callback_height = 3;
// fee_split is the breakdown of the fees paid by the contract to reserve the callback
CallbackFeesFeeSplit fee_split = 4;
// reserved_by is the address which reserved the callback (bech32 encoded).
string reserved_by = 5;
// contract_address is the address of the contract for which callback is being
// registered (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// callback_height is the height at which the callback is executed.
int64 callback_height = 3;
// fee_split is the breakdown of the fees paid by the contract to reserve the
// callback
CallbackFeesFeeSplit fee_split = 4;
// reserved_by is the address which reserved the callback (bech32 encoded).
string reserved_by = 5;
}

// CallbackCancelledEvent is emitted when a callback is cancelled.
message CallbackCancelledEvent {
// cancelled_by is the address of the contract whose callback is being cancelled (bech32 encoded)
string cancelled_by = 1;
// contract_address is the address of the contract (bech32 encoded)
string contract_address = 2;
// job_id is an identifier the callback requestor had passed during registration of the callback
uint64 job_id = 3;
// callback_height is the height at which the callback requestor had registered the callback
int64 callback_height = 4;
// refund_amount is the amount of fees which was refunded on cancellation
cosmos.base.v1beta1.Coin refund_amount = 5 [ (gogoproto.nullable) = false ];
// cancelled_by is the address of the contract whose callback is being
// cancelled (bech32 encoded)
string cancelled_by = 1;
// contract_address is the address of the contract (bech32 encoded)
string contract_address = 2;
// job_id is an identifier the callback requestor had passed during
// registration of the callback
uint64 job_id = 3;
// callback_height is the height at which the callback requestor had
// registered the callback
int64 callback_height = 4;
// refund_amount is the amount of fees which was refunded on cancellation
cosmos.base.v1beta1.Coin refund_amount = 5 [ (gogoproto.nullable) = false ];
}

// CallbackExecutedSuccessEvent is emitted when a callback is executed successfully.
// CallbackExecutedSuccessEvent is emitted when a callback is executed
// successfully.
message CallbackExecutedSuccessEvent {
// contract_address is the address of the contract for which callback is being executed (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// sudo_msg is the input passed by the module to the contract
string sudo_msg = 3;
// gas_used is the amount of gas consumed during the callback execution
uint64 gas_used = 4;
// contract_address is the address of the contract for which callback is being
// executed (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// sudo_msg is the input passed by the module to the contract
string sudo_msg = 3;
// gas_used is the amount of gas consumed during the callback execution
uint64 gas_used = 4;
}

// CallbackExecutedFailedEvent is emitted when a callback execution fails.
message CallbackExecutedFailedEvent {
// contract_address is the address of the contract for which callback is being executed (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// sudo_msg is the input passed by the module to the contract
string sudo_msg = 3;
// gas_used is the amount of gas consumed during the callback execution
uint64 gas_used = 4;
// error is the error returned during the callback execution
string error = 5;
// contract_address is the address of the contract for which callback is being
// executed (bech32 encoded).
string contract_address = 1;
// job_id is an identifier of the callback.
uint64 job_id = 2;
// sudo_msg is the input passed by the module to the contract
string sudo_msg = 3;
// gas_used is the amount of gas consumed during the callback execution
uint64 gas_used = 4;
// error is the error returned during the callback execution
string error = 5;
}
2 changes: 1 addition & 1 deletion proto/archway/callback/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "archway/callback/v1/callback.proto";
// GenesisState defines the initial state of the callback module.
message GenesisState {
// params defines all the module parameters.
Params params = 1 [ (gogoproto.nullable) = false ];
Params params = 1 [ (gogoproto.nullable) = false ];
// callbacks defines all the callbacks which are yet to be executed
repeated Callback callbacks = 2;
}
44 changes: 25 additions & 19 deletions proto/archway/callback/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import "archway/callback/v1/callback.proto";

// Query service for the callback module.
service Query {
// Params returns module parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/archway/callback/v1/params";
}
// EstimateCallbackFees returns the total amount of callback fees a contract needs to pay to register the callback
rpc EstimateCallbackFees(QueryEstimateCallbackFeesRequest) returns (QueryEstimateCallbackFeesResponse) {
option (google.api.http).get = "/archway/callback/v1/estimate_callback_fees";
}
// Callbacks returns all the callbacks registered at a given height
rpc Callbacks(QueryCallbacksRequest) returns (QueryCallbacksResponse) {
option (google.api.http).get = "/archway/callback/v1/callbacks";
}
// Params returns module parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/archway/callback/v1/params";
}
// EstimateCallbackFees returns the total amount of callback fees a contract
// needs to pay to register the callback
rpc EstimateCallbackFees(QueryEstimateCallbackFeesRequest)
returns (QueryEstimateCallbackFeesResponse) {
option (google.api.http).get =
"/archway/callback/v1/estimate_callback_fees";
}
// Callbacks returns all the callbacks registered at a given height
rpc Callbacks(QueryCallbacksRequest) returns (QueryCallbacksResponse) {
option (google.api.http).get = "/archway/callback/v1/callbacks";
}
}

// QueryParamsRequest is the request for Query.Params.
Expand All @@ -33,28 +36,31 @@ message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryEstimateCallbackFeesRequest is the request for Query.EstimateCallbackFees.
message QueryEstimateCallbackFeesRequest{
// QueryEstimateCallbackFeesRequest is the request for
// Query.EstimateCallbackFees.
message QueryEstimateCallbackFeesRequest {
// block_height is the height at which to estimate the callback fees
int64 block_height = 1;
}

// QueryEstimateCallbackFeesResponse is the response for Query.EstimateCallbackFees.
message QueryEstimateCallbackFeesResponse{
// total_fees is the total fees that needs to be paid by the contract to reserve a callback
// QueryEstimateCallbackFeesResponse is the response for
// Query.EstimateCallbackFees.
message QueryEstimateCallbackFeesResponse {
// total_fees is the total fees that needs to be paid by the contract to
// reserve a callback
cosmos.base.v1beta1.Coin total_fees = 1;
// fee_split is the breakdown of the total_fees
CallbackFeesFeeSplit fee_split = 2;
}

// QueryCallbacksRequest is the request for Query.Callbacks.
message QueryCallbacksRequest{
message QueryCallbacksRequest {
// block_height is the height at which to query the callbacks
int64 block_height = 1;
}

// QueryCallbacksResponse is the response for Query.Callbacks.
message QueryCallbacksResponse{
message QueryCallbacksResponse {
// callbacks is the list of callbacks registered at the given height
repeated Callback callbacks = 1;
}
Loading

0 comments on commit da453f7

Please sign in to comment.