Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

migrate AMM contract from agoric-sdk#37

Draft
dckc wants to merge 3 commits intomainfrom
amm-contract
Draft

migrate AMM contract from agoric-sdk#37
dckc wants to merge 3 commits intomainfrom
amm-contract

Conversation

@dckc
Copy link
Copy Markdown
Member

@dckc dckc commented Mar 1, 2023

This is a copy of the AMM contract extracted from agoric-sdk as of 2023-02-28 70ba9b0ce, just before:

 - [ ] address failing tests
 - [ ] connect the contract to the UI to make it functional.

Many tests not passing

As noted in the README, a number of the tests do not pass; they have dependencies on
agoric-sdk that did not survive the extraction.

full output from yarn test
$ yarn test
yarn run v1.22.4
$ ava

  Uncaught exception in test/test-feeDistributor.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/zoe/test/unitTests/setupBasicMints.js' imported from /home/connolly/projects/dapp-amm/contract/test/test-feeDistributor.js

  Uncaught exception in test/test-voPool.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/swingset-liveslots/tools/vo-test-harness.js' imported from /home/connolly/projects/dapp-amm/contract/test/test-voPool.js

  Uncaught exception in test/test-contractSupport.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/governance/bundles/bundle-binaryVoteCounter.js' imported from /home/connolly/projects/dapp-amm/contract/test/supports.js

  Uncaught exception in test/stakeFactory/test-stakeFactory.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/governance/bundles/bundle-binaryVoteCounter.js' imported from /home/connolly/projects/dapp-amm/contract/test/stakeFactory/test-stakeFactory.js

  Uncaught exception in test/test-interest-labeled.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/time/src/timeMath.js' imported from /home/connolly/projects/dapp-amm/contract/node_modules/@agoric/time/index.js

  ✘ test/test-interest-labeled.js exited with a non-zero exit code: 1

  Uncaught exception in test/test-interest.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/time/src/timeMath.js' imported from /home/connolly/projects/dapp-amm/contract/node_modules/@agoric/time/index.js

  ✘ test/test-interest.js exited with a non-zero exit code: 1
  ✘ test/test-feeDistributor.js exited with a non-zero exit code: 1

  Uncaught exception in test/reserve/test-reserve.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/governance/bundles/bundle-binaryVoteCounter.js' imported from /home/connolly/projects/dapp-amm/contract/test/supports.js

  Uncaught exception in test/test-interchainPool.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/internal/src/lib-chainStorage.js' imported from /home/connolly/projects/dapp-amm/contract/src/proposals/econ-behaviors.js

  Uncaught exception in test/amm/constantProduct/test-estimator.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/governance/bundles/bundle-binaryVoteCounter.js' imported from /home/connolly/projects/dapp-amm/contract/test/supports.js

  ✘ test/stakeFactory/test-stakeFactory.js exited with a non-zero exit code: 1
  ✘ test/amm/constantProduct/test-estimator.js exited with a non-zero exit code: 1
  ✘ test/test-contractSupport.js exited with a non-zero exit code: 1
  ✘ test/test-voPool.js exited with a non-zero exit code: 1
  ✘ test/reserve/test-reserve.js exited with a non-zero exit code: 1
  ✘ test/test-interchainPool.js exited with a non-zero exit code: 1

  Uncaught exception in test/amm/constantProduct/test-checkInvariants.js

  file:///home/connolly/projects/dapp-amm/contract/src/vpool-xyk-amm/constantProduct/invariants.js:1
  import { Fail } from '@agoric/assert';
           ^^^^
  SyntaxError: The requested module '@agoric/assert' does not provide an export named 'Fail'

  ✘ test/amm/constantProduct/test-checkInvariants.js exited with a non-zero exit code: 1

  Uncaught exception in test/test-demoAMM.js

  file:///home/connolly/projects/dapp-amm/contract/src/proposals/demoIssuers.js:3
  import { allValues, objectMap } from '@agoric/internal';
           ^^^^^^^^^
  SyntaxError: The requested module '@agoric/internal' does not provide an export named 'allValues'

  Uncaught exception in test/amm/constantProduct/test-compareBondingCurves.js

  file:///home/connolly/projects/dapp-amm/contract/src/vpool-xyk-amm/constantProduct/invariants.js:1
  import { Fail } from '@agoric/assert';
           ^^^^
  SyntaxError: The requested module '@agoric/assert' does not provide an export named 'Fail'

  ✘ test/test-demoAMM.js exited with a non-zero exit code: 1
  ✘ test/amm/constantProduct/test-compareBondingCurves.js exited with a non-zero exit code: 1

  Uncaught exception in test/amm/vpool-xyk-amm/test-xyk-amm-swap.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/zoe/test/autoswapJig.js' imported from /home/connolly/projects/dapp-amm/contract/test/amm/vpool-xyk-amm/test-xyk-amm-swap.js

  ✔ interest-math › no debt wo/compounding
  ✔ interest-math › no debt w/ compounding
  ✔ interest-math › some debt wo/compounding
  ✔ interest-math › some debt w/ compounding
  ✔ interest-math › previous interest wo/compounding
  ✔ interest-math › previous interest w/ compounding
  ✔ interest-math › previous interest, compounded down
  ✔ interest-math › none
  ✔ interest-math › none w/interest
  ✔ interest-math › some
  ✔ interest-math › some w/interest
  ✔ interest-math › some w/100% interest
  ✘ test/amm/vpool-xyk-amm/test-xyk-amm-swap.js exited with a non-zero exit code: 1

  Uncaught exception in test/amm/vpool-xyk-amm/test-liquidity.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/zoe/test/unitTests/setupBasicMints.js' imported from /home/connolly/projects/dapp-amm/contract/test/amm/vpool-xyk-amm/test-liquidity.js

  Uncaught exception in test/amm/vpool-xyk-amm/test-amm-governance.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/internal/src/lib-chainStorage.js' imported from /home/connolly/projects/dapp-amm/contract/src/proposals/startEconCommittee.js

  Uncaught exception in test/swingsetTests/governance/test-governance.js

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/connolly/projects/dapp-amm/contract/node_modules/@agoric/governance/bundles/bundle-binaryVoteCounter.js' imported from /home/connolly/projects/dapp-amm/contract/test/swingsetTests/governance/test-governance.js

  ✘ test/amm/vpool-xyk-amm/test-liquidity.js exited with a non-zero exit code: 1
  ✘ test/amm/vpool-xyk-amm/test-amm-governance.js exited with a non-zero exit code: 1
  ✘ test/swingsetTests/governance/test-governance.js exited with a non-zero exit code: 1
  ✔ amm › constantProduct › getXY › swap Central for Secondary
  ✔ amm › constantProduct › getXY › swap Central for Secondary no Give
  ✔ amm › constantProduct › getXY › swap Central for Secondary no want
  ✔ amm › constantProduct › getXY › swap Secondary for Central
  ✔ amm › constantProduct › getXY › swap Secondary for Central no want
  ✔ amm › constantProduct › getXY › swap Secondary for Central no give
  ✘ [fail]: amm › constantProduct › calcDeltaY › 0, 0, 0, 0
  ✔ amm › constantProduct › calcDeltaY › 0, 0, 1, 0 (112ms)
  ✔ amm › constantProduct › calcDeltaY › 1, 0, 0, 0
  ✘ [fail]: amm › constantProduct › calcDeltaY › 0, 1, 0, 0
  ✔ amm › constantProduct › calcDeltaY › 1, 1, 0, 0
  ✔ amm › constantProduct › calcDeltaY › 1, 1, 1, 0
  ✔ amm › constantProduct › calcDeltaY › 1, 2, 1, 1
  ✔ amm › constantProduct › calcDeltaY › 2, 3, 4, 2
  ✔ amm › constantProduct › calcDeltaY › 928861206, 130870247, 746353662, 58306244
  ✔ amm › constantProduct › calcDeltaY › 9, 3, 17, 1
  ✔ amm › constantProduct › calcDeltaY › 10000, 5000, 209, 102
  ✔ amm › constantProduct › calcDeltaY › 1000000, 5000, 209, 1
  ✔ amm › constantProduct › calcDeltaY › 5000, 1000000, 209, 40122

  Uncaught exception in test/amm/constantProduct/test-readmeScenario.js

  file:///home/connolly/projects/dapp-amm/contract/src/vpool-xyk-amm/constantProduct/invariants.js:1
  import { Fail } from '@agoric/assert';
           ^^^^
  SyntaxError: The requested module '@agoric/assert' does not provide an export named 'Fail'

  Uncaught exception in test/amm/constantProduct/test-swapScenarios.js

  file:///home/connolly/projects/dapp-amm/contract/src/vpool-xyk-amm/constantProduct/invariants.js:1
  import { Fail } from '@agoric/assert';
           ^^^^
  SyntaxError: The requested module '@agoric/assert' does not provide an export named 'Fail'

  ✘ test/amm/constantProduct/test-readmeScenario.js exited with a non-zero exit code: 1
  ✘ test/amm/constantProduct/test-swapScenarios.js exited with a non-zero exit code: 1
  ✘ [fail]: amm › constantProduct › calcDeltaX › 0, 0, 0, 0
  ✔ amm › constantProduct › calcDeltaX › 0, 0, 1, 0 (112ms)
  ✘ [fail]: amm › constantProduct › calcDeltaX › 1, 0, 0, 0
  ✔ amm › constantProduct › calcDeltaX › 0, 1, 0, 0
  ✔ amm › constantProduct › calcDeltaX › 1, 1, 0, 0
  ✘ [fail]: amm › constantProduct › calcDeltaX › 1, 1, 1, 0
  ✔ amm › constantProduct › calcDeltaX › 1, 2, 1, 1
  ✔ amm › constantProduct › calcDeltaX › 2, 3, 1, 1
  ✔ amm › constantProduct › calcDeltaX › 928861206, 130870247, 746353662, 158115257
  ✔ amm › constantProduct › calcDeltaX › 9, 17, 3, 2
  ✔ amm › constantProduct › calcDeltaX › 10000, 5000, 209, 437
  ✔ amm › constantProduct › calcDeltaX › 1000000, 5000, 209, 1
  ✔ amm › constantProduct › calcDeltaX › 5000, 1000000, 209, 2
  ✔ amm › constantProduct › calcDeltaX › 500_000, 1000_000, 209 or 210
  ✔ amm › vpool-xyk-amm › amm-calc › balancesToReachRatio calculations are to spec
  ✔ amm › vpool-xyk-amm › addLiquidity › calcBalances
  ✔ amm › vpool-xyk-amm › addLiquidity › calcBalances 2
  ✔ amm › vpool-xyk-amm › addLiquidity › calcBalances out of balance
  ─

  amm › constantProduct › calcDeltaY › 0, 0, 0, 0

  test/amm/constantProduct/test-calcDeltaY.js:19

   18: test('0, 0, 0, 0', t => {                                                   
   19:   t.throws(() => doTest(t, 0n, 0n, 0n, 0n), {                               
   20:     message: 'No infinite ratios! Denominator was 0 "[Alleged: RUN brand]"',

  Function threw unexpected exception:

  Error {
    message: 'No infinite ratios! Denominator was 0/"[Alleged: RUN brand]"',
  }

  Expected message to equal:

  'No infinite ratios! Denominator was 0 "[Alleged: RUN brand]"'

  › calcDeltaYSellingX (file://src/vpool-xyk-amm/constantProduct/core.js:67:18)
  › doTest (file://test/amm/constantProduct/test-calcDeltaY.js:10:18)
  › t.throws.message (file://test/amm/constantProduct/test-calcDeltaY.js:19:18)
  › file://test/amm/constantProduct/test-calcDeltaY.js:19:5



  amm › constantProduct › calcDeltaY › 0, 1, 0, 0

  test/amm/constantProduct/test-calcDeltaY.js:34

   33: test('0, 1, 0, 0', t => {                                                   
   34:   t.throws(() => doTest(t, 0n, 1n, 0n, 0n), {                               
   35:     message: 'No infinite ratios! Denominator was 0 "[Alleged: RUN brand]"',

  Function threw unexpected exception:

  Error {
    message: 'No infinite ratios! Denominator was 0/"[Alleged: RUN brand]"',
  }

  Expected message to equal:

  'No infinite ratios! Denominator was 0 "[Alleged: RUN brand]"'

  › calcDeltaYSellingX (file://src/vpool-xyk-amm/constantProduct/core.js:67:18)
  › doTest (file://test/amm/constantProduct/test-calcDeltaY.js:10:18)
  › t.throws.message (file://test/amm/constantProduct/test-calcDeltaY.js:34:18)
  › file://test/amm/constantProduct/test-calcDeltaY.js:34:5



  amm › constantProduct › calcDeltaX › 0, 0, 0, 0

  test/amm/constantProduct/test-calcDeltaX.js:18

   17: test('0, 0, 0, 0', t => {                                                   
   18:   t.throws(() => doTest(t, 0n, 0n, 0n, 0n), {                               
   19:     message: 'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"',

  Function threw unexpected exception:

  Error {
    message: 'No infinite ratios! Denominator was 0/"[Alleged: BLD brand]"',
  }

  Expected message to equal:

  'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"'

  › calcDeltaXSellingX (file://src/vpool-xyk-amm/constantProduct/core.js:89:18)
  › doTest (file://test/amm/constantProduct/test-calcDeltaX.js:10:18)
  › t.throws.message (file://test/amm/constantProduct/test-calcDeltaX.js:18:18)
  › file://test/amm/constantProduct/test-calcDeltaX.js:18:5



  amm › constantProduct › calcDeltaX › 1, 0, 0, 0

  test/amm/constantProduct/test-calcDeltaX.js:30

   29: test('1, 0, 0, 0', t => {                                                   
   30:   t.throws(() => doTest(t, 1n, 0n, 0n, 0n), {                               
   31:     message: 'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"',

  Function threw unexpected exception:

  Error {
    message: 'No infinite ratios! Denominator was 0/"[Alleged: BLD brand]"',
  }

  Expected message to equal:

  'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"'

  › calcDeltaXSellingX (file://src/vpool-xyk-amm/constantProduct/core.js:89:18)
  › doTest (file://test/amm/constantProduct/test-calcDeltaX.js:10:18)
  › t.throws.message (file://test/amm/constantProduct/test-calcDeltaX.js:30:18)
  › file://test/amm/constantProduct/test-calcDeltaX.js:30:5



  amm › constantProduct › calcDeltaX › 1, 1, 1, 0

  test/amm/constantProduct/test-calcDeltaX.js:44

   43: test('1, 1, 1, 0', t => {                                                   
   44:   t.throws(() => doTest(t, 1n, 1n, 1n, 0n), {                               
   45:     message: 'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"',

  Function threw unexpected exception:

  Error {
    message: 'No infinite ratios! Denominator was 0/"[Alleged: BLD brand]"',
  }

  Expected message to equal:

  'No infinite ratios! Denominator was 0 "[Alleged: BLD brand]"'

  › calcDeltaXSellingX (file://src/vpool-xyk-amm/constantProduct/core.js:89:18)
  › doTest (file://test/amm/constantProduct/test-calcDeltaX.js:10:18)
  › t.throws.message (file://test/amm/constantProduct/test-calcDeltaX.js:44:18)
  › file://test/amm/constantProduct/test-calcDeltaX.js:44:5

  ─

  5 tests failed
  18 uncaught exceptions

dckc added 3 commits March 1, 2023 09:38
copied from packages/inter-protocol 2023-02-28 70ba9b0ce

choice of which files to include is somewhat arbitrary

a few tests were passing while selecting files; none pass at this
point
Copy link
Copy Markdown
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to .skip the failing tests? Does this repo have different rules about test robustness?

I looked, and didn't detect anything missing. Everything I'd want to preserve is here.

@samsiegart
Copy link
Copy Markdown
Contributor

Is this functional in any way, or are we just dumping code here to archive it? It seems like this will make this repo difficult to maintain, and confusing to new eyes as to the purpose of this code. May I suggest we just make a tag in agoric-sdk to the latest version with this code so we can go back and find it?

@samsiegart
Copy link
Copy Markdown
Contributor

Alternatively, I would feel better keeping this in its own branch and not merging into main

@dckc
Copy link
Copy Markdown
Member Author

dckc commented Mar 1, 2023

Is this functional in any way, or are we just dumping code here to archive it?

The proposal here is/was to kinda just dump the code. I'm persuaded that it's not cost-effective. I'll mark it draft and add TODOs about addressing failing tests and making it functional.

@dckc dckc marked this pull request as draft March 1, 2023 19:05
@dckc dckc changed the title "as-is" copy of AMM contract from agoric-sdk migrate AMM contract from agoric-sdk Mar 1, 2023
@turadg turadg removed their request for review March 31, 2023 21:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants