-
Notifications
You must be signed in to change notification settings - Fork 19
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: mayan integration #322
Open
kuchmenko
wants to merge
21
commits into
gemwalletcom:main
Choose a base branch
from
kuchmenko:feat/mayan-swift-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6a0d51c
feat: added base structure to mayan swift integration
kuchmenko 2d52d3b
Merge branch 'main' into feat/mayan-swift-integration
kuchmenko a9ae31d
feat: use mayan relayer for quota
kuchmenko 9c9cef8
fix: fixed min amount out and destination chain id
kuchmenko 37daadd
feat: swap and forward eth implemented
kuchmenko 1bd5519
feat: added referrer fee integration
kuchmenko 86f130f
Merge branch 'main' into feat/mayan-swift-integration
kuchmenko b0abdfd
feat: fetch erc20 swap quote
kuchmenko a1749d6
feat: erc20 swap using mayan swift
kuchmenko 32d137b
chore: code refactoring
kuchmenko 5251961
Merge branch 'main' into feat/mayan-swift-integration
kuchmenko a312f8e
chore: post merge fix
kuchmenko 389892d
chore: refactored forwarder errros
kuchmenko 004270d
chore: imporved wormhole id
kuchmenko 18be7e2
chore: removed unused defaults
kuchmenko 46dd9bf
chore: cargo formatting
kuchmenko 7f8475a
Merge branch 'main' into feat/mayan-swift-integration
kuchmenko 7ab8096
chore: post merge
kuchmenko c7cc625
Merge branch 'main' into pr/322
gemcoder21 32ca861
Merge branch 'main' into feat/mayan-swift-integration
a882c77
chore: updated to main
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ pub mod erc20; | |
pub mod erc2612; | ||
pub mod jsonrpc; | ||
pub mod lido; | ||
pub mod mayan; | ||
pub mod permit2; | ||
pub mod uniswap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use alloy_core::sol; | ||
|
||
sol! { | ||
/// @title MayanForwarder Interface | ||
#[derive(Debug, PartialEq)] | ||
interface IMayanForwarder { | ||
|
||
/// @notice Forward ETH to Mayan protocol | ||
function forwardEth(address mayanProtocol, bytes calldata protocolData) external payable; | ||
|
||
/// @notice Forward ERC20 tokens to Mayan protocol | ||
function forwardERC20( | ||
address tokenIn, | ||
uint256 amountIn, | ||
PermitParams calldata permitParams, | ||
address mayanProtocol, | ||
bytes calldata protocolData | ||
) external payable; | ||
|
||
/// @notice Swap ETH to token and forward to Mayan protocol | ||
function swapAndForwardEth( | ||
uint256 amountIn, | ||
address swapProtocol, | ||
bytes calldata swapData, | ||
address middleToken, | ||
uint256 minMiddleAmount, | ||
address mayanProtocol, | ||
bytes calldata mayanData | ||
) external payable; | ||
|
||
/// @notice Swap ERC20 token and forward to Mayan protocol | ||
function swapAndForwardERC20( | ||
address tokenIn, | ||
uint256 amountIn, | ||
PermitParams calldata permitParams, | ||
address swapProtocol, | ||
bytes calldata swapData, | ||
address middleToken, | ||
uint256 minMiddleAmount, | ||
address mayanProtocol, | ||
bytes calldata mayanData | ||
) external payable; | ||
|
||
/// Structs | ||
struct PermitParams { | ||
uint256 value; | ||
uint256 deadline; | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod forwarder; | ||
pub mod swift; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,144 @@ | ||||
use std::collections::HashMap; | ||||
|
||||
use primitives::Chain; | ||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||||
pub enum MayanSwiftDeploymentWormholeId { | ||||
Solana = 1, | ||||
Ethereum = 2, | ||||
SmartChain = 4, | ||||
Polygon = 5, | ||||
Arbitrum = 23, | ||||
Optimism = 24, | ||||
Base = 30, | ||||
} | ||||
|
||||
#[derive(Debug, Clone, PartialEq)] | ||||
pub struct MayanSwiftDeployment { | ||||
pub address: String, | ||||
pub wormhole_id: MayanSwiftDeploymentWormholeId, | ||||
} | ||||
|
||||
pub fn get_swift_providers() -> HashMap<Chain, MayanSwiftDeployment> { | ||||
HashMap::from([ | ||||
( | ||||
Chain::Solana, | ||||
MayanSwiftDeployment { | ||||
address: "BLZRi6frs4X4DNLw56V4EXai1b6QVESN1BhHBTYM9VcY".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Solana, | ||||
}, | ||||
), | ||||
( | ||||
Chain::Ethereum, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Ethereum, | ||||
}, | ||||
), | ||||
( | ||||
Chain::SmartChain, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::SmartChain, | ||||
}, | ||||
), | ||||
( | ||||
Chain::Polygon, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Polygon, | ||||
}, | ||||
), | ||||
( | ||||
Chain::Arbitrum, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Arbitrum, | ||||
}, | ||||
), | ||||
( | ||||
Chain::Optimism, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Optimism, | ||||
}, | ||||
), | ||||
( | ||||
Chain::Base, | ||||
MayanSwiftDeployment { | ||||
address: "0xC38e4e6A15593f908255214653d3D947CA1c2338".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Base, | ||||
}, | ||||
), | ||||
]) | ||||
} | ||||
|
||||
pub fn get_swift_deployment_chains() -> Vec<Chain> { | ||||
get_swift_providers().keys().cloned().collect() | ||||
} | ||||
|
||||
pub fn get_swift_deployment_by_chain(chain: Chain) -> Option<MayanSwiftDeployment> { | ||||
get_swift_providers().get(&chain).cloned() | ||||
} | ||||
|
||||
#[cfg(test)] | ||||
mod tests { | ||||
use super::*; | ||||
|
||||
#[test] | ||||
fn test_get_swift_provider_address() { | ||||
// Test all supported chains | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Solana), | ||||
Some(MayanSwiftDeployment { | ||||
address: "BLZRi6frs4X4DNLw56V4EXai1b6QVESN1BhHBTYM9VcY".to_string(), | ||||
wormhole_id: MayanSwiftDeploymentWormholeId::Solana, | ||||
}) | ||||
); | ||||
|
||||
let evm_address = "0xC38e4e6A15593f908255214653d3D947CA1c2338"; | ||||
|
||||
assert_eq!(get_swift_deployment_by_chain(Chain::Ethereum).map(|x| x.address), Some(evm_address.to_string())); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::SmartChain).map(|x| x.address), | ||||
Some(evm_address.to_string()) | ||||
); | ||||
assert_eq!(get_swift_deployment_by_chain(Chain::Polygon).map(|x| x.address), Some(evm_address.to_string())); | ||||
// assert_eq!(get_swift_deployment_by_chain(Chain::Avalanche).map(|x| x.address), Some(evm_address.to_string())); | ||||
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.
Suggested change
|
||||
assert_eq!(get_swift_deployment_by_chain(Chain::Arbitrum).map(|x| x.address), Some(evm_address.to_string())); | ||||
assert_eq!(get_swift_deployment_by_chain(Chain::Optimism).map(|x| x.address), Some(evm_address.to_string())); | ||||
|
||||
// Test unsupported chain | ||||
assert_eq!(get_swift_deployment_by_chain(Chain::Sui), None); | ||||
} | ||||
|
||||
#[test] | ||||
fn test_chain_ids() { | ||||
// Verify chain IDs match the provided table, and that they are in order | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Solana).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::Solana) | ||||
); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Ethereum).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::Ethereum) | ||||
); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::SmartChain).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::SmartChain) | ||||
); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Polygon).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::Polygon) | ||||
); | ||||
// assert_eq!(get_swift_deployment_by_chain(Chain::Avalanche).map(|x| x.wormhole_id), Some(6)); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Arbitrum).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::Arbitrum) | ||||
); | ||||
assert_eq!( | ||||
get_swift_deployment_by_chain(Chain::Optimism).map(|x| x.wormhole_id), | ||||
Some(MayanSwiftDeploymentWormholeId::Optimism) | ||||
); | ||||
} | ||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod deployment; | ||
pub mod swift; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use alloy_core::sol; | ||
|
||
sol! { | ||
/// @title MayanSwift Cross-Chain Swap Contract | ||
#[derive(Debug)] | ||
contract IMayanSwift{ | ||
struct OrderParams { | ||
bytes32 trader; | ||
bytes32 tokenOut; | ||
uint64 minAmountOut; | ||
uint64 gasDrop; | ||
uint64 cancelFee; | ||
uint64 refundFee; | ||
uint64 deadline; | ||
bytes32 destAddr; | ||
uint16 destChainId; | ||
bytes32 referrerAddr; | ||
uint8 referrerBps; | ||
uint8 auctionMode; | ||
bytes32 random; | ||
} | ||
|
||
struct PermitParams { | ||
uint256 value; | ||
uint256 deadline; | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} | ||
|
||
function createOrderWithEth(OrderParams memory params) external payable returns (bytes32 orderHash); | ||
function createOrderWithToken(address tokenIn, uint256 amountIn, OrderParams memory params) external returns (bytes32 orderHash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub const MAYAN_PROGRAM_ID: &str = "FC4eXxkyrMPTjiYUpp4EAnkmwMbQyZ6NDCh1kfLn6vsf"; | ||
pub const MAYAN_FORWARDER_CONTRACT: &str = "0x0654874eb7F59C6f5b39931FC45dC45337c967c3"; | ||
pub const MAYAN_ZERO_ADDRESS: &str = "0x0000000000000000000000000000000000000000"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nitpick, this is really long, let's just call it
WormholdChainId
?