Skip to content

Commit

Permalink
Merge branch 'main' into lempire123/silo-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored May 11, 2023
2 parents a10526e + c5b4090 commit 3864afb
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 11 deletions.
19 changes: 19 additions & 0 deletions .catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: aurora-engine-cli-rs
description: |-
Command-line tool for interacting with the Aurora Engine
tags:
- near
- cli
links: []
annotations:
aurora.dev/security-tier: "2"
spec:
owner: engine-team
type: contract-library
lifecycle: production
system: aurora-engine
interactsWith: []
18 changes: 18 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
on:
push:
branches:
- main
pull_request:
schedule:
- cron: "20 12 * * *"
workflow_dispatch:

name: "Security Analysis"
jobs:
contract_analysis:
name: "Shared"
uses: aurora-is-near/.github/.github/workflows/security_analysis.yml@master
secrets: inherit
with:
ignore_failures: "true"
24 changes: 17 additions & 7 deletions scripts/advanced.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
ENGINE_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/latest/aurora-mainnet.wasm"
AURORA_LAST_VERSION="2.9.0"
ENGINE_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-mainnet.wasm"
ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin

Expand All @@ -13,7 +14,7 @@ export NEARCORE_HOME="/tmp/localnet"
pip3 list | grep nearup > /dev/null || pip3 install --user nearup

start_node() {
cmd="nearup run localnet --home $NEARCORE_HOME"
cmd="nearup run localnet --home $NEARCORE_HOME --num-nodes 1"

if [[ $(uname -m) == "arm64" ]]; then # Check for local execution
cmd="$cmd --binary-path $HOME/.nearup/near/localnet"
Expand All @@ -27,7 +28,16 @@ finish() {
nearup stop > /dev/null 2>&1
# Cleanup
rm -rf $NEARCORE_HOME
exit

if [[ -z "$1" ]]; then
exit 0
else
exit "$1"
fi
}

error_exit() {
finish 1
}

# Download `neard` and preparing config files.
Expand All @@ -45,18 +55,18 @@ start_node
sleep 1

# Download Aurora EVM.
curl -sL $ENGINE_WASM_URL -o $ENGINE_WASM_PATH || finish
curl -sL $ENGINE_WASM_URL -o $ENGINE_WASM_PATH || error_exit

# Deploy and init Aurora EVM smart contract.
aurora-cli near write engine-init -w $ENGINE_WASM_PATH || finish
aurora-cli near write engine-init -w $ENGINE_WASM_PATH || error_exit
sleep 2

# Deploy EVM code.
aurora-cli near write deploy-code $EVM_CODE || finish
aurora-cli near write deploy-code $EVM_CODE || error_exit
sleep 2

# Run EVM view call.
aurora-cli near read solidity -t 0x592186c059e3d9564cac6b1ada6f2dc7ff1d78e9 call-args-by-name \
--abi-path $ABI_PATH -m "greet" --arg '{}'
--abi-path $ABI_PATH -m "greet" --arg '{}' || error_exit

finish
11 changes: 11 additions & 0 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ EVM_CODE=$(cat docs/res/HelloWorld.hex)
ABI_PATH="docs/res/HelloWorld.abi"
ENGINE_PREV_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_PREV_VERSION/aurora-mainnet.wasm"
ENGINE_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-mainnet.wasm"
XCC_ROUTER_LAST_WASM_URL="https://github.com/aurora-is-near/aurora-engine/releases/download/$AURORA_LAST_VERSION/aurora-factory-mainnet.wasm"
ENGINE_WASM_PATH="/tmp/aurora-mainnet.wasm"
XCC_ROUTER_WASM_PATH="/tmp/aurora-factory-mainnet.wasm"
USER_BASE_BIN=$(python3 -m site --user-base)/bin
NODE_KEY_PATH=$NEARCORE_HOME/node0/validator_key.json
AURORA_KEY_PATH=$NEARCORE_HOME/node0/aurora_key.json
Expand Down Expand Up @@ -179,5 +181,14 @@ sleep 1
mask=$(aurora-cli --engine $ENGINE_ACCOUNT paused-precompiles || error_exit)
assert_eq "$mask" 0

# XCC router operations.
# Download XCC router contract.
curl -sL $XCC_ROUTER_LAST_WASM_URL -o $XCC_ROUTER_WASM_PATH || error_exit
aurora-cli --engine $ENGINE_ACCOUNT factory-update $XCC_ROUTER_WASM_PATH || error_exit
sleep 1
aurora-cli --engine $ENGINE_ACCOUNT factory-set-wnear-address 0x80c6a002756e29b8bf2a587f7d975a726d5de8b9 || error_exit
sleep 1
aurora-cli --engine $ENGINE_ACCOUNT fund-xcc-sub-account 0x43a4969cc2c22d0000c591ff4bd71983ea8a8be9 some_account.near 25.5 || error_exit

# Stop NEAR node and clean up.
finish
19 changes: 17 additions & 2 deletions src/cli/simple/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde_json::Value;
use std::fmt::{Display, Formatter};
use std::{path::Path, str::FromStr};

use crate::utils::near_to_yocto;
use crate::{
client::Client,
utils::{self, hex_to_address, hex_to_arr, hex_to_vec, secret_key_from_hex},
Expand Down Expand Up @@ -376,6 +377,7 @@ pub async fn fund_xcc_sub_account(
client: Client,
target: String,
account_id: Option<String>,
deposit: f64,
) -> anyhow::Result<()> {
let args = FundXccArgs {
target: hex_to_address(&target)?,
Expand All @@ -390,7 +392,7 @@ pub async fn fund_xcc_sub_account(
success_message: "The XCC sub-account has been funded successfully",
error_message: "Error while funding XCC sub-account",
}
.proceed(client, args)
.proceed_with_deposit(client, args, deposit)
.await
}

Expand Down Expand Up @@ -702,7 +704,20 @@ struct ContractCall<'a> {

impl ContractCall<'_> {
async fn proceed(&self, client: Client, args: Vec<u8>) -> anyhow::Result<()> {
let result = client.near().contract_call(self.method, args).await?;
self.proceed_with_deposit(client, args, 0.0).await
}

async fn proceed_with_deposit(
&self,
client: Client,
args: Vec<u8>,
deposit: f64,
) -> anyhow::Result<()> {
let yocto = near_to_yocto(deposit);
let result = client
.near()
.contract_call_with_deposit(self.method, args, yocto)
.await?;

match result.status {
FinalExecutionStatus::NotStarted | FinalExecutionStatus::Started => {
Expand Down
5 changes: 4 additions & 1 deletion src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub enum Command {
target: String,
/// Wnear Account Id
wnear_account_id: Option<String>,
/// Attached deposit in NEAR
deposit: f64,
},
/// Stage a new code for upgrade
StageUpgrade {
Expand Down Expand Up @@ -302,8 +304,9 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
Command::FundXccSubAccount {
target,
wnear_account_id,
deposit,
} => {
command::fund_xcc_sub_account(client, target, wnear_account_id).await?;
command::fund_xcc_sub_account(client, target, wnear_account_id, deposit).await?;
}
Command::StageUpgrade { path } => command::stage_upgrade(client, path).await?,
Command::DeployUpgrade => command::deploy_upgrade(client).await?,
Expand Down
11 changes: 10 additions & 1 deletion src/client/near.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,23 @@ impl NearClient {
&self,
method_name: &str,
args: Vec<u8>,
) -> anyhow::Result<FinalExecutionOutcomeView> {
self.contract_call_with_deposit(method_name, args, 0).await
}

pub async fn contract_call_with_deposit(
&self,
method_name: &str,
args: Vec<u8>,
deposit: u128,
) -> anyhow::Result<FinalExecutionOutcomeView> {
self.near_broadcast_tx(
vec![Action::FunctionCall(
near_primitives::transaction::FunctionCallAction {
method_name: method_name.to_string(),
args,
gas: NEAR_GAS,
deposit: 0,
deposit,
},
)],
None,
Expand Down

0 comments on commit 3864afb

Please sign in to comment.