Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Aug 30, 2024
1 parent 330edda commit cca2132
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 24 deletions.
36 changes: 33 additions & 3 deletions move/example/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

[move]
version = 2
manifest_digest = "35EEA97D60D29F06D44ECBC878C919B5E79C2A94B14C542D6A429B33F9572E97"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
manifest_digest = "196CD7C03594C5D0B7CCE594F4099D87F127C8F0EAB84C1570C4D2C874A28047"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ name = "AxelarGateway" },
{ name = "GasService" },
{ name = "ITS" },
{ name = "Sui" },
]

[[move.package]]
name = "Abi"
source = { local = "../abi" }

dependencies = [
{ name = "Sui" },
]

Expand All @@ -26,6 +35,27 @@ dependencies = [
{ name = "Sui" },
]

[[move.package]]
name = "Governance"
source = { local = "../governance" }

dependencies = [
{ name = "Abi" },
{ name = "AxelarGateway" },
{ name = "Sui" },
]

[[move.package]]
name = "ITS"
source = { local = "../its" }

dependencies = [
{ name = "AxelarGateway" },
{ name = "GasService" },
{ name = "Governance" },
{ name = "Sui" },
]

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet-v1.25.3", subdir = "crates/sui-framework/packages/move-stdlib" }
Expand All @@ -39,6 +69,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.32.0"
compiler-version = "1.30.3"
edition = "2024.beta"
flavor = "sui"
67 changes: 55 additions & 12 deletions move/example/sources/its/its.move
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module example::its {
module example::its_example {
use std::ascii;
use std::ascii::{String};
use std::type_name;

use sui::event;
use sui::address;
use sui::hex;
use sui::coin::{Coin};
use sui::coin::{Self, Coin, TreasuryCap, CoinMetadata};
use sui::sui::SUI;
use sui::clock::Clock;
use sui::url::Url;

use axelar_gateway::channel::{Self, Channel, ApprovedMessage};
use axelar_gateway::discovery::{Self, RelayerDiscovery, Transaction};
Expand All @@ -18,10 +19,17 @@ module example::its {
use its::service;
use its::its::ITS;
use its::token_id::TokenId;
use its::coin_management;
use its::coin_info;

public struct ITS_EXAMPLE has drop {}

public struct Singleton has key {
id: UID,
channel: Channel,
treasury_cap: Option<TreasuryCap<ITS_EXAMPLE>>,
coin_metadata: Option<CoinMetadata<ITS_EXAMPLE>>,
token_id: Option<TokenId>,
}

public struct Executed has copy, drop {
Expand All @@ -31,15 +39,41 @@ module example::its {
amount: u64,
}

fun init(ctx: &mut TxContext) {
fun init(witness: ITS_EXAMPLE, ctx: &mut TxContext) {
let decimals: u8 = 8;
let symbol: vector<u8> = b"ITS";
let name: vector<u8> = b"Test Coin";
let description = b"";
let icon_url = option::none<Url>();
let (treasury_cap, coin_metadata) = coin::create_currency<ITS_EXAMPLE>(
witness,
decimals,
symbol,
name,
description,
icon_url,
ctx,
);

let singletonId = object::new(ctx);
let channel = channel::new(ctx);
transfer::share_object(Singleton {
id: singletonId,
channel,
treasury_cap: option::some(treasury_cap),
coin_metadata: option::some(coin_metadata),
token_id: option::none<TokenId>(),
});
}

public fun token_id(self: &Singleton): &TokenId {
self.token_id.borrow()
}

public fun mint(self: &mut Singleton, amount: u64, ctx: &mut TxContext): Coin<ITS_EXAMPLE> {
self.treasury_cap.borrow_mut().mint(amount, ctx)
}

public fun register_transaction(discovery: &mut RelayerDiscovery, singleton: &Singleton, its: &ITS) {
let mut arguments = vector::empty<vector<u8>>();

Expand Down Expand Up @@ -117,20 +151,29 @@ module example::its {
)
}

public fun send_interchain_transfer<T>(
singleton: &Singleton,
public fun register_coin(self: &mut Singleton, its: &mut ITS) {
let coin_info = coin_info::from_metadata(self.coin_metadata.extract(), 12);
let coin_management = coin_management::new_with_cap(self.treasury_cap.extract());

let token_id = service::register_coin(its, coin_info, coin_management);

self.token_id.fill(token_id);
}

public fun send_interchain_transfer(
self: &Singleton,
its: &mut ITS,
destination_chain: String,
destination_address: vector<u8>,
token_id: TokenId,
coin: Coin<T>,
coin: Coin<ITS_EXAMPLE>,
metadata: vector<u8>,
gas_service: &mut GasService,
gas: Coin<SUI>,
clock: &Clock,
ctx: &mut TxContext,
) {
service::interchain_transfer<T>(
let token_id = *self.token_id.borrow();
service::interchain_transfer<ITS_EXAMPLE>(
its,
token_id,
coin,
Expand All @@ -139,25 +182,25 @@ module example::its {
metadata,
gas_service,
gas,
&singleton.channel,
&self.channel,
clock,
ctx,
);
}

public fun execute_interchain_transfer<T>(
public fun execute_interchain_transfer(
approved_message: ApprovedMessage,
singleton: &mut Singleton,
its: &mut ITS,
clock: &Clock,
ctx: &mut TxContext
): Coin<T> {
): Coin<ITS_EXAMPLE> {
let (
source_chain,
source_address,
data,
coin,
) = service::receive_interchain_transfer_with_data<T>(
) = service::receive_interchain_transfer_with_data<ITS_EXAMPLE>(
its,
approved_message,
&singleton.channel,
Expand Down
10 changes: 4 additions & 6 deletions move/governance/sources/governance/governance.move
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public fun is_governance(
entry fun take_upgrade_cap(self: &mut Governance, upgrade_cap: UpgradeCap) {
is_cap_new(&upgrade_cap);

self
.caps
.add(
object::id(&upgrade_cap),
upgrade_cap,
)
self.caps.add(
object::id(&upgrade_cap),
upgrade_cap,
)
}

public fun authorize_upgrade(
Expand Down
6 changes: 4 additions & 2 deletions move/its/sources/service.move
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ module its::service {

public fun register_coin<T>(
self: &mut ITS, coin_info: CoinInfo<T>, coin_management: CoinManagement<T>
) {
): TokenId {
let token_id = token_id::from_coin_data(&coin_info, &coin_management);

self.add_registered_coin(token_id, coin_management, coin_info);

event::emit(CoinRegistered<T> {
token_id
})
});

token_id
}

public fun deploy_remote_interchain_token<T>(
Expand Down
Loading

0 comments on commit cca2132

Please sign in to comment.