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(nft-swap): add standalone maker contract and proxy support #2100

Merged
merged 49 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
394fe4d
use NFT_MAKER_SWAP_V2 in nft_swap_v2 mod and in spend erc721 test
laruh Apr 18, 2024
44f542d
deploy contracts before tokens, add constructor to EtomicSwapMakerNft…
laruh Apr 18, 2024
ff1006a
use Sepolia in dockerized nft tests
laruh Apr 22, 2024
aebf756
global variables and send nft back to maker
laruh Apr 23, 2024
1966fcf
add web3 HTTPS support in mm2_main tests
laruh Apr 23, 2024
1922bff
wait for send_back_tx confirmation
laruh Apr 23, 2024
c07e8e2
call contract addresses with functions
laruh Apr 23, 2024
ebac6e6
impl check_token_uri and make chains field in ClearNftDbReq optional …
laruh Apr 4, 2024
f9f4eab
doc comms
laruh Apr 24, 2024
ad0ce31
Merge remote-tracking branch 'origin/dev' into standalone-nft-maker-s…
laruh Apr 25, 2024
4a4dfc0
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh Apr 26, 2024
c703913
fix merge conflicts
laruh Apr 26, 2024
fe498fa
impl wait_pending_transactions
laruh Apr 26, 2024
18fa53e
increase max nonce by 1
laruh Apr 26, 2024
b9a6719
Revert "increase max nonce by 1"
laruh Apr 26, 2024
9a23f20
Merge remote-tracking branch 'origin/dev' into standalone-nft-maker-s…
laruh Apr 29, 2024
998708b
impl get_or_create_nft function
laruh Apr 29, 2024
364d795
additional logs, ignore erc1155
laruh Apr 29, 2024
cb187c7
deploy new SEPOLIA_ERC721_CONTRACT
laruh Apr 29, 2024
9d4e3ee
fix linter
laruh Apr 29, 2024
495e7a9
run both nft send payment tests
laruh Apr 29, 2024
e917b0b
proxy: send nft reqs with payload data in body to satisfy proxy HttpG…
laruh May 6, 2024
f868a50
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh May 8, 2024
e94fac7
provide UrlSignWrapper structure
laruh May 9, 2024
2e8c662
additionally include chain field into UrlSignWrapper
laruh May 9, 2024
0fbf75d
increase erc721 tx confirmation time to 150, add more logs
laruh May 9, 2024
03860e1
review: use map_err for generate_gui_auth_signed_validation, doc comm…
laruh May 10, 2024
b8b05d1
proxy: send regular http post request to proxy for nft feature
laruh May 12, 2024
3de2b92
make erc721 and erc1155 time locks different in tests
laruh May 12, 2024
f2625fd
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh May 13, 2024
930a593
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh May 14, 2024
350abd6
review: impl lock_coins() to keep coins field in CoinsContext private
laruh May 14, 2024
36eaf38
review: rename Gui-Auth types to align with new names in the KomodoDe…
laruh May 15, 2024
4478ccb
review: use "http-rustls-tls" feature in web3 crate for tests
laruh May 15, 2024
7882e6e
review: send Http GET request to activate NFT
laruh May 16, 2024
d03b6d1
review: support GET requests to KomodoDeFi Proxy layer and to 3rd API…
laruh May 17, 2024
ff92a20
impl build_and_send_request func to avoid code repetition
laruh May 17, 2024
a2c47f8
review: panic in wait_for_geth_node_ready if Deth node is not ready a…
laruh May 17, 2024
d6cbfd8
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh May 21, 2024
9c3ff07
merge: fmt, log tx_hash() in NFT payments instead of bytes, import et…
laruh May 21, 2024
0bedba3
send only signed message as header in nft
laruh May 23, 2024
7976761
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh May 24, 2024
5f34f1c
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh Jun 22, 2024
e672485
review: provide log!, instead println! in tests
laruh Jun 22, 2024
0d54567
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh Jun 28, 2024
801a688
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh Jul 8, 2024
1e050d2
fmt code after merge
laruh Jul 8, 2024
7cbb941
Merge remote-tracking branch 'refs/remotes/origin/dev' into standalon…
laruh Jul 10, 2024
191b5f0
Merge remote-tracking branch 'origin/dev' into standalone-nft-maker-s…
laruh Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use instant::Instant;
use keys::Public as HtlcPubKey;
use mm2_core::mm_ctx::{MmArc, MmWeak};
use mm2_event_stream::behaviour::{EventBehaviour, EventInitStatus};
use mm2_net::transport::{GuiAuthValidation, GuiAuthValidationGenerator};
use mm2_net::transport::{KomodefiProxyAuthValidation, ProxyAuthValidationGenerator};
use mm2_number::bigdecimal_custom::CheckedDivision;
use mm2_number::{BigDecimal, BigUint, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
Expand Down Expand Up @@ -172,6 +172,7 @@ const ERC721_ABI: &str = include_str!("eth/erc721_abi.json");
/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md
const ERC1155_ABI: &str = include_str!("eth/erc1155_abi.json");
const NFT_SWAP_CONTRACT_ABI: &str = include_str!("eth/nft_swap_contract_abi.json");
const NFT_MAKER_SWAP_V2_ABI: &str = include_str!("eth/nft_maker_swap_v2_abi.json");

/// Payment states from etomic swap smart contract: https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol#L5
pub enum PaymentState {
Expand Down Expand Up @@ -289,8 +290,8 @@ impl Default for EthGasLimit {
}
}

/// Lifetime of generated signed message for gui-auth requests
const GUI_AUTH_SIGNED_MESSAGE_LIFETIME_SEC: i64 = 90;
/// Lifetime of generated signed message for proxy-auth requests
const PROXY_AUTH_SIGNED_MESSAGE_LIFETIME_SEC: i64 = 90;

/// Max transaction type according to EIP-2718
const ETH_MAX_TX_TYPE: u64 = 0x7f;
Expand All @@ -301,6 +302,7 @@ lazy_static! {
pub static ref ERC721_CONTRACT: Contract = Contract::load(ERC721_ABI.as_bytes()).unwrap();
pub static ref ERC1155_CONTRACT: Contract = Contract::load(ERC1155_ABI.as_bytes()).unwrap();
pub static ref NFT_SWAP_CONTRACT: Contract = Contract::load(NFT_SWAP_CONTRACT_ABI.as_bytes()).unwrap();
pub static ref NFT_MAKER_SWAP_V2: Contract = Contract::load(NFT_MAKER_SWAP_V2_ABI.as_bytes()).unwrap();
}

pub type EthDerivationMethod = DerivationMethod<Address, EthHDWallet>;
Expand Down Expand Up @@ -639,7 +641,7 @@ pub(crate) enum FeeEstimatorState {
pub struct EthCoinImpl {
ticker: String,
pub coin_type: EthCoinType,
priv_key_policy: EthPrivKeyPolicy,
pub(crate) priv_key_policy: EthPrivKeyPolicy,
/// Either an Iguana address or a 'EthHDWallet' instance.
/// Arc is used to use the same hd wallet from platform coin if we need to.
/// This allows the reuse of the same derived accounts/addresses of the
Expand Down Expand Up @@ -3593,7 +3595,7 @@ impl EthCoin {
impl EthCoin {
/// Sign and send eth transaction.
/// This function is primarily for swap transactions so internally it relies on the swap tx fee policy
pub(crate) fn sign_and_send_transaction(&self, value: U256, action: Action, data: Vec<u8>, gas: U256) -> EthTxFut {
pub fn sign_and_send_transaction(&self, value: U256, action: Action, data: Vec<u8>, gas: U256) -> EthTxFut {
let coin = self.clone();
let fut = async move {
match coin.priv_key_policy {
Expand Down Expand Up @@ -5776,14 +5778,15 @@ impl<T: TryToAddress> TryToAddress for Option<T> {
}
}

pub trait GuiAuthMessages {
fn gui_auth_sign_message_hash(message: String) -> Option<[u8; 32]>;
fn generate_gui_auth_signed_validation(generator: GuiAuthValidationGenerator)
-> SignatureResult<GuiAuthValidation>;
pub trait KomodoDefiAuthMessages {
fn proxy_auth_sign_message_hash(message: String) -> Option<[u8; 32]>;
fn generate_proxy_auth_signed_validation(
generator: ProxyAuthValidationGenerator,
) -> SignatureResult<KomodefiProxyAuthValidation>;
}

impl GuiAuthMessages for EthCoin {
fn gui_auth_sign_message_hash(message: String) -> Option<[u8; 32]> {
impl KomodoDefiAuthMessages for EthCoin {
fn proxy_auth_sign_message_hash(message: String) -> Option<[u8; 32]> {
let message_prefix = "atomicDEX Auth Ethereum Signed Message:\n";
let prefix_len = CompactInteger::from(message_prefix.len());

Expand All @@ -5796,16 +5799,16 @@ impl GuiAuthMessages for EthCoin {
Some(keccak256(&stream.out()).take())
}

fn generate_gui_auth_signed_validation(
generator: GuiAuthValidationGenerator,
) -> SignatureResult<GuiAuthValidation> {
let timestamp_message = get_utc_timestamp() + GUI_AUTH_SIGNED_MESSAGE_LIFETIME_SEC;
fn generate_proxy_auth_signed_validation(
generator: ProxyAuthValidationGenerator,
) -> SignatureResult<KomodefiProxyAuthValidation> {
let timestamp_message = get_utc_timestamp() + PROXY_AUTH_SIGNED_MESSAGE_LIFETIME_SEC;

let message_hash =
EthCoin::gui_auth_sign_message_hash(timestamp_message.to_string()).ok_or(SignatureError::PrefixNotFound)?;
let message_hash = EthCoin::proxy_auth_sign_message_hash(timestamp_message.to_string())
.ok_or(SignatureError::PrefixNotFound)?;
let signature = sign(&generator.secret, &H256::from(message_hash))?;

Ok(GuiAuthValidation {
Ok(KomodefiProxyAuthValidation {
coin_ticker: generator.coin_ticker,
address: generator.address,
timestamp_message,
Expand Down
Loading
Loading