-
Notifications
You must be signed in to change notification settings - Fork 95
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(LRAPI): add 1inch classic swap rpc #2222
base: dev
Are you sure you want to change the base?
Conversation
} | ||
|
||
/// "1inch_classic_swap_create" rpc impl | ||
pub async fn one_inch_v6_0_classic_swap_create_rpc( |
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.
Note, that this rpc actually creates a transaction to call the swap aggregation contract. It is supposed that the GUI should sign it and send. We don't verify the tx in any way and trust the 1inch api.
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.
Then lest add this clarification to doc comment
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.
done
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.
Great start! Here is the 1st review iteration
pub struct ClassicSwapQuoteRequest { | ||
pub base: String, | ||
pub rel: String, | ||
pub amount: BigDecimal, |
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.
What do you think about using the U256
type for the "amount" from the beginning? We don’t have a 1inch coin, in wallet or our own trading protocol features, so we are free to use coin-specific types for external third-party trading
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.
I used BigDecimal to make it like most our other rpcs do (for e.g. withdraw).
But now I see I probably should use MmNumber as those classic swap rpcs are close to our "buy" and "sell" methods
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.
I made the swap amount as MmNumber (like in our own swap rpcs). I hope this is consistent
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.
I made the swap amount as MmNumber (like in our own swap rpcs). I hope this is consistent
Hmm, I think yes. We use MmNumber
type for atomic swaps and, as 1inch is a trading aggregator, then we can do the same for it.
I will leave comment as unresolved, so other people can find this.
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.
Thanks :)
First review iteration.
pub fn with_fee(mut self, fee: Option<f32>) -> Self { | ||
self.fee = fee; | ||
self | ||
} | ||
pub fn with_protocols(mut self, protocols: Option<String>) -> Self { | ||
self.protocols = protocols; | ||
self | ||
} | ||
pub fn with_gas_price(mut self, gas_price: Option<String>) -> Self { | ||
self.gas_price = gas_price; | ||
self | ||
} | ||
pub fn with_complexity_level(mut self, complexity_level: Option<u32>) -> Self { | ||
self.complexity_level = complexity_level; | ||
self | ||
} | ||
pub fn with_parts(mut self, parts: Option<u32>) -> Self { | ||
self.parts = parts; | ||
self | ||
} | ||
pub fn with_main_route_parts(mut self, main_route_parts: Option<u32>) -> Self { | ||
self.main_route_parts = main_route_parts; | ||
self | ||
} | ||
pub fn with_gas_limit(mut self, gas_limit: Option<u128>) -> Self { | ||
self.gas_limit = gas_limit; | ||
self | ||
} | ||
pub fn with_include_tokens_info(mut self, include_tokens_info: Option<bool>) -> Self { | ||
self.include_tokens_info = include_tokens_info; | ||
self | ||
} | ||
pub fn with_include_protocols(mut self, include_protocols: Option<bool>) -> Self { | ||
self.include_protocols = include_protocols; | ||
self | ||
} | ||
pub fn with_include_gas(mut self, include_gas: Option<bool>) -> Self { | ||
self.include_gas = include_gas; | ||
self | ||
} | ||
pub fn with_connector_tokens(mut self, connector_tokens: Option<String>) -> Self { | ||
self.connector_tokens = connector_tokens; | ||
self | ||
} |
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.
I am not a fan of this pattern personally, but if we really want to do this I guess the best way would be creating macro which implements this pattern automatically without taking too much space in the module.
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.
I am not a fan of this pattern personally, but if we really want to do this I guess the best way would be creating macro which implements this pattern automatically without taking too much space in the module.
really like this idea
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.
made a macro, great idea, ty
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.
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.
great work! couple notes for first review
@@ -866,6 +852,8 @@ impl EthCoinImpl { | |||
let guard = self.erc20_tokens_infos.lock().unwrap(); | |||
(*guard).clone() | |||
} | |||
|
|||
pub fn chain_id(&self) -> u64 { self.chain_id } |
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.
pub fn chain_id(&self) -> u64 { self.chain_id } | |
#[inline(always)] | |
pub fn chain_id(&self) -> u64 { self.chain_id } |
/// Get chain id | ||
pub(crate) async fn chain_id(&self) -> Result<U256, web3::Error> { | ||
pub(crate) async fn network_chain_id(&self) -> Result<U256, web3::Error> { |
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.
nit: I guess we should either remove the doc-comment (as function name is already clear) or update it with "Get network chain id".
#[display(fmt = "No such coin {}", coin)] | ||
NoSuchCoin { coin: String }, | ||
#[display(fmt = "Coin not supported {}", coin)] | ||
CoinNotSupported { coin: String }, | ||
#[from_stringify("NumConversError")] | ||
#[display(fmt = "Invalid param: {}", _0)] | ||
InvalidParam(String), |
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.
nit: I would use the same pattern from NoSuchCoin
and CoinNotSupported
for InvalidParam
(e.g., InvalidParam { param: String }
) to make it more explicit. Right now it's not clear what this error takes as a String
value.
/// Call allowance for ERC20 tokens | ||
/// Returns BigDecimal value |
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.
/// Call allowance for ERC20 tokens | |
/// Returns BigDecimal value | |
/// Call allowance for ERC20 tokens. | |
/// Returns BigDecimal value. |
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.
Can we add a ref link (like this) for "allowance" and "approve"?
/// Call approve for ERC20 coins | ||
/// Returns signed transaction to send to the chain |
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.
/// Call approve for ERC20 coins | |
/// Returns signed transaction to send to the chain | |
/// Call approve for ERC20 coins. | |
/// Returns signed transaction to send to the chain. |
let coin = lp_coinfind_or_err(&ctx, &req.coin) | ||
.await | ||
.mm_err(|_| Erc20CallError::NoSuchCoin { coin: req.coin.clone() })?; | ||
match coin { | ||
MmCoinEnum::EthCoin(eth_coin) => { | ||
let wei = eth_coin.allowance(req.spender).compat().await?; | ||
let amount = u256_to_big_decimal(wei, eth_coin.decimals())?; | ||
Ok(amount) | ||
}, | ||
_ => Err(MmError::new(Erc20CallError::CoinNotSupported { coin: req.coin })), | ||
} |
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.
let coin = lp_coinfind_or_err(&ctx, &req.coin) | |
.await | |
.mm_err(|_| Erc20CallError::NoSuchCoin { coin: req.coin.clone() })?; | |
match coin { | |
MmCoinEnum::EthCoin(eth_coin) => { | |
let wei = eth_coin.allowance(req.spender).compat().await?; | |
let amount = u256_to_big_decimal(wei, eth_coin.decimals())?; | |
Ok(amount) | |
}, | |
_ => Err(MmError::new(Erc20CallError::CoinNotSupported { coin: req.coin })), | |
} | |
match lp_coinfind_or_err(&ctx, &req.coin).await { | |
Ok(MmCoinEnum::EthCoin(eth_coin)) => { | |
let wei = eth_coin.allowance(req.spender).compat().await?; | |
let amount = u256_to_big_decimal(wei, eth_coin.decimals())?; | |
Ok(amount) | |
}, | |
Ok(_) => Err(MmError::new(Erc20CallError::CoinNotSupported { coin: req.coin })), | |
Err(_) => Err(MmError::new(Erc20CallError::NoSuchCoin { coin: req.coin.clone() })), | |
} |
let coin = lp_coinfind_or_err(&ctx, &req.coin) | ||
.await | ||
.mm_err(|_| Erc20CallError::NoSuchCoin { coin: req.coin.clone() })?; |
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 suggestion above could be applied to here as well.
type Erc20AllowanceResult = MmResult<BigDecimal, Erc20CallError>; | ||
type Erc20ApproveResult = MmResult<BytesJson, Erc20CallError>; |
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.
Actual results are already quite clear, why is this needed?
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.
Thanks!
LGTM :)
This PR adds: