stellar_token_utils/
contract.rs

1use stellar_axelar_std::token::Client;
2use stellar_axelar_std::{contract, contractimpl, soroban_sdk, Address, Bytes, Env};
3
4use crate::interface::TokenUtilsInterface;
5
6#[contract]
7pub struct TokenUtils;
8
9#[contractimpl]
10impl TokenUtilsInterface for TokenUtils {
11    fn create_stellar_asset_contract(env: Env, asset_xdr: Bytes) -> Address {
12        let deployer = env.deployer().with_stellar_asset(asset_xdr);
13        let deployed_address = deployer.deployed_address();
14
15        // Return if the asset contract has already been deployed
16        // This prevents failures triggered by frontrunning this creation, when it's part of a multicall
17        if Client::new(&env, &deployed_address).try_decimals().is_ok() {
18            return deployed_address;
19        }
20
21        deployer.deploy()
22    }
23}