Skip to content

Commit

Permalink
fix(docs/content): make self sponsor example for Shimmer
Browse files Browse the repository at this point in the history
  • Loading branch information
miker83z committed Aug 13, 2024
1 parent 7626a54 commit 3eb16f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ name = "foundry-output-claim"
path = "stardust/foundry-output-claim.rs"

[[example]]
name = "self-sponsor"
path = "stardust/self-sponsor.rs"
name = "shimmer-self-sponsor"
path = "stardust/shimmer-self-sponsor.rs"
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Example demonstrating the self-sponsor scenario for claiming a basic output.
//! In order to work, it requires a network with test objects
//! Example demonstrating the self-sponsor scenario for claiming a Shimmer basic
//! output. In order to work, it requires a network with test objects
//! generated from iota-genesis-builder/src/stardust/test_outputs.
use std::{fs, path::PathBuf, str::FromStr};
Expand All @@ -15,9 +15,9 @@ use iota_sdk::{
types::{
base_types::ObjectID,
crypto::SignatureScheme::ED25519,
gas_coin::GAS,
programmable_transaction_builder::ProgrammableTransactionBuilder,
quorum_driver_types::ExecuteTransactionRequestType,
smr_coin::SMR,
transaction::{Argument, ObjectArg, Transaction, TransactionData},
IOTA_FRAMEWORK_ADDRESS, STARDUST_ADDRESS,
},
Expand All @@ -26,6 +26,9 @@ use iota_sdk::{
use move_core_types::ident_str;
use shared_crypto::intent::Intent;

pub const IOTA_COIN_TYPE: u32 = 4218;
pub const SHIMMER_COIN_TYPE: u32 = 4219;

/// Got from iota-genesis-builder/src/stardust/test_outputs/stardust_mix.rs
const MAIN_ADDRESS_MNEMONIC: &str = "crazy drum raw dirt tooth where fee base warm beach trim rule sign silk fee fee dad large creek venue coin steel hub scale";

Expand Down Expand Up @@ -57,9 +60,12 @@ async fn main() -> Result<(), anyhow::Error> {
let mut keystore = setup_keystore()?;

// For this example we need to derive addresses that are not at different
// indexes, one for sponsoring and one for claiming the Basic Output.
let sponsor_derivation_path = DerivationPath::from_str("m/44'/4218'/0'/0'/5'")?;
let sender_derivation_path = DerivationPath::from_str("m/44'/4218'/0'/0'/10'")?;
// indexes and coin_types, one for sponsoring with IOTA coin type and one for
// claiming the Basic Output with Shimmer coin type.
let sponsor_derivation_path =
DerivationPath::from_str(format!("m/44'/{IOTA_COIN_TYPE}'/0'/0'/5'").as_str())?;
let sender_derivation_path =
DerivationPath::from_str(format!("m/44'/{SHIMMER_COIN_TYPE}'/0'/0'/50'").as_str())?;

// Derive the address of the sponsor
let sponsor = keystore.import_from_mnemonic(
Expand All @@ -80,7 +86,7 @@ async fn main() -> Result<(), anyhow::Error> {
// This object id was fetched manually. It refers to a Basic Output object that
// contains some Native Tokens.
let basic_output_object_id = ObjectID::from_hex_literal(
"0xb9c75a53a39e82bafcb454e68b3bd265a6083f32be832632df9ade976b47c37f",
"0xbdc4dec75098700e8e82349d9f3a9f28dcd22d2b39f5fbdf8436b05430bc3690",
)?;
// Get Basic Output object
let basic_output_object = iota_client
Expand All @@ -100,9 +106,9 @@ async fn main() -> Result<(), anyhow::Error> {
let mut builder = ProgrammableTransactionBuilder::new();

////// Command #1: extract the base token and native tokens bag.
// Type argument for a Basic Output coming from the IOTA network, i.e., the IOTA
// token or Gas type tag
let type_arguments = vec![GAS::type_tag()];
// Type argument for a Basic Output coming from the Shimmer network, i.e., the
// SMR coin
let type_arguments = vec![SMR::type_tag()];
// Then pass the basic output object as input
let arguments = vec![builder.obj(ObjectArg::ImmOrOwnedObject(basic_output_object_ref))?];
// Finally call the basic_output::extract_assets function
Expand All @@ -128,9 +134,9 @@ async fn main() -> Result<(), anyhow::Error> {
arguments,
);

////// Command #3: create a coin from the extracted IOTA balance
// Type argument for the IOTA coin
let type_arguments = vec![GAS::type_tag()];
////// Command #3: create a coin from the extracted SMR balance
// Type argument for the SMR coin
let type_arguments = vec![SMR::type_tag()];
let arguments = vec![extracted_base_token];
let new_iota_coin = builder.programmable_move_call(
IOTA_FRAMEWORK_ADDRESS.into(),
Expand Down

0 comments on commit 3eb16f2

Please sign in to comment.