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 1 commit
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
24 changes: 23 additions & 1 deletion 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 @@ -489,7 +511,7 @@ fn omni_connector(network: Network, cli_config: CliConfig) -> OmniConnector {
.eth_bridge_client(Some(eth_bridge_client))
.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 @@ -23,6 +23,9 @@ 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_WITH_EVM_PROOF_GAS: u64 = 120_000_000_000_000;
const DEPLOY_TOKEN_WITH_EVM_PROOF_DEPOSIT: u128 = 4_000_000_000_000_000_000_000_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does deposit depend on which proof we are providing? If not, perhaps should be a single constant for all types

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in 685daed


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 @@ -276,6 +279,30 @@ impl NearBridgeClient {
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_WITH_EVM_PROOF_GAS,
DEPLOY_TOKEN_WITH_EVM_PROOF_DEPOSIT,
)
.await?;

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

Ok(tx_hash)
}

/// Binds token on NEAR chain using the token locker
#[tracing::instrument(skip_all, name = "BIND TOKEN")]
pub async fn bind_token(&self, args: BindTokenArgs) -> Result<CryptoHash> {
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::DeployToken)
olga24912 marked this conversation as resolved.
Show resolved Hide resolved
.await?;

let verify_proof_args = EvmVerifyProofArgs {
proof_kind: ProofKind::DeployToken,
olga24912 marked this conversation as resolved.
Show resolved Hide resolved
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