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: add curve support in pricing module #514

Closed
wants to merge 0 commits into from

Conversation

1010adigupta
Copy link
Contributor

@1010adigupta 1010adigupta commented Mar 18, 2024

closes #501
This pr adds support for curve protocol in pricing-module

Overview:

Curve consists of a variety of pools such as base-pools, liquidity-pools, meta-pools, plain-pools, tri-crypto pools etc. But at a higher level, all these pools can be classified into two broad groups based on the underlying AMM model used for pool balancing basically into two types that are Stable-Swap pools which use the stable-swap invariant model, and Crypto-Swap pools which use the crypto-swap invariant model.

General-Solution:

  1. To generalize the code for various pools to a maximum extent I have divided price calculation in two different parts:
  • Stable-Swap pools

  • base pools

  • meta pools

  • plain pools

  • other underlying pools

  • Crypto-Swap pools

  • underlying pools

  1. I have successfully constructed pool-state initializers and added code to update the state from underlying logs for both pools.
  2. contract used to retrieve data for crypto pool: crypto_pool_data_batch_request.sol, and a simmilar contract was used for stable_pool as well

@1010adigupta 1010adigupta changed the title Add curve support in pricing module feat: add curve support in pricing module Mar 18, 2024
@1010adigupta 1010adigupta self-assigned this Mar 18, 2024
@1010adigupta
Copy link
Contributor Author

cli failing for some other reasons

@Will-Smith11
Copy link
Collaborator

cli failing for some other reasons

yeah the user for the server got nuked, needs to be re-created

Copy link
Collaborator

@Will-Smith11 Will-Smith11 left a comment

Choose a reason for hiding this comment

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

I didn't bother checking the math, The changes you made though will require db changes on our end, should be no problem though. The tests won't pass but the build, fmt and clippy should.

@1010adigupta 1010adigupta marked this pull request as draft March 20, 2024 07:00
@1010adigupta 1010adigupta force-pushed the add-curve-support-in-pricing-module branch from 5d5a6e7 to 7855a3f Compare March 27, 2024 10:28
@1010adigupta 1010adigupta marked this pull request as ready for review March 29, 2024 11:28
@1010adigupta
Copy link
Contributor Author

just slot address and bytecode locations of variables used are need to be added

@1010adigupta
Copy link
Contributor Author

trait definitions for calculate_price fn will have to be changed to use quote_token along with base_token, since till now all pools consisted only of two assets, but curve pool can contain up to 4 assets per pool

// contract immutable variables
pub price_scale_packed: U256,
pub future_a_gamma_time: U256,
//update this on executions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

few pools in which future_a_gamma_time is specified, d_value needs to be updated due to ramping, on every swap function, will add this code to cover these types of pools as well

fee: U256::ZERO,
admin_fee: U256::ZERO,
a_value: U256::ZERO,
rates: RATES.to_vec(),
Copy link
Contributor Author

@1010adigupta 1010adigupta Mar 29, 2024

Choose a reason for hiding this comment

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

majority of pools use these base rates(RATES) only, which are set during contract deployment, and then updated subsequently on various actions, but some TriCrypto use different base rates or do not use them at all(a different rate calculation method), will add code to incorporate those few pools.

);

// Positions of crypto pool immutables in the bytecode
const PRICE_SCALE_PACKED_RANGE: std::ops::Range<usize> = "";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these will be set now

) -> Result<(), AmmError> {

// Pool Storage Slots
let d_value_slot: FixedBytes<32> = FixedBytes::new([""]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add support for curve in pricing module.
3 participants