Published unlisted
Edited
Feb 8, 2022
Importers
Insert cell
Insert cell
Insert cell
Insert cell
## Basic Classes
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
### Principal-Protected
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
### Principle Protected Inner Curve
Insert cell
withPrincipleProtectedInnerCurve = NestedCurve => class extends NestedCurve {
/**
* @constructor
* @param {withPrincipleProtection(BancorCurve)} innerCurve - A principle-protected bonding curve to be used
` * as the inner curve of the nested bonding curve.
*/
constructor({ address, chain, OuterCurveClass, outerCurveConfig, innerCurve, reserveToken }) {
const OuterCurve = OuterCurveClass || withCostBasisReserves(BancorCurve)
const outerCurve = new OuterCurve(outerCurveConfig)

super({ innerCurve, outerCurve, chain, address, reserveToken })
}
}
Insert cell
Insert cell
## Simulate2
A simulator function that accepts arbitrary actions, state, reducers & state logging.
Insert cell
Insert cell
Insert cell
Insert cell
md`# A. Basic Bonding Curve Scenarios`
Insert cell
Insert cell
Insert cell
md`## Scenario 1: Sandwich Attack`
Insert cell
md`### Scenario Setup`
Insert cell
Insert cell
md`### Experiment 1.1: Sandwich Attack w/ Base Bonding Curve`
Insert cell
Insert cell
md`### Experiment 1.2: Sandwich Attack w/ Flat Deposit Tax`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md `## Scenario 2: Apeing in`
Insert cell
md`### Scenario Setup`
Insert cell
Insert cell
Insert cell
Insert cell
## Scenario 3: Bonding Curve Payouts
Insert cell
Insert cell
### Experiment A.3.1: Deposit into Bancor Reserves
Insert cell
scenario_A_3_1_results = {
const { actions, initialReserveTokenBalances, recordState } = scenario_A_3_config
const chain = new Chain({})
const reserveToken = new Token({ initialBalances: initialReserveTokenBalances })
const curve = new BancorCurve({ chain, reserveRatio: (1/2), reserveToken, address: 'bonding_curve'})
const state = {
chain,
reserveToken,
curve,
}

return simulate3({
actions,
state,
recordState,
})
}
Insert cell
Insert cell
Insert cell
### Experiment A.3.3: Principle Protected Curve
Insert cell
Insert cell
# B. Nested Bonding Curve Scenarios
Insert cell
1. Initialize inner curve of nested curve
2. Several Curators mint on nested curve
3. Upgrade nested curve from previous inner curve to new inner curve.
4. Several Curators burn on the nested curve

Analyze profits depending on timing and the shape of the old vs. new inner curve.
Insert cell
Insert cell
Insert cell
Insert cell
## Scenario B.1: Inner Curve Upgrade
Insert cell
### Experiment B.1.1: Basic Inner Curve Upgrade
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
## Scenario B.2 Front-Running Inner Curve Upgrade
Insert cell
### Experiment B.2.1: Front-Running Basic Curve Upgrade
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
## Scenario B.3 Principle Protected Nesting Strategies
Insert cell
scenario_B_3_config = ({
initialReserveTokenBalances: [
['0x0', 0],
['protocol', 5000],
['curator1', 1000],
['curator2', 1000],
],
actions: [
{ type: "MINT", target: 'nestedCurve', args: ['curator1', 1000] },
{ type: "MINT", target: 'nestedCurve', args: ['curator2', 1000] },
(_, { outerShareBalances } ) =>
({ type: "BURN", target: 'nestedCurve', args: ['curator2', outerShareBalances['curator2']] }),
],
recordState: ({ nestedCurve, innerCurve, outerCurve, reserveToken }) => ({
outerShareBalances: Object.fromEntries(nestedCurve.outerCurve.shareToken.balances.entries()),
outerCurvePrice: outerCurve.price,
outerCurvePricePerHundredth: outerCurve.pricePerHundredth,
outerShares: outerCurve.shares,
reserveTokenBalances: Object.fromEntries(reserveToken.balances.entries()),
innerCostBases: Object.fromEntries(nestedCurve.innerCurve.shareToken.costBases.entries()),
innerShareTokenBalances: Object.fromEntries(nestedCurve.innerCurve.shareToken.balances.entries()),
innerShares: innerCurve.shares,
innerCurvePrice: innerCurve.price,
innerCurvePricePerHundredth: innerCurve.pricePerHundredth,
})
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`# Imports`
Insert cell
_ = require('lodash@4.17.20/lodash.js')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more