Skip to content

Commit

Permalink
Merge pull request #62 from Near-One/feature/deploy_token_evm_proof
Browse files Browse the repository at this point in the history
Add token deploy on NEAR with evm proof.
  • Loading branch information
kiseln authored Jan 9, 2025
2 parents d342be3 + 685daed commit b9e0d4a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
22 changes: 22 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
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

0 comments on commit b9e0d4a

Please sign in to comment.