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

query minted token address on starknet using static keys #175

Closed
Tracked by #123
rnbguy opened this issue Jan 9, 2025 · 1 comment · Fixed by #186
Closed
Tracked by #123

query minted token address on starknet using static keys #175

rnbguy opened this issue Jan 9, 2025 · 1 comment · Fixed by #186
Assignees
Milestone

Comments

@rnbguy
Copy link
Member

rnbguy commented Jan 9, 2025

hermes-sdk has derive_ibc_denom to find the ibc minted denoms (of the form ibc/<hash>) in cosmos-sdk based chains. This is a pure function as <hash> can be derived statically from trace prefix and native denom.

But in starknet, the tokens are minted by deploying a new erc20 contract. So the minted token denoms (contract addresses) can't be derived statically. The ics20 contract maintains a map of keys (which can be statically derived) of the minted token and the corresponding token addresses.

pub struct Storage {
erc20_class_hash: ClassHash,
salt: felt252,
ibc_token_key_to_address: Map<felt252, ContractAddress>,
ibc_token_address_to_key: Map<ContractAddress, felt252>,
}

Thus, StarknetChain needs a method which takes the same arguments as derive_ibc_denom and derive the key (using poseidon hash) and query the ics20 contract for the token address.

let denom_key = denom.key();
self.write_ibc_token_key_to_address(denom_key, token_address);
self.write_ibc_token_address_to_key(token_address, denom_key);

fn ibc_token_address(
self: @ComponentState<TContractState>, token_key: felt252
) -> ContractAddress {
let address = self.read_ibc_token_address(token_key);
assert(address.is_non_zero(), TransferErrors::ZERO_TOKEN_ADDRESS);
address
}

@rnbguy
Copy link
Member Author

rnbguy commented Jan 10, 2025

Once this is done, we can remove the ibc_token_addresses endpoint from the ics20 cairo contract

fn ibc_token_addresses(self: @ComponentState<TContractState>) -> Array<ContractAddress> {
self.read_ibc_token_addresses()
}

and stop maintaining the all token addresses:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants