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

Add token deploy on NEAR with evm proof. #62

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions bridge-cli/src/omni_connector_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub enum OmniConnectorSubCommand {
#[command(flatten)]
config_cli: CliConfig,
},
NearDeployTokenWithEvmProof {
#[clap(short, long)]
source_chain_id: u8,
#[clap(short, long)]
tx_hash: String,
#[command(flatten)]
config_cli: CliConfig,
},
NearStorageDeposit {
#[clap(short, long)]
token: String,
Expand Down Expand Up @@ -428,6 +436,20 @@ pub async fn match_subcommand(cmd: OmniConnectorSubCommand, network: Network) {
.await
.unwrap();
}

OmniConnectorSubCommand::NearDeployTokenWithEvmProof {
source_chain_id,
tx_hash,
config_cli,
} => {
omni_connector(network, config_cli)
.deploy_token(DeployTokenArgs::NearDeployTokenWithEvmProof {
chain_kind: ChainKind::try_from(source_chain_id).unwrap(),
tx_hash: TxHash::from_str(&tx_hash).expect("Invalid tx_hash"),
})
.await
.unwrap();
}
}
}

Expand Down Expand Up @@ -490,6 +512,7 @@ fn omni_connector(network: Network, cli_config: CliConfig) -> OmniConnector {
.base_bridge_client(Some(base_bridge_client))
.arb_bridge_client(Some(arb_bridge_client))
.solana_bridge_client(Some(solana_bridge_client))
.wormhole_bridge_client(None)
olga24912 marked this conversation as resolved.
Show resolved Hide resolved
.build()
.unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const STORAGE_DEPOSIT_GAS: u64 = 10_000_000_000_000;
const LOG_METADATA_GAS: u64 = 300_000_000_000_000;
const LOG_METADATA_DEPOSIT: u128 = 200_000_000_000_000_000_000_000;

const DEPLOY_TOKEN_WITH_VAA_GAS: u64 = 120_000_000_000_000;
const DEPLOY_TOKEN_WITH_VAA_DEPOSIT: u128 = 4_000_000_000_000_000_000_000_000;
const DEPLOY_TOKEN_GAS: u64 = 120_000_000_000_000;
const DEPLOY_TOKEN_DEPOSIT: u128 = 4_000_000_000_000_000_000_000_000;

const BIND_TOKEN_GAS: u64 = 300_000_000_000_000;
const BIND_TOKEN_DEPOSIT: u128 = 200_000_000_000_000_000_000_000;
Expand Down Expand Up @@ -263,8 +263,32 @@ impl NearBridgeClient {
token_locker_id.to_string(),
"deploy_token".to_string(),
borsh::to_vec(&args).map_err(|_| BridgeSdkError::UnknownError)?,
DEPLOY_TOKEN_WITH_VAA_GAS,
DEPLOY_TOKEN_WITH_VAA_DEPOSIT,
DEPLOY_TOKEN_GAS,
DEPLOY_TOKEN_DEPOSIT,
)
.await?;

tracing::info!(
tx_hash = format!("{:?}", tx_hash),
"Sent deploy token transaction"
);

Ok(tx_hash)
}

/// Deploys a token on the target chain using the evm proof
pub async fn deploy_token_with_evm_proof(&self, args: DeployTokenArgs) -> Result<CryptoHash> {
let endpoint = self.endpoint()?;
let token_locker_id = self.token_locker_id_as_str()?;

let tx_hash = near_rpc_client::change(
endpoint,
self.signer()?,
token_locker_id.to_string(),
"deploy_token".to_string(),
borsh::to_vec(&args).map_err(|_| BridgeSdkError::UnknownError)?,
DEPLOY_TOKEN_GAS,
DEPLOY_TOKEN_DEPOSIT,
)
.await?;

Expand Down
38 changes: 38 additions & 0 deletions bridge-sdk/connectors/omni-connector/src/omni_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub enum DeployTokenArgs {
chain_kind: ChainKind,
vaa: String,
},
NearDeployTokenWithEvmProof {
chain_kind: ChainKind,
tx_hash: TxHash,
},
EvmDeployToken {
chain_kind: ChainKind,
event: Nep141LockerEvent,
Expand Down Expand Up @@ -248,6 +252,33 @@ impl OmniConnector {
.await
}

pub async fn near_deploy_token_with_evm_proof(
&self,
chain_kind: ChainKind,
tx_hash: TxHash,
) -> Result<CryptoHash> {
let near_bridge_client = self.near_bridge_client()?;
let evm_bridge_client = self.evm_bridge_client(chain_kind)?;

let proof = evm_bridge_client
.get_proof_for_event(tx_hash, ProofKind::LogMetadata)
.await?;

let verify_proof_args = EvmVerifyProofArgs {
proof_kind: ProofKind::LogMetadata,
proof,
};

near_bridge_client
.deploy_token_with_evm_proof(omni_types::locker_args::DeployTokenArgs {
chain_kind,
prover_args: borsh::to_vec(&verify_proof_args).map_err(|_| {
BridgeSdkError::EthProofError("Failed to serialize proof".to_string())
})?,
})
.await
}

pub async fn evm_deploy_token(
&self,
chain_kind: ChainKind,
Expand Down Expand Up @@ -540,6 +571,13 @@ impl OmniConnector {
.solana_deploy_token(tx_hash, sender_id)
.await
.map(|hash| hash.to_string()),
DeployTokenArgs::NearDeployTokenWithEvmProof {
chain_kind,
tx_hash,
} => self
.near_deploy_token_with_evm_proof(chain_kind, tx_hash)
.await
.map(|hash| hash.to_string()),
}
}

Expand Down
Loading