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

fix(axelar-gas-service)!: fix axelar gas service pay_gas #83

Merged
merged 9 commits into from
Nov 25, 2024
19 changes: 11 additions & 8 deletions contracts/axelar-gas-service/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,37 @@ impl AxelarGasService {

#[contractimpl]
impl AxelarGasServiceInterface for AxelarGasService {
fn pay_gas_for_contract_call(
#[allow(clippy::too_many_arguments)]
fn pay_gas(
env: Env,
spender: Address,
sender: Address,
destination_chain: String,
destination_address: String,
payload: Bytes,
refund_address: Address,
token: Token,
refund_address: Address,
metadata: Bytes,
) -> Result<(), ContractError> {
sender.require_auth();
spender.require_auth();

ensure!(token.amount > 0, ContractError::InvalidAmount);

token::Client::new(&env, &token.address).transfer_from(
&env.current_contract_address(),
&sender,
token::Client::new(&env, &token.address).transfer(
&spender,
&env.current_contract_address(),
&token.amount,
);

event::gas_paid_for_contract_call(
event::gas_paid(
&env,
sender,
destination_chain,
destination_address,
payload,
refund_address,
token,
refund_address,
metadata,
);

Ok(())
Expand Down
16 changes: 9 additions & 7 deletions contracts/axelar-gas-service/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
use axelar_soroban_std::types::Token;
use soroban_sdk::{Address, Bytes, Env, String, Symbol};

pub fn gas_paid_for_contract_call(
#[allow(clippy::too_many_arguments)]
pub fn gas_paid(
env: &Env,
sender: Address,
destination_chain: String,
destination_address: String,
payload: Bytes,
refund_address: Address,
token: Token,
refund_address: Address,
metadata: Bytes,
) {
let topics = (
Symbol::new(env, "gas_paid"),
env.crypto().keccak256(&payload),
sender,
destination_chain,
destination_address,
env.crypto().keccak256(&payload),
token,
refund_address,
);
env.events().publish(
topics,
(destination_address, payload, refund_address, token),
);
env.events().publish(topics, (metadata,));
}

pub fn gas_added(env: &Env, message_id: String, token: Token, refund_address: Address) {
Expand Down
15 changes: 9 additions & 6 deletions contracts/axelar-gas-service/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ use crate::error::ContractError;

#[contractclient(name = "AxelarGasServiceClient")]
pub trait AxelarGasServiceInterface {
/// Pay for gas using a token for a contract call on a destination chain.
#[allow(clippy::too_many_arguments)]
/// Pay for gas using a token for sending a message on a destination chain.
///
/// This function is called on the source chain before calling the gateway to execute a remote contract.
fn pay_gas_for_contract_call(
/// This function is called on the source chain before calling the gateway to send a message.
ahramy marked this conversation as resolved.
Show resolved Hide resolved
fn pay_gas(
env: Env,
spender: Address,
sender: Address,
destination_chain: String,
destination_address: String,
payload: Bytes,
refund_address: Address,
token: Token,
ahramy marked this conversation as resolved.
Show resolved Hide resolved
refund_address: Address,
ahramy marked this conversation as resolved.
Show resolved Hide resolved
metadata: Bytes,
) -> Result<(), ContractError>;

/// Add additional gas payment after initiating a cross-chain call.
/// Add additional gas payment after initiating a cross-chain message.
fn add_gas(
env: Env,
sender: Address,
Expand All @@ -32,7 +35,7 @@ pub trait AxelarGasServiceInterface {
/// Only callable by the `gas_collector`.
fn collect_fees(env: Env, receiver: Address, token: Token) -> Result<(), ContractError>;

/// Refunds gas payment to the receiver in relation to a specific cross-chain transaction.
/// Refunds gas payment to the receiver in relation to a specific cross-chain message.
///
/// Only callable by the `gas_collector`.
fn refund(env: Env, message_id: String, receiver: Address, token: Token);
Expand Down
Loading
Loading