-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6977 from Agoric/6701-ec-removeOracles
6701 EC removeOracles
- Loading branch information
Showing
10 changed files
with
571 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { Fail } from '@agoric/assert'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { defineDurableExoClassKit, M, makeKindHandle } from '@agoric/vat-data'; | ||
|
||
const trace = makeTracer('OrKit', false); | ||
|
||
export const INVITATION_MAKERS_DESC = 'oracle invitation'; | ||
|
||
/** | ||
* @typedef {{ | ||
* oracleId: string, | ||
* roundPowers: { handlePush: (status: OracleStatus, result: import('./roundsManager.js').PriceRound) => Promise<OracleStatus> } | ||
* }} HeldParams | ||
*/ | ||
|
||
/** | ||
* @typedef {{ roundId: number | undefined, unitPrice: NatValue }} PriceDatum | ||
*/ | ||
|
||
/** | ||
* @typedef {object} OracleStatus | ||
* @property {boolean} [disabled] | ||
* @property {bigint} lastReportedRound | ||
* @property {bigint} lastStartedRound | ||
* @property {bigint} latestSubmission | ||
* @property {string} oracleId | ||
*/ | ||
/** | ||
* @typedef {Readonly<HeldParams & { | ||
* }>} ImmutableState | ||
* | ||
* @typedef {OracleStatus & { | ||
* }} MutableState | ||
*/ | ||
/** @typedef {ImmutableState & MutableState} State */ | ||
|
||
const oracleKitKind = makeKindHandle('OracleKit'); | ||
|
||
/** | ||
* @param {HeldParams} heldParams | ||
* @returns {State} | ||
*/ | ||
const initState = ({ oracleId, roundPowers }) => { | ||
return { | ||
oracleId, | ||
roundPowers, | ||
disabled: false, | ||
lastReportedRound: 0n, | ||
lastStartedRound: 0n, | ||
latestSubmission: 0n, | ||
}; | ||
}; | ||
|
||
const AdminI = M.interface('OracleKitAdmin', { | ||
disable: M.call().returns(), | ||
}); | ||
|
||
const OracleI = M.interface('Oracle', { | ||
pushPrice: M.call({ roundId: M.any(), unitPrice: M.bigint() }).returns( | ||
M.promise(), | ||
), | ||
getStatus: M.call().returns(M.record()), | ||
}); | ||
|
||
export const makeOracleAdminKit = defineDurableExoClassKit( | ||
oracleKitKind, | ||
{ admin: AdminI, oracle: OracleI }, | ||
initState, | ||
{ | ||
admin: { | ||
disable() { | ||
trace(`oracle ${this.state.oracleId} disabled`); | ||
this.state.disabled = true; | ||
}, | ||
}, | ||
oracle: { | ||
/** | ||
* push a unitPrice result from this oracle | ||
* | ||
* @param {PriceDatum} datum | ||
*/ | ||
async pushPrice({ | ||
roundId: roundIdRaw = undefined, | ||
unitPrice: valueRaw, | ||
}) { | ||
const { state } = this; | ||
!state.disabled || Fail`pushPrice for disabled oracle`; | ||
const { roundPowers } = state; | ||
const result = await roundPowers.handlePush( | ||
{ | ||
oracleId: state.oracleId, | ||
lastReportedRound: state.lastReportedRound, | ||
lastStartedRound: state.lastStartedRound, | ||
latestSubmission: state.latestSubmission, | ||
}, | ||
{ | ||
roundId: roundIdRaw, | ||
unitPrice: valueRaw, | ||
}, | ||
); | ||
|
||
state.lastReportedRound = result.lastReportedRound; | ||
state.lastStartedRound = result.lastStartedRound; | ||
state.latestSubmission = result.latestSubmission; | ||
}, | ||
/** | ||
* | ||
* @returns {OracleStatus} | ||
*/ | ||
getStatus() { | ||
const { state } = this; | ||
return { | ||
oracleId: state.oracleId, | ||
disabled: state.disabled, | ||
lastReportedRound: state.lastReportedRound, | ||
lastStartedRound: state.lastStartedRound, | ||
latestSubmission: state.latestSubmission, | ||
}; | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
/** @typedef {ReturnType<typeof makeOracleAdminKit>} OracleKit */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.