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

[fix] Update caching mechanism #33

Merged
merged 10 commits into from
Apr 29, 2023
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
26 changes: 16 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions alice_node_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"gateway_contract_address": "fE174DC5FF85Ed8871e4f35d86f1BB32A8461A38",
"gateway_contract_address": "c7BcC4c1f7bA7fF7A618a8B8e1A1c1007cBD5393",
"id": 80001
},
{
"url": "https://data-seed-prebsc-2-s3.binance.org:8545",
"gateway_contract_address": "fE174DC5FF85Ed8871e4f35d86f1BB32A8461A38",
"gateway_contract_address": "c1F13fde5fFDE7B7ae6C95C9190d038A2eEb9e29",
"id": 97
}],
"pair_vec": [[80001, 97], [97, 80001]],
"pair_vec": [[80001, 97], [97, 80001]],
"signer_public_key": "020a1091341fe5664bfa1782d5e04779689068c916b04cb365ec3153755684d9a1",
"role" : "QP_FINALIZER"
"role" : "QP_MINER"
}
}
10 changes: 5 additions & 5 deletions bob_node_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"networks": {
"network_vec": [{
"url": "https://rpc-mumbai.maticvigil.com/",
"gateway_contract_address": "fE174DC5FF85Ed8871e4f35d86f1BB32A8461A38",
"gateway_contract_address": "ee8F7BB1ED6CFE3f42C815e56bb3cd47D7393e71",
"id": 80001
},
{
"url": "https://data-seed-prebsc-2-s3.binance.org:8545",
"gateway_contract_address": "fE174DC5FF85Ed8871e4f35d86f1BB32A8461A38",
"id": 97
"url": "http://127.0.0.1:8545",
"gateway_contract_address": "660eB2A65026D18705C4B824Cdbfae2203EcAD81",
"id": 26100
}],
"pair_vec": [[80001, 97], [97, 80001]],
"pair_vec": [[80001, 26100], [26100, 80001]],
"signer_public_key": "0390084fdbf27d2b79d26a4f13f0ccd982cb755a661969143c37cbc49ef5b91f27",
"role" : "QP_MINER"
}
Expand Down
34 changes: 34 additions & 0 deletions contracts/erc20/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "ferrum-xvm-erc20"
version = "0.1.0"
authors = ["Ferrum Network"]
edition = "2021"

[dependencies]
ink = { version = "4.0.0", default-features = false }
ethabi = { git = "https://github.com/akru/ethabi", default-features = false }
hex-literal = "0.3"

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [
"derive",
] }
scale-info = { version = "2", default-features = false, features = [
"derive",
], optional = true }

xvm-environment = { gith = "https://github.com/AstarNetwork/ink-xvm-sdk", default-features = false }

[lib]
name = "ferrum_xvm_erc20"
path = "lib.rs"
# This setting typically specifies that you'd like the compiler to
# create a dynamic system library. For WebAssembly though it specifies
# that the compiler should create a `*.wasm` without a start function.
crate-type = [
"cdylib",
]

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std", "xvm-environment/std"]
ink-as-dependency = []
113 changes: 113 additions & 0 deletions contracts/erc20/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//! ERC20 EVM contract interoperability using XVM interface.
#![cfg_attr(not(feature = "std"), no_std)]

pub use self::erc20::{
Erc20,
Erc20Ref,
};

/// EVM ID (from astar runtime)
const EVM_ID: u8 = 0x0F;

/// The EVM ERC20 delegation contract.
#[ink::contract(env = xvm_environment::XvmDefaultEnvironment)]
mod erc20 {
// ======= IERC20.sol:IERC20 =======
// Function signatures:
// dd62ed3e: allowance(address,address)
// 095ea7b3: approve(address,uint256)
// 70a08231: balanceOf(address)
// 18160ddd: totalSupply()
// a9059cbb: transfer(address,uint256)
// 23b872dd: transferFrom(address,address,uint256)
//
const APPROVE_SELECTOR: [u8; 4] = hex!["095ea7b3"];
const TRANSFER_SELECTOR: [u8; 4] = hex!["a9059cbb"];
const TRANSFER_FROM_SELECTOR: [u8; 4] = hex!["23b872dd"];

use ethabi::{
ethereum_types::{
H160,
U256,
},
Token,
};
use hex_literal::hex;
use ink::prelude::vec::Vec;

#[ink(storage)]
pub struct Erc20 {
evm_address: [u8; 20],
}

impl Erc20 {
/// Create new ERC20 abstraction from given contract address.
#[ink(constructor)]
pub fn new(evm_address: [u8; 20]) -> Self {
Self { evm_address }
}

/// Send `approve` call to ERC20 contract.
#[ink(message)]
pub fn approve(&mut self, to: [u8; 20], value: u128) -> bool {
let encoded_input = Self::approve_encode(to.into(), value.into());
self.env()
.extension()
.xvm_call(
super::EVM_ID,
Vec::from(self.evm_address.as_ref()),
encoded_input,
)
.is_ok()
}

/// Send `transfer` call to ERC20 contract.
#[ink(message)]
pub fn transfer(&mut self, to: [u8; 20], value: u128) -> bool {
let encoded_input = Self::transfer_encode(to.into(), value.into());
self.env()
.extension()
.xvm_call(
super::EVM_ID,
Vec::from(self.evm_address.as_ref()),
encoded_input,
)
.is_ok()
}

/// Send `transfer_from` call to ERC20 contract.
#[ink(message)]
pub fn transfer_from(&mut self, from: [u8; 20], to: [u8; 20], value: u128) -> bool {
let encoded_input = Self::transfer_from_encode(from.into(), to.into(), value.into());
self.env()
.extension()
.xvm_call(
super::EVM_ID,
Vec::from(self.evm_address.as_ref()),
encoded_input,
)
.is_ok()
}

fn approve_encode(to: H160, value: U256) -> Vec<u8> {
let mut encoded = APPROVE_SELECTOR.to_vec();
let input = [Token::Address(to), Token::Uint(value)];
encoded.extend(&ethabi::encode(&input));
encoded
}

fn transfer_encode(to: H160, value: U256) -> Vec<u8> {
let mut encoded = TRANSFER_SELECTOR.to_vec();
let input = [Token::Address(to), Token::Uint(value)];
encoded.extend(&ethabi::encode(&input));
encoded
}

fn transfer_from_encode(from: H160, to: H160, value: U256) -> Vec<u8> {
let mut encoded = TRANSFER_FROM_SELECTOR.to_vec();
let input = [Token::Address(from), Token::Address(to), Token::Uint(value)];
encoded.extend(&ethabi::encode(&input));
encoded
}
}
}
34 changes: 34 additions & 0 deletions contracts/multi-chain-staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "qp-multichain-staking"
version = "0.1.0"
authors = ["Ferrum Network"]
edition = "2021"

[dependencies]
ink = { version = "4.0.0", default-features = false }
ethabi = { git = "https://github.com/akru/ethabi", default-features = false }
hex-literal = "0.3"

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [
"derive",
] }
scale-info = { version = "2", default-features = false, features = [
"derive",
], optional = true }

xvm-environment = { gith = "https://github.com/AstarNetwork/ink-xvm-sdk", default-features = false }

[lib]
name = "qp_multichain_staking"
path = "lib.rs"
# This setting typically specifies that you'd like the compiler to
# create a dynamic system library. For WebAssembly though it specifies
# that the compiler should create a `*.wasm` without a start function.
crate-type = [
"cdylib",
]

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std", "xvm-environment/std"]
ink-as-dependency = []
Loading
Loading