Skip to content
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: permissionless AMM pools from Interchain assets #5397

Merged
merged 6 commits into from
May 23, 2022
Merged

Conversation

dckc
Copy link
Member

@dckc dckc commented May 19, 2022

refs: #5075, #4643

Description

Given sufficient IST, create an issuer for an IBC denom and an invitation to add a pool for it to the AMM.

There are 2 steps:

  1. offer IST (Central) and provide a denom in the offer args; get back the issuer for that denom in the VBANK
  2. offer the new asset (Secondary) and get back liquidity.

Un-ties knots discussed in #4643 (comment) , #5075 (comment)

TODO:

Security Considerations

Does not provide offer safety, due to usual propoerties of offerTo.

Requires bankManager as a private arg.

Documentation Considerations

Yet Another Contract to document / review.
cc @jessysaurusrex

Testing Considerations

Lightly tested. Reviewers will please suggest further tests.

@dckc dckc requested a review from turadg as a code owner May 19, 2022 04:49
@turadg turadg removed their request for review May 19, 2022 12:56
);
kwNonce += 1;

const liquidityIssuer = await E(amm).addPool(
Copy link
Member Author

Choose a reason for hiding this comment

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

@Chris-Hibbert the addPool call would move to step 2 when we require funds (#5377). I can't move it yet because the AMM requires the liquidity brand in the want when adding liquidity, even though it doesn't use it.

Maybe I should fix that in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Chris-Hibbert the addPool call would move to step 2 when we require funds (#5377). I can't move it yet because the AMM requires the liquidity brand in the want when adding liquidity, even though it doesn't use it.

Maybe I should fix that in this PR?

Before and after #5377 the APIs for adding a pool are just different. Our choices are to reconcile in whichever PR is second, or merge this into #5377 once approved.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did fix the odd AMM constraint and move addPool to step 2. That way, when #5377 lands, we'll have the collateral on hand when we want to addPool.

* }} pa
*
* @typedef {{
* minimumCentral: Amount<'nat'>,
Copy link
Contributor

Choose a reason for hiding this comment

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

If this should eventually be governed, let's at least add a comment to that effect here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a TODO to get this value dynamically from the AMM (once #5377 lands)

Comment on lines +106 to +108
return deposited.then(_ => {
seat.exit();
seat2.exit();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be a .catch() clause here that returns the money from seat2 to seat1 and exits the seat.

I would test it by setting the AMM's minimum higher than the minimum enforced here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I plan to get the AMM's minimum on demand, so that test wouldn't last.

What is it that could throw? seat.exit() or deposited? In either case, what difference does it make which seat the money is returned in?

Copy link
Contributor

Choose a reason for hiding this comment

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

what difference does it make which seat the money is returned in?

I thought seat2 was purely internal, but I now see that I was wrong.

It still seems surprising that the caller has to check both seats to see if there's money there.

If someone has already saved an issuer on the AMM and called it 'Interchain5', then the saveIssuer() call will fail, and the allocation will be stuck on seat2.

Copy link
Member Author

Choose a reason for hiding this comment

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

It still seems surprising that the caller has to check both seats to see if there's money there.

In discussion with @dtribble and co., we didn't see an obvious improvement. (There are 2 offers, so having 2 seats to check on failure never seemed odd, to me.)

If someone has already saved an issuer on the AMM and called it 'Interchain5', then the saveIssuer() call will fail

The saveIssuer() call here doesn't depend on issuers in the AMM, as we discussed. (There could be a collision at addPool, but that's before the saveIssuer() here.)

@dckc dckc marked this pull request as draft May 20, 2022 16:18
@dckc dckc force-pushed the dc-ibc-pool branch 6 times, most recently from 8b3791b to 2088c49 Compare May 20, 2022 22:13
@dckc dckc requested a review from Chris-Hibbert May 20, 2022 22:22
@dckc dckc removed the request for review from michaelfig May 20, 2022 22:27
@dckc
Copy link
Member Author

dckc commented May 20, 2022

@Chris-Hibbert @turadg I wired up everything to get test-gov-collateral.js and such working. Please take a look.

@dckc dckc marked this pull request as ready for review May 20, 2022 22:29
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

Nothing stands out to me as a concern but given the security risks and my understanding of the interchain I don't feel comfortable approving and leave that to @Chris-Hibbert .

});
};

const keyword = denom; // ISSUE: should not show up in all wallets.
Copy link
Member

Choose a reason for hiding this comment

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

what does ISSUE mean? something to do or just know about?

Copy link
Member Author

Choose a reason for hiding this comment

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

what does ISSUE mean?

um... something to do, I suppose.

In this case, it originated from discussion with @dtribble , who was OK postponing it; I didn't turn it into a separate issue, #5412 , until I got a chance to run it by @michaelfig , where we decided it's feasible in due course. Now that I have a number for it, I can add it to that comment.

receive: () => {},
}),
});
// @ts-ignore mock doesn't have all the methods
Copy link
Member

Choose a reason for hiding this comment

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

@ts-expect-error

(not worth a push bc I plan to lint this soon)

Comment on lines +106 to +108
return deposited.then(_ => {
seat.exit();
seat2.exit();
Copy link
Contributor

Choose a reason for hiding this comment

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

what difference does it make which seat the money is returned in?

I thought seat2 was purely internal, but I now see that I was wrong.

It still seems surprising that the caller has to check both seats to see if there's money there.

If someone has already saved an issuer on the AMM and called it 'Interchain5', then the saveIssuer() call will fail, and the allocation will be stuck on seat2.

@dckc dckc added the automerge:no-update (expert!) Automatically merge without updates label May 23, 2022
@mergify mergify bot merged commit 3d0d9de into master May 23, 2022
@mergify mergify bot deleted the dc-ibc-pool branch May 23, 2022 19:32
Chris-Hibbert added a commit that referenced this pull request May 24, 2022
update interchainPool tests

switch minInitialPoolLiquidity back to Nat in startupAmm since it has
to be driven from text values in environment variables.
mergify bot added a commit that referenced this pull request May 24, 2022
* feat: make amm.addPool() require minimum collateral

When creating a new pool for the AMM, there will be a minimum amount
of IST. The caller is expected to provide an equivalent value of the
collateral to balance the AMM pool. The liquidity tokens corresponding
to that minimum will be added to the AssetReserve. If the caller adds
more liquidity than the minimum, they get the extra liquidity tokens.

Closes: #4643

This required updating a number of tests to initialize their AMMs with
a minimal amount.

* fix: don't create AMM pools in `addAssetToVault`

* docs: update references to addPool in documentation

* fix: update demoIssuers to use addPoolInvitation.

* refactor: turn minInitialPoolLiquidity into an Amount

* chore: cleanups.  variable names and typescript annotations.

* fix pool helper types

* parameterize VirtualPool type

* pool amounts are nat

* chore: update TODO to include issue #

* test: uncomment a test assertion before pool creation

* refactor: integrate with #5397

update interchainPool tests

switch minInitialPoolLiquidity back to Nat in startupAmm since it has
to be driven from text values in environment variables.

* chore: lint errors (unreferenced names)

Co-authored-by: Turadg Aleahmad <turadg@agoric.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:no-update (expert!) Automatically merge without updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants