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

feat(ITS): add chain name and token deploy salt and token sdk to ITS #95

Merged
merged 8 commits into from
Dec 4, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ axelar-soroban-std = { version = "^0.1.0", path = "packages/axelar-soroban-std"
axelar-gas-service = { version = "^0.1.0", path = "contracts/axelar-gas-service" }
axelar-gateway = { version = "^0.1.0", path = "contracts/axelar-gateway" }
axelar-operators = { version = "^0.1.0", path = "contracts/axelar-operators" }
interchain-token = { version = "^0.1.0", path = "contracts/interchain-token" }
interchain-token-service = { version = "^0.1.0", path = "contracts/interchain-token-service" }
alloy-primitives = { version = "0.7.6", default-features = false, features = [
"std",
Expand Down
1 change: 1 addition & 0 deletions contracts/interchain-token-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ axelar-gas-service = { workspace = true, features = ["library"] }
axelar-gateway = { workspace = true, features = ["library"] }
axelar-soroban-std = { workspace = true }
soroban-sdk = { workspace = true, features = ["alloc"] }
soroban-token-sdk = { workspace = true }

[dev-dependencies]
axelar-gas-service = { workspace = true, features = ["testutils"] }
Expand Down
85 changes: 73 additions & 12 deletions contracts/interchain-token-service/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axelar_soroban_std::types::Token;
use axelar_soroban_std::{ensure, shared_interfaces};
use soroban_sdk::xdr::ToXdr;
use soroban_sdk::{bytes, contract, contractimpl, Address, Bytes, BytesN, Env, FromVal, String};

use crate::error::ContractError;
Expand All @@ -15,22 +16,44 @@ use axelar_gateway::executable::AxelarExecutableInterface;
use axelar_soroban_std::shared_interfaces::{
migrate, MigratableInterface, OwnableInterface, UpgradableInterface,
};
use soroban_token_sdk::metadata::TokenMetadata;

const PREFIX_INTERCHAIN_TOKEN_SALT: &str = "interchain-token-salt";

#[contract]
pub struct InterchainTokenService;

#[contractimpl]
impl InterchainTokenService {
pub fn __constructor(env: Env, owner: Address, gateway: Address, gas_service: Address) {
pub fn __constructor(
env: Env,
owner: Address,
gateway: Address,
gas_service: Address,
chain_name: String,
) {
shared_interfaces::set_owner(&env, &owner);
env.storage().instance().set(&DataKey::Gateway, &gateway);
env.storage()
.instance()
.set(&DataKey::GasService, &gas_service);
env.storage()
.instance()
.set(&DataKey::ChainName, &chain_name);
}

fn gas_service(env: &Env) -> Address {
env.storage().instance().get(&DataKey::GasService).unwrap()
env.storage()
.instance()
.get(&DataKey::GasService)
.expect("gas service not found")
}

fn chain_name(env: &Env) -> String {
env.storage()
.instance()
.get(&DataKey::ChainName)
.expect("chain name not found")
}

fn pay_gas_and_call_contract(
Expand Down Expand Up @@ -146,17 +169,52 @@ impl InterchainTokenServiceInterface for InterchainTokenService {
}

fn deploy_interchain_token(
_env: &Env,
_caller: Address,
_token_id: String,
_source_address: Bytes,
_destination_chain: String,
_destination_address: Bytes,
_amount: i128,
_metadata: Bytes,
env: &Env,
caller: Address,
salt: BytesN<32>,
name: String,
symbol: String,
decimal: u32,
initial_supply: i128,
minter: Address,
_gas_token: Token,
) {
todo!()
caller.require_auth();

// TODO: minterBytes
let _minter_bytes = minter;

let _deploy_salt = Self::interchain_token_deploy_salt(env, caller, salt);

let _token_meta_data = TokenMetadata {
decimal,
name,
symbol,
};

let _token_id = BytesN::<32>::from_array(env, &[0; 32]);

// TODO: _deployInterchainToken(deploySalt, currentChain, name, symbol, decimals, minterBytes, gasValue);

if initial_supply > 0 {
// TODO: mint, transferMintership
}
}

fn interchain_token_deploy_salt(env: &Env, deployer: Address, salt: BytesN<32>) -> BytesN<32> {
ahramy marked this conversation as resolved.
Show resolved Hide resolved
let chain_name = Self::chain_name(env);
let chain_name_hash: BytesN<32> = env.crypto().keccak256(&(chain_name).to_xdr(env)).into();
env.crypto()
.keccak256(
&(
PREFIX_INTERCHAIN_TOKEN_SALT,
chain_name_hash,
deployer,
salt,
)
.to_xdr(env),
)
.into()
ahramy marked this conversation as resolved.
Show resolved Hide resolved
}

fn deploy_remote_interchain_token(
Expand Down Expand Up @@ -211,7 +269,10 @@ impl InterchainTokenServiceInterface for InterchainTokenService {
#[contractimpl]
impl AxelarExecutableInterface for InterchainTokenService {
fn gateway(env: &Env) -> Address {
env.storage().instance().get(&DataKey::Gateway).unwrap()
env.storage()
.instance()
.get(&DataKey::Gateway)
.expect("gateway not found")
}

fn execute(
Expand Down
22 changes: 12 additions & 10 deletions contracts/interchain-token-service/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axelar_gateway::executable::AxelarExecutableInterface;
use axelar_soroban_std::types::Token;
use soroban_sdk::{contractclient, Address, Bytes, Env, String};
use soroban_sdk::{contractclient, Address, Bytes, BytesN, Env, String};

use crate::error::ContractError;

Expand All @@ -14,16 +14,18 @@ pub trait InterchainTokenServiceInterface: AxelarExecutableInterface {

fn remove_trusted_address(env: &Env, chain: String) -> Result<(), ContractError>;

fn interchain_token_deploy_salt(env: &Env, deployer: Address, salt: BytesN<32>) -> BytesN<32>;

fn deploy_interchain_token(
_env: &Env,
_caller: Address,
_token_id: String,
_source_address: Bytes,
_destination_chain: String,
_destination_address: Bytes,
_amount: i128,
_metadata: Bytes,
_gas_token: Token,
env: &Env,
caller: Address,
salt: BytesN<32>,
name: String,
symbol: String,
decimals: u32,
initial_supply: i128,
minter: Address,
gas_token: Token,
);

fn deploy_remote_interchain_token(
Expand Down
1 change: 1 addition & 0 deletions contracts/interchain-token-service/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pub enum DataKey {
TrustedAddress(String),
Gateway,
GasService,
ChainName,
}
16 changes: 14 additions & 2 deletions contracts/interchain-token-service/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ fn setup_env<'a>() -> (Env, InterchainTokenServiceClient<'a>) {
let owner = Address::generate(&env);
let gateway_client = setup_gateway(&env);
let gas_service_client = setup_gas_service(&env);
let chain_name = String::from_str(&env, "chain_name");
let contract_id = env.register(
InterchainTokenService,
(&owner, gateway_client.address, gas_service_client.address),
(
&owner,
gateway_client.address,
gas_service_client.address,
chain_name,
),
);
let client = InterchainTokenServiceClient::new(&env, &contract_id);

Expand All @@ -43,9 +49,15 @@ fn register_interchain_token_service() {
let owner = Address::generate(&env);
let gateway_client = setup_gateway(&env);
let gas_service_client = setup_gas_service(&env);
let chain_name = String::from_str(&env, "chain_name");
let contract_id = env.register(
InterchainTokenService,
(&owner, gateway_client.address, gas_service_client.address),
(
&owner,
gateway_client.address,
gas_service_client.address,
chain_name,
),
);
let client = InterchainTokenServiceClient::new(&env, &contract_id);

Expand Down
5 changes: 0 additions & 5 deletions contracts/interchain-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ pub mod error;

mod interface;

// Allows using std (and its macros) in test modules
#[cfg(test)]
#[macro_use]
extern crate std;

cfg_if::cfg_if! {
if #[cfg(all(feature = "library", not(feature = "testutils")))] {
pub use interface::{InterchainTokenClient, InterchainTokenInterface};
Expand Down
3 changes: 2 additions & 1 deletion contracts/interchain-token/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ extern crate std;
use axelar_soroban_std::{
assert_invoke_auth_err, assert_invoke_auth_ok, assert_last_emitted_event,
};
use interchain_token::{contract::InterchainToken, InterchainTokenClient};

use interchain_token::contract::{InterchainToken, InterchainTokenClient};
use soroban_sdk::testutils::{MockAuth, MockAuthInvoke};
use soroban_sdk::{
testutils::{Address as _, BytesN as _},
Expand Down
Loading