-
Notifications
You must be signed in to change notification settings - Fork 212
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: publish econ stats from AMM #5420
Conversation
const getPool = brand => secondaryBrandToPool.get(brand).pool; | ||
const getPoolHelper = brand => secondaryBrandToPool.get(brand).helper; | ||
const initPool = secondaryBrandToPool.init; | ||
const isSecondary = secondaryBrandToPool.has; | ||
|
||
const quoteIssuerKit = makeIssuerKit('Quote', AssetKind.SET); | ||
|
||
const { publication: metricsPublication, subscription: metricsSubscription } = |
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.
please type this so there is API documentation on what comes out of getMetrics
.
e.g. define a type up top,
/**
* @typedef {object} MetricsNotification
* @property {Brand[]} XYK brands
*/
then here would be,
const { publication: metricsPublication, subscription: metricsSubscription } = | |
/** @type {SubscriptonKit<MetricsNotification> */ | |
const { publication: metricsPublication, subscription: metricsSubscription } = |
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.
done
@@ -177,6 +188,9 @@ const start = async (zcf, privateArgs) => { | |||
}; | |||
}; | |||
|
|||
/** @param {Brand} brand */ | |||
const getPoolMetrics = brand => getPool(brand).getMetrics(); |
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.
consider inlining
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.
done
Central: facets.pool.getCentralAmount(), | ||
Secondary: facets.pool.getSecondaryAmount(), | ||
Liquidity: state.liqTokenSupply, |
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.
extant metrics are camelCase
. Open to changing that but I think we should try to be consistent.
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.
These match the keywords, which are (uniquely) initial cap. I think it's worth supporting that exception, without relaxing camelCase as a general rule.
@@ -295,6 +308,10 @@ export const definePoolKind = ( | |||
const { brand: liquidityBrand, issuer: liquidityIssuer } = | |||
liquidityZcfMint.getIssuerRecord(); | |||
const { notifier, updater } = makeNotifierKit(); | |||
const { |
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.
please type
const { | |
/** @type {SubscriptionKit<MetricsNotification> */ | |
const { |
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.
FYI, that's SubscriptionRecord<>
. Took me a bit to find it.
return 'Added liquidity.'; | ||
}, | ||
updateMetrics: ({ state, facets }) => { |
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.
updateMetrics: ({ state, facets }) => { | |
/** @param {MethodContext} context */ | |
updateMetrics: ({ state, facets }) => { |
this would reveal that metricsPublication
and metricsSubscription
need to be added to the ImmutableState
type.
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.
done
@@ -68,6 +68,7 @@ | |||
* @property {() => PriceAuthority} getToCentralPriceAuthority | |||
* @property {() => PriceAuthority} getFromCentralPriceAuthority | |||
* @property {() => VirtualPool} getVPool | |||
* @property {() => Subscription<unknown>} getMetrics |
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.
all the unknown
in this file are well known. please include the type
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.
Now they are.
const metricsNotifier = makeNotifierFromAsyncIterable(metricsSub); | ||
|
||
const state0 = await E(metricsNotifier).getUpdateSince(); | ||
t.deepEqual(state0.value, { XYK: [] }); |
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 test will be easier to follow using this helper,
const metricsNotifier = makeNotifierFromAsyncIterable(metricsSub); | |
const state0 = await E(metricsNotifier).getUpdateSince(); | |
t.deepEqual(state0.value, { XYK: [] }); | |
const m = await subscriptionTracker(t, metricsSub); | |
m.assertInitial({ XYK: [] }); |
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.
done
const state1 = await E(metricsNotifier).getUpdateSince(state0.updateCount); | ||
t.deepEqual(state1.value, { XYK: [moolaR.brand] }); |
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.
and this would be,
const state1 = await E(metricsNotifier).getUpdateSince(state0.updateCount); | |
t.deepEqual(state1.value, { XYK: [moolaR.brand] }); | |
m.assertChange({ XYK: {"1": moolaR.brand } }); |
"1" to indicate that only the 1-index of the array changed
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.
done
2daaa7b
to
ed73c57
Compare
* @typedef {{ | ||
* Central: Amount, | ||
* Secondary: Amount, | ||
* Liquidity: bigint, | ||
* }} PoolMetricsNotification |
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.
per our call,
* @typedef {{ | |
* Central: Amount, | |
* Secondary: Amount, | |
* Liquidity: bigint, | |
* }} PoolMetricsNotification | |
* @typedef {object} PoolMetricsNotification | |
* @property {Amount} centralAmount | |
* @property {Amount} secondaryAmount | |
* @property {NatValue} liquidityTokens - outstanding tokens |
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.
done
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.
Approving contingent on the planned changes
closes: #4648 add notifier and subscription to state
7b04a60
to
66a6fc3
Compare
closes: #4648
Description
Publish econ stats from the AMM
Security Considerations
Not a security issue
Documentation Considerations
Nothing new
Testing Considerations
Tested that updates are emitted for new pools and for changes due to trading and liquidity changes.