Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/axelar_gateway_e…
Browse files Browse the repository at this point in the history
…vent_checking
  • Loading branch information
Foivos committed Nov 20, 2024
2 parents b28be61 + 409d52f commit d65578f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-dots-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': minor
---

Paying for gas now requires the message ticket instead of the call information.
2 changes: 1 addition & 1 deletion move/example/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.35.2" }
AxelarGateway = { local = "../axelar_gateway" }
GasService = { local = "../gas_service" }
AxelarGateway = { local = "../axelar_gateway" }
Utils = { local = "../utils" }
VersionControl = { local = "../version_control" }
ITS = { local = "../its" }
Expand Down
17 changes: 8 additions & 9 deletions move/example/sources/gmp/gmp.move
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,19 @@ public fun send_call(
coin: Coin<SUI>,
params: vector<u8>,
) {
gas_service.pay_gas(
coin,
sui::object::id_address(&singleton.channel),
destination_chain,
destination_address,
payload,
refund_address,
params,
);

let message_ticket = gateway::prepare_message(
&singleton.channel,
destination_chain,
destination_address,
payload,
);

gas_service.pay_gas(
&message_ticket,
coin,
refund_address,
params,
);

gateway.send_message(message_ticket);
Expand Down
5 changes: 1 addition & 4 deletions move/example/sources/its/its.move
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,8 @@ fun pay_gas_and_send_message(
gas_params: vector<u8>,
) {
gas_service.pay_gas(
&message_ticket,
gas,
message_ticket.source_id(),
message_ticket.destination_chain(),
message_ticket.destination_address(),
message_ticket.payload(),
refund_address,
gas_params,
);
Expand Down
24 changes: 22 additions & 2 deletions move/gas_service/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

[move]
version = 3
manifest_digest = "C29AEC3A18805EA1C5A2FCA5811D6AAD6BE44E394A8FDF0B02FB34D3409F4D3E"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
manifest_digest = "C04CC08DC1212FBCB4F5A869F32A9607A3C3E3586BC3BEFC0C0F1DBD3CE563CE"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ id = "AxelarGateway", name = "AxelarGateway" },
{ id = "Sui", name = "Sui" },
{ id = "VersionControl", name = "VersionControl" },
]

[[move.package]]
id = "AxelarGateway"
source = { local = "../axelar_gateway" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "Utils", name = "Utils" },
{ id = "VersionControl", name = "VersionControl" },
]

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

[[move.package]]
id = "Utils"
source = { local = "../utils" }

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

[[move.package]]
id = "VersionControl"
source = { local = "../version_control" }
Expand Down
1 change: 1 addition & 0 deletions move/gas_service/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024.beta"
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.35.2" }
VersionControl = { local = "../version_control" }
AxelarGateway = { local = "../axelar_gateway" }

[addresses]
gas_service = "0xa2"
29 changes: 17 additions & 12 deletions move/gas_service/sources/gas_service.move
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module gas_service::gas_service;

use axelar_gateway::message_ticket::MessageTicket;
use gas_service::gas_service_v0::{Self, GasService_v0};
use std::ascii::{Self, String};
use sui::coin::Coin;
Expand Down Expand Up @@ -71,22 +72,16 @@ macro fun value_mut(
/// setting the sender as the channel ID.
public fun pay_gas(
self: &mut GasService,
message_ticket: &MessageTicket,
coin: Coin<SUI>,
sender: address,
destination_chain: String,
destination_address: String,
payload: vector<u8>,
refund_address: address,
params: vector<u8>,
) {
self
.value_mut!(b"pay_gas")
.pay_gas(
message_ticket,
coin,
sender,
destination_chain,
destination_address,
payload,
refund_address,
params,
);
Expand Down Expand Up @@ -220,21 +215,31 @@ fun test_pay_gas() {
let digest = ctx.digest();
let value = (((digest[0] as u16) << 8) | (digest[1] as u16) as u64) + 1;
let c: Coin<SUI> = coin::mint_for_testing(value, ctx);
let channel = axelar_gateway::channel::new(ctx);
let destination_chain = b"destination chain".to_ascii_string();
let destination_address = b"destination address".to_ascii_string();
let payload = b"payload";

let ticket = axelar_gateway::gateway::prepare_message(
&channel,
destination_chain,
destination_address,
payload,
);

service.pay_gas(
&ticket,
c,
ctx.sender(),
std::ascii::string(b"destination chain"),
std::ascii::string(b"destination address"),
vector[],
ctx.sender(),
vector[],
);

assert!(service.value!().balance().value() == value);

cap.destroy_cap();
service.destroy();
channel.destroy();
sui::test_utils::destroy(ticket);
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions move/gas_service/sources/versioned/gas_service_v0.move
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module gas_service::gas_service_v0;

use axelar_gateway::message_ticket::MessageTicket;
use gas_service::events;
use std::ascii::String;
use sui::address;
Expand Down Expand Up @@ -33,23 +34,22 @@ public(package) fun version_control(self: &GasService_v0): &VersionControl {

public(package) fun pay_gas(
self: &mut GasService_v0,
message_ticket: &MessageTicket,
coin: Coin<SUI>,
sender: address,
destination_chain: String,
destination_address: String,
payload: vector<u8>,
refund_address: address,
params: vector<u8>,
) {
let coin_value = coin.value();
self.put(coin);

let payload_hash = address::from_bytes(keccak256(&payload));
let payload_hash = address::from_bytes(
keccak256(&message_ticket.payload()),
);

events::gas_paid<SUI>(
sender,
destination_chain,
destination_address,
message_ticket.source_id(),
message_ticket.destination_chain(),
message_ticket.destination_address(),
payload_hash,
coin_value,
refund_address,
Expand Down

0 comments on commit d65578f

Please sign in to comment.