-
Notifications
You must be signed in to change notification settings - Fork 13
moved the code for the cefi-defi blogpost #77
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #.env file | ||
| AMBER_DATA_API_SECRET_KEY_n = "<input api key here>" | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
|
|
||
|
|
||
|
|
||
| #swap_amount_eth_to_usdc( eth_amountIn = 2, usdc_reserve = 102819284 , eth_reserve = 27978, fee_tier = 0.003) | ||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| def swap_amount_eth_to_usdc( eth_amountIn, usdc_reserve , eth_reserve , fee_tier = 0.003,): | ||
|
|
||
| eth_amountInWithFee = eth_amountIn * ( 1 - fee_tier) | ||
|
|
||
| numerator = eth_amountInWithFee * usdc_reserve | ||
| denominator = eth_reserve + eth_amountInWithFee | ||
|
|
||
| usdc_amount_out = numerator * 1.00 / denominator | ||
|
|
||
| return usdc_amount_out | ||
|
|
||
|
|
||
| def swap_amount_usdc_to_eth( usdc_amountIn, usdc_reserve , eth_reserve, fee_tier = 0.003): | ||
|
|
||
| usdc_amountInWithFee = usdc_amountIn * ( 1 - fee_tier) | ||
|
|
||
| numerator = usdc_amountInWithFee * eth_reserve | ||
| denominator = usdc_reserve + usdc_amountInWithFee | ||
|
|
||
| eth_amount_out = numerator * 1.00 / denominator | ||
|
|
||
| return eth_amount_out | ||
|
Comment on lines
+6
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two functions Here's an example of a generic function: def get_amount_out(amount_in, reserve_in, reserve_out, fee_tier=0.003):
"""Calculates the output amount for a given input amount based on Uniswap v2 formula."""
amount_in_with_fee = amount_in * (1 - fee_tier)
numerator = amount_in_with_fee * reserve_out
denominator = reserve_in + amount_in_with_fee
return numerator / denominatorYou could then replace the existing functions with this one, or have them call this generic function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 environment variable name
AMBER_DATA_API_SECRET_KEY_nappears to have a typo with the_nsuffix. This is unconventional and could lead to confusion. It's recommended to remove the suffix for clarity and to follow common naming conventions. Note that this change would require updating where this variable is used.