Skip to content

Commit

Permalink
Remove built-in soroban token (#607)
Browse files Browse the repository at this point in the history
* Remove built-in soroban token

* Update test wasms

* Use updated sdk and update test wasms

* stop using deprecated functions

* update sdk in wasm-tests

* remove create_token_from_contract from env.json
  • Loading branch information
sisuresh authored Dec 15, 2022
1 parent 869752e commit 249f659
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 288 deletions.
12 changes: 0 additions & 12 deletions soroban-env-common/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,18 +788,6 @@
],
"return": "Object",
"docs": "Deploys a contract from the current contract. `wasm_hash` must be a hash of the contract code that has already been installed on this network. `salt` is used to create a unique contract id."
},
{
"export": "4",
"name": "create_token_from_contract",
"args": [
{
"name": "salt",
"type": "Object"
}
],
"return": "Object",
"docs": "Deploys a built-in token contract from the current contract. `salt` is used to create a unique contract id for the token."
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@
pub const ENV_META_V0_SECTION_NAME: &'static str = "contractenvmetav0";

soroban_env_macros::generate_env_meta_consts!(
interface_version: 26,
interface_version: 27,
);
11 changes: 0 additions & 11 deletions soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,17 +1771,6 @@ impl VmCallerCheckedEnv for Host {
self.create_contract_with_id_preimage(code, id_preimage)
}

fn create_token_from_contract(
&self,
_vmcaller: &mut VmCaller<Host>,
salt: Object,
) -> Result<Object, HostError> {
let contract_id = self.get_current_contract_id()?;
let salt = self.uint256_from_obj_input("salt", salt)?;
let id_preimage = self.id_preimage_from_contract(contract_id, salt)?;
self.create_contract_with_id_preimage(ScContractCode::Token, id_preimage)
}

// Notes on metering: here covers the args unpacking. The actual VM work is changed at lower layers.
fn call(
&self,
Expand Down
6 changes: 0 additions & 6 deletions soroban-env-host/src/native_contract/token/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ pub fn write_state(e: &Host, id: Identifier, is_frozen: bool) -> Result<(), Host
// Metering: covered by components
pub fn transfer_classic_balance(e: &Host, to_key: AccountId, amount: i64) -> Result<(), HostError> {
match read_metadata(e)? {
Metadata::Token(_) => {
return Err(e.err_status_msg(
ContractError::OperationNotSupportedError,
"smart tokens don't support conversions to/from classic",
))
}
Metadata::Native => transfer_account_balance(e, to_key, amount)?,
Metadata::AlphaNum4(asset) => transfer_trustline_balance(
e,
Expand Down
24 changes: 4 additions & 20 deletions soroban-env-host/src/native_contract/token/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::native_contract::token::balance::{
use crate::native_contract::token::cryptography::check_auth;
use crate::native_contract::token::event;
use crate::native_contract::token::metadata::{
has_metadata, read_decimal, read_name, read_symbol, write_metadata,
has_metadata, read_name, read_symbol, write_metadata,
};
use crate::native_contract::token::nonce::read_nonce;
use crate::native_contract::token::public_types::{Identifier, Metadata, Signature, TokenMetadata};
use crate::native_contract::token::public_types::{Identifier, Metadata, Signature};
use crate::{err, HostError};

use soroban_env_common::xdr::Asset;
Expand All @@ -35,9 +35,6 @@ pub trait TokenTrait {
/// (burn, freeze, unfreeze, mint, set_admin) will always fail
fn init_asset(e: &Host, asset_bytes: Bytes) -> Result<(), HostError>;

/// init creates a token contract that does not wrap an asset on the classic side.
fn init(e: &Host, admin: Identifier, metadata: TokenMetadata) -> Result<(), HostError>;

fn nonce(e: &Host, id: Identifier) -> Result<i128, HostError>;

fn allowance(e: &Host, from: Identifier, spender: Identifier) -> Result<i128, HostError>;
Expand Down Expand Up @@ -190,19 +187,6 @@ impl TokenTrait for Token {
Ok(())
}

fn init(e: &Host, admin: Identifier, metadata: TokenMetadata) -> Result<(), HostError> {
if has_metadata(&e)? {
return Err(e.err_status_msg(
ContractError::AlreadyInitializedError,
"token has been already initialized",
));
}

write_administrator(&e, admin)?;
write_metadata(&e, Metadata::Token(metadata))?;
Ok(())
}

fn nonce(e: &Host, id: Identifier) -> Result<i128, HostError> {
read_nonce(e, id)
}
Expand Down Expand Up @@ -380,8 +364,8 @@ impl TokenTrait for Token {
Ok(())
}

fn decimals(e: &Host) -> Result<u32, HostError> {
read_decimal(&e)
fn decimals(_e: &Host) -> Result<u32, HostError> {
Ok(7)
}

fn name(e: &Host) -> Result<Bytes, HostError> {
Expand Down
10 changes: 0 additions & 10 deletions soroban-env-host/src/native_contract/token/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub fn has_metadata(e: &Host) -> Result<bool, HostError> {
// Metering: *mostly* covered by components. `bytes_new_from_slice` and `Bytes` not covered.
pub fn read_name(e: &Host) -> Result<Bytes, HostError> {
match read_metadata(e)? {
Metadata::Token(token) => Ok(token.name),
Metadata::Native => Ok(Bytes::try_from_val(e, e.bytes_new_from_slice(b"native")?)?),
Metadata::AlphaNum4(asset) => {
let mut res: Bytes = asset.asset_code.into();
Expand Down Expand Up @@ -56,17 +55,8 @@ pub fn read_name(e: &Host) -> Result<Bytes, HostError> {
// Metering: *mostly* covered by components.`bytes_new_from_slice` and `Bytes` not covered.
pub fn read_symbol(e: &Host) -> Result<Bytes, HostError> {
match read_metadata(e)? {
Metadata::Token(token) => Ok(token.symbol),
Metadata::Native => Ok(Bytes::try_from_val(e, e.bytes_new_from_slice(b"native")?)?),
Metadata::AlphaNum4(asset) => Ok(asset.asset_code.into()),
Metadata::AlphaNum12(asset) => Ok(asset.asset_code.into()),
}
}

// Metering: covered by components
pub fn read_decimal(e: &Host) -> Result<u32, HostError> {
match read_metadata(e)? {
Metadata::Token(token) => Ok(token.decimals),
Metadata::Native | Metadata::AlphaNum4(_) | Metadata::AlphaNum12(_) => Ok(7),
}
}
9 changes: 0 additions & 9 deletions soroban-env-host/src/native_contract/token/public_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ pub enum SignaturePayload {
V0(SignaturePayloadV0),
}

#[derive(Clone)]
#[contracttype]
pub struct TokenMetadata {
pub name: Bytes,
pub symbol: Bytes,
pub decimals: u32,
}

#[derive(Clone)]
#[contracttype]
pub struct AlphaNum4Metadata {
Expand All @@ -108,7 +100,6 @@ pub struct AlphaNum12Metadata {
#[derive(Clone)]
#[contracttype]
pub enum Metadata {
Token(TokenMetadata),
Native,
AlphaNum4(AlphaNum4Metadata),
AlphaNum12(AlphaNum12Metadata),
Expand Down
36 changes: 2 additions & 34 deletions soroban-env-host/src/native_contract/token/test_token.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use crate::{
host_vec,
native_contract::{
testutils::{sign_args, HostVec, TestSigner},
token::public_types::TokenMetadata,
},
test::util::{generate_account_id, generate_bytes_array},
native_contract::testutils::{sign_args, HostVec, TestSigner},
Host, HostError,
};
use soroban_env_common::{
xdr::{Asset, ContractId, CreateContractArgs, HostFunction, ScContractCode, Uint256},
xdr::{Asset, ContractId, CreateContractArgs, HostFunction, ScContractCode},
CheckedEnv, RawVal,
};
use soroban_env_common::{Symbol, TryFromVal, TryIntoVal};
Expand All @@ -23,23 +19,6 @@ pub(crate) struct TestToken<'a> {
}

impl<'a> TestToken<'a> {
pub(crate) fn new(host: &'a Host) -> Self {
host.set_source_account(generate_account_id());
let id_obj: RawVal = host
.invoke_function(HostFunction::CreateContract(CreateContractArgs {
contract_id: ContractId::SourceAccount(Uint256(generate_bytes_array())),
source: ScContractCode::Token,
}))
.unwrap()
.try_into_val(host)
.unwrap();
host.remove_source_account();
Self {
id: BytesN::<32>::try_from_val(host, id_obj).unwrap(),
host,
}
}

pub(crate) fn new_from_asset(host: &'a Host, asset: Asset) -> Self {
let id_obj: RawVal = host
.invoke_function(HostFunction::CreateContract(CreateContractArgs {
Expand All @@ -55,17 +34,6 @@ impl<'a> TestToken<'a> {
}
}

pub(crate) fn init(&self, admin: Identifier, metadata: TokenMetadata) -> Result<(), HostError> {
Ok(self
.host
.call(
self.id.clone().into(),
Symbol::from_str("init").into(),
host_vec![self.host, admin, metadata].into(),
)?
.try_into_val(self.host)?)
}

pub(crate) fn nonce(&self, id: Identifier) -> Result<i128, HostError> {
Ok(self
.host
Expand Down
Loading

0 comments on commit 249f659

Please sign in to comment.