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: stargate integration #374

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

feat: stargate integration #374

wants to merge 22 commits into from

Conversation

kuchmenko
Copy link

@kuchmenko kuchmenko commented Jan 14, 2025

@kuchmenko kuchmenko linked an issue Jan 14, 2025 that may be closed by this pull request
gemstone/src/swapper/stargate/pool.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/asset.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/endpoint.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/pool.rs Outdated Show resolved Hide resolved
core Outdated Show resolved Hide resolved
crates/gem_evm/src/stargate/contract.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@0xh3rman 0xh3rman left a comment

Choose a reason for hiding this comment

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

good work in general, left some comments, stargate supports solana, better to think how to support it now

gemstone/src/swapper/asset.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/models.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/endpoint.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Show resolved Hide resolved
gemstone/src/swapper/stargate/provider.rs Outdated Show resolved Hide resolved
@kuchmenko kuchmenko marked this pull request as ready for review January 16, 2025 15:23
Untitled Outdated Show resolved Hide resolved
async fn fetch_quote_data(&self, quote: &SwapQuote, _provider: Arc<dyn AlienProvider>, _data: FetchQuoteData) -> Result<SwapQuoteData, SwapperError> {
let pool = self.client.get_pool_by_asset_id(&quote.request.from_asset)?;
let route_data: StargateRouteData = serde_json::from_str(&quote.data.routes.first().unwrap().route_data).map_err(|_| SwapperError::InvalidRoute)?;
let send_calldata = self.client.send(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let send_calldata = self.client.send(
let calldata = self.client.send(

Copy link
Author

Choose a reason for hiding this comment

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

done

&Address::from_str(route_data.refund_address.as_str()).unwrap(),
);

let mut value_to_send = route_data.fee.nativeFee;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend using:

let fee = if quote.request.from_asset.is_native() { route_data.fee.nativeFee } else { 0 }
let value = route_data.send_param.amountLD + fee

Copy link
Contributor

Choose a reason for hiding this comment

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

Always try to avoid using mut

Copy link
Author

Choose a reason for hiding this comment

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

done

}

let pool = self.client.get_pool_by_asset_id(&request.from_asset)?;
let mut send_param = self.client.build_send_param(request)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid using mut? create function that would calculate all the data for you instead and return a struct

Copy link
Author

Choose a reason for hiding this comment

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

Here we have 2 steps:
Build initial send params and request oft quote
Update initial send params and request send quote

I improved code style based on comment

let from_asset = &request.from_asset;
let to_asset = &request.to_asset;

if from_asset.chain == to_asset.chain {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need check chains, we have function on the higher level to check for this

Copy link
Author

Choose a reason for hiding this comment

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

Removed

gemstone/src/swapper/stargate/layer_zero/scan.rs Outdated Show resolved Hide resolved
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.

Integrate LayerZero / Stargate protocol
4 participants