diff --git a/README.md b/README.md index e97ddbc..3db1859 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ### On Sepolia -XAPI: `0x6984ebE378F8cb815546Cb68a98807C1fA121A81` +XAPI: `0x06e1aCbb0A1d23F57798ca36eb3e20D552AcfC62` XAPI Consumer Example: `0xcd3627925b1396104126Fa400715A01C09703D66` diff --git a/aggregator/src/abstract/aggregator.abstract.ts b/aggregator/src/abstract/aggregator.abstract.ts index 4ed2ca9..10b43be 100644 --- a/aggregator/src/abstract/aggregator.abstract.ts +++ b/aggregator/src/abstract/aggregator.abstract.ts @@ -11,7 +11,6 @@ export enum RequestStatus { FETCHING, AGGREGATED, PUBLISHED, - TIMEOUT, } export enum RequestMethod { @@ -98,12 +97,6 @@ class RemoveDataSourceEvent extends Nep297Event { } } -class TimeoutEvent extends Nep297Event { - constructor(data: Response) { - super("Timeout", data) - } -} - class ReportEvent extends Nep297Event { constructor(data: Report) { super("Report", data) @@ -238,17 +231,12 @@ export class Staked { account_id: AccountId } -// Default timeout: 5 hours -const DEFAULT_TIME_OUT = "18000000000000"; - // Derivation path prefix for mpc const DERIVATION_PATH_PREFIX = "XAPI"; export abstract class Aggregator extends ContractBase { description: string; latest_request_id: RequestId; - // Nanoseconds - timeout: Timestamp; mpc_config: MpcConfig; staking_contract: AccountId; @@ -263,19 +251,13 @@ export abstract class Aggregator extends ContractBase { // key: chain_id publish_chain_config_lookup: LookupMap; - constructor({ description, timeout, mpc_config, reporter_required, staking_contract, contract_metadata, }: { description: string, timeout: Timestamp, mpc_config: MpcConfig, reporter_required: ReporterRequired, staking_contract: AccountId, contract_metadata: ContractSourceMetadata }) { + constructor({ description, mpc_config, reporter_required, staking_contract, contract_metadata, }: { description: string, mpc_config: MpcConfig, reporter_required: ReporterRequired, staking_contract: AccountId, contract_metadata: ContractSourceMetadata }) { super(contract_metadata); this.description = description; this.mpc_config = mpc_config; this.reporter_required = reporter_required; this.staking_contract = staking_contract; - if (!timeout) { - this.timeout = DEFAULT_TIME_OUT; - } else { - this.timeout = timeout; - } - this.data_sources = new UnorderedMap("data_sources"); this.report_lookup = new LookupMap("report_lookup"); this.response_lookup = new LookupMap("response_lookup"); @@ -428,18 +410,6 @@ export abstract class Aggregator extends ContractBase { return this.publish_chain_config_lookup.get(chain_id); } - abstract set_timeout({ timeout }: { timeout: Timestamp }): void; - _set_timeout({ timeout }: { timeout: Timestamp }): void { - this._assert_operator(); - assert(BigInt(timeout) > BigInt(0), "timeout should be greater than 0."); - this.timeout = timeout; - } - - abstract get_timeout(): Timestamp; - _get_timeout(): Timestamp { - return this.timeout; - } - abstract get_latest_request_id(): string; _get_latest_request_id(): RequestId { return this.latest_request_id; @@ -497,14 +467,6 @@ export abstract class Aggregator extends ContractBase { _response = this.response_lookup.get(request_id); } - // Update timeout status if necessary. - if (_response.status == RequestStatus[RequestStatus.FETCHING] && BigInt(_response.started_at) + BigInt(this.timeout) < near.blockTimestamp()) { - _response.status = RequestStatus[RequestStatus.TIMEOUT]; - new TimeoutEvent(_response).emit(); - this.response_lookup.set(request_id, _response); - return; - } - // Only fetching request can accept reports. assert( _response.status == RequestStatus[RequestStatus.FETCHING], @@ -634,17 +596,6 @@ export abstract class Aggregator extends ContractBase { assert(_response != null, `Response for ${request_id} does not exist`); assert(_response.status == RequestStatus[RequestStatus.AGGREGATED] || _response.status == RequestStatus[RequestStatus.PUBLISHED], `Response status is ${_response.status}, can't be published`); - // Update timeout status if necessary. - if (BigInt(_response.started_at) + BigInt(this.timeout) < near.blockTimestamp()) { - if (_response.status == RequestStatus[RequestStatus.AGGREGATED]) { - _response.status = RequestStatus[RequestStatus.TIMEOUT]; - new TimeoutEvent(_response).emit(); - this.response_lookup.set(request_id, _response); - } - near.log(`Request ${request_id} is timeout.`); - return; - } - const _chain_config = this.publish_chain_config_lookup.get(_response.chain_id); assert(_chain_config != null, `Chain config for ${_response.chain_id} does not exist`); diff --git a/aggregator/src/ormp.aggregator.ts b/aggregator/src/ormp.aggregator.ts index 2d0b6d2..caf0b12 100644 --- a/aggregator/src/ormp.aggregator.ts +++ b/aggregator/src/ormp.aggregator.ts @@ -9,7 +9,7 @@ class OrmpAggregator extends Aggregator { constructor() { super({ - description: "ORMP Aggregator", timeout: null, + description: "ORMP Aggregator", mpc_config: new MpcConfig({ mpc_contract: "v1.signer-prod.testnet", attached_balance: BigInt(10 ** 24).toString() }), reporter_required: new ReporterRequired(1, 1), // todo update staking contract @@ -148,11 +148,6 @@ class OrmpAggregator extends Aggregator { super._set_publish_chain_config(publis_chain_config); } - @call({}) - set_timeout({ timeout }: { timeout: Timestamp; }): void { - super._set_timeout({ timeout }) - } - @call({}) set_mpc_config(mpc_config: MpcConfig): void { super._set_mpc_config(mpc_config); @@ -191,10 +186,6 @@ class OrmpAggregator extends Aggregator { return super._get_reports({ request_id }); } @view({}) - get_timeout(): Timestamp { - return super._get_timeout(); - } - @view({}) get_publish_chain_config({ chain_id }: { chain_id: ChainId; }): PublishChainConfig { return super._get_publish_chain_config({ chain_id }) } diff --git a/xapi/contracts/XAPI.sol b/xapi/contracts/XAPI.sol index 54c8342..8fbb953 100644 --- a/xapi/contracts/XAPI.sol +++ b/xapi/contracts/XAPI.sol @@ -38,7 +38,15 @@ contract XAPI is IXAPI, Ownable2Step { response: ResponseData({reporters: new address[](0), result: new bytes(0)}), requestData: requestData }); - emit RequestMade(requestId, aggregatorConfig.aggregator, requestData, msg.sender); + emit RequestMade( + requestId, + aggregatorConfig.aggregator, + requestData, + msg.sender, + exAggregator, + aggregatorConfig.reportersFee, + aggregatorConfig.publishFee + ); return requestId; } @@ -53,10 +61,7 @@ contract XAPI is IXAPI, Ownable2Step { AggregatorConfig memory aggregatorConfig = aggregatorConfigs[msg.sender]; // Avoid changing the reward configuration after the request but before the response to obtain the contract balance - require( - aggregatorConfig.publishFee + aggregatorConfig.reportersFee <= request.payment, - "Insufficient rewards" - ); + require(aggregatorConfig.publishFee + aggregatorConfig.reportersFee <= request.payment, "Insufficient rewards"); for (uint256 i = 0; i < response.reporters.length; i++) { rewards[response.reporters[i]] += aggregatorConfig.reportersFee / response.reporters.length; } @@ -110,7 +115,7 @@ contract XAPI is IXAPI, Ownable2Step { emit AggregatorConfigSet(msg.sender, reportersFee, publishFee, aggregator, rewardAddress); } - function suspendAggregator(address exAggregator) external onlyOwner{ + function suspendAggregator(address exAggregator) external onlyOwner { require(aggregatorConfigs[exAggregator].rewardAddress != address(0), "!Aggregator"); aggregatorConfigs[exAggregator].suspended = true; diff --git a/xapi/contracts/interfaces/IXAPI.sol b/xapi/contracts/interfaces/IXAPI.sol index 068650e..60c7ef3 100644 --- a/xapi/contracts/interfaces/IXAPI.sol +++ b/xapi/contracts/interfaces/IXAPI.sol @@ -36,15 +36,19 @@ struct AggregatorConfig { } interface IXAPI { - event RequestMade(uint256 indexed requestId, string aggregator, string requestData, address indexed requester); + event RequestMade( + uint256 indexed requestId, + string aggregator, + string requestData, + address indexed requester, + address indexed exAggregator, + uint256 reportersFee, + uint256 publishFee + ); event Fulfilled(uint256 indexed requestId, ResponseData response, RequestStatus indexed status); event RewardsWithdrawn(address indexed withdrawer, uint256 amount); event AggregatorConfigSet( - address indexed exAggregator, - uint256 reportersFee, - uint256 publishFee, - string aggregator, - address rewardAddress + address indexed exAggregator, uint256 reportersFee, uint256 publishFee, string aggregator, address rewardAddress ); event AggregatorSuspended(address indexed exAggregator, string indexed aggregator); diff --git a/xapi/ignition/deployments/chain-11155111/deployed_addresses.json b/xapi/ignition/deployments/chain-11155111/deployed_addresses.json index 89804ab..80ed1f8 100644 --- a/xapi/ignition/deployments/chain-11155111/deployed_addresses.json +++ b/xapi/ignition/deployments/chain-11155111/deployed_addresses.json @@ -1,3 +1,3 @@ { - "XAPIModule#XAPI": "0x6984ebE378F8cb815546Cb68a98807C1fA121A81" + "XAPIModule#XAPI": "0x06e1aCbb0A1d23F57798ca36eb3e20D552AcfC62" } diff --git a/xapi/package.json b/xapi/package.json index 45489e0..8938f86 100644 --- a/xapi/package.json +++ b/xapi/package.json @@ -8,7 +8,7 @@ "clear": "npx hardhat clean", "deploy": "npx hardhat ignition deploy ./ignition/modules/XAPI.deploy.js --network sepolia", "console": "npx hardhat console --network sepolia", - "verify": "npx hardhat verify --network sepolia 0x6984ebE378F8cb815546Cb68a98807C1fA121A81", + "verify": "npx hardhat verify --network sepolia 0x06e1aCbb0A1d23F57798ca36eb3e20D552AcfC62", "test": "npx hardhat test" }, "devDependencies": {