Skip to content

Commit f69589f

Browse files
committed
feat: add a possibility to deploy ERC-20 tokens
1 parent c6200c7 commit f69589f

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

cli/src/cli/simple/command/mod.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use aurora_engine_types::parameters::connector::{
99
PausedMask, SetErc20MetadataArgs, SetEthConnectorContractAccountArgs, WithdrawSerializeType,
1010
};
1111
use aurora_engine_types::parameters::engine::{
12-
CallArgs, FunctionCallArgsV2, GetStorageAtArgs, NewCallArgs, NewCallArgsV2,
13-
PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs, SetOwnerArgs,
12+
CallArgs, DeployErc20TokenArgs, FunctionCallArgsV2, GetStorageAtArgs, NewCallArgs,
13+
NewCallArgsV2, PausePrecompilesCallArgs, RelayerKeyArgs, RelayerKeyManagerArgs, SetOwnerArgs,
1414
SetUpgradeDelayBlocksArgs, SubmitResult, TransactionStatus,
1515
};
1616
use aurora_engine_types::parameters::xcc::FundXccArgs;
@@ -778,6 +778,28 @@ pub async fn set_erc20_metadata(
778778
.await
779779
}
780780

781+
/// Deploy a new ERC-20 contract.
782+
pub async fn deploy_erc20_token(
783+
context: Context,
784+
nep141: String,
785+
with_metadata: bool,
786+
) -> anyhow::Result<()> {
787+
let nep141_account_id = nep141.parse().map_err(|e| anyhow::anyhow!("{e}"))?;
788+
let args = borsh::to_vec(&if with_metadata {
789+
DeployErc20TokenArgs::WithMetadata(nep141_account_id)
790+
} else {
791+
DeployErc20TokenArgs::Legacy(nep141_account_id)
792+
})?;
793+
794+
contract_call!(
795+
"deploy_erc20_token",
796+
"ERC-20 token has been deployed successfully",
797+
"Error while deploying ERC-20 token"
798+
)
799+
.proceed(context, args)
800+
.await
801+
}
802+
781803
/// Mirror ERC-20 contract.
782804
pub async fn mirror_erc20_token(
783805
context: Context,
@@ -1039,7 +1061,17 @@ impl ContractCall<'_> {
10391061
// TODO: The output could be serialized with JSON or Borsh.
10401062
// TODO: In the case of Borsh we should provide a type for deserializing the output in the corresponding object.
10411063
OutputFormat::Plain => match to_string_pretty(&output) {
1042-
Ok(msg) if !output.is_empty() => println!("{}\n{msg}", self.success_message),
1064+
Ok(msg) if !output.is_empty() => {
1065+
// TODO: Add optional argument `fn(&[u8]) -> String` which will generate a custom output message.
1066+
if self.method == "deploy_erc20_token"
1067+
|| self.method == "mirror_erc20_token"
1068+
{
1069+
let address = hex::encode(&output);
1070+
println!("{}, ERC-20 address: 0x{address}", self.success_message)
1071+
} else {
1072+
println!("{}: {msg}", self.success_message)
1073+
}
1074+
}
10431075
Ok(_) | Err(_) => println!("{}", self.success_message),
10441076
},
10451077
OutputFormat::Json => {

cli/src/cli/simple/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum Command {
7272
/// Owner of the Aurora EVM
7373
#[arg(long)]
7474
owner_id: Option<String>,
75-
/// How many blocks after staging upgrade can deploy it
75+
/// Delay in blocks between staging and updating the contract
7676
#[arg(long)]
7777
upgrade_delay_blocks: Option<u64>,
7878
},
@@ -346,6 +346,15 @@ pub enum Command {
346346
#[arg(long)]
347347
decimals: u8,
348348
},
349+
/// Deploy ERC-20 token
350+
DeployErc20Token {
351+
/// Account ID of corresponding NEP-141
352+
#[arg(long)]
353+
nep141: String,
354+
/// With ERC-20 metadata received from the corresponding NEP-141
355+
#[arg(long, default_value_t = false)]
356+
with_metadata: bool,
357+
},
349358
/// Mirror ERC-20 token
350359
MirrorErc20Token {
351360
/// Account of contract where ERC-20 has been deployed
@@ -620,6 +629,12 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
620629
} => {
621630
command::set_erc20_metadata(context, erc20_id, name, symbol, decimals).await?;
622631
}
632+
Command::DeployErc20Token {
633+
nep141,
634+
with_metadata,
635+
} => {
636+
command::deploy_erc20_token(context, nep141, with_metadata).await?;
637+
}
623638
Command::MirrorErc20Token {
624639
contract_id,
625640
nep141,

scripts/simple.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ echo "$version"
123123
aurora-cli --engine $ENGINE_ACCOUNT set-eth-connector-contract-account --account-id eth.connector.near || error_exit
124124
wait_for_block
125125

126+
# Deploy ERC-20 token contract
127+
aurora-cli --engine $ENGINE_ACCOUNT deploy-erc20-token --nep141 eth.token.near || error_exit
128+
wait_for_block
129+
126130
# Create account id for key manager
127131
aurora-cli create-account --account $MANAGER_ACCOUNT --balance 10 > $MANAGER_KEY_PATH || error_exit
128132
wait_for_block

0 commit comments

Comments
 (0)