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

feat: create gmp tracker event interface #186

Merged
merged 23 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions contracts/interfaces/IAxelarGMPTransfer.sol
npty marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
* @title IInterchainTransferSent
* @dev Interface for tracking asset value transfers using General Message Passing (GMP) calls in the Axelar Network.
* This interface defines an event that should be emitted when a GMP transfer is sent,
* allowing for standardized volume tracking across different implementations.
*/
interface IInterchainTransferSent {
/**
* @dev Emitted when a GMP transfer is sent, providing details for volume tracking.
* @param destinationChain The Axelar chain identifier of the destination chain.
* @param destinationContractAddress The address of the contract on the destination chain that receives the transfer.
* @param recipient The address of the final recipient of the transferred assets on the destination chain.
* @param token The address of the token contract on the source chain.
* @param amount The amount (in atomic units) of tokens transferred.
*/
event InterchainTransferSent(
string destinationChain,
string destinationContractAddress,
bytes recipient,
npty marked this conversation as resolved.
Show resolved Hide resolved
address token,
npty marked this conversation as resolved.
Show resolved Hide resolved
uint256 amount
);
}

/**
* @title IInterchainTransferReceived
* @dev Interface for tracking asset value transfers using General Message Passing (GMP) calls in the Axelar Network.
* This interface defines an event that should be emitted when a GMP transfer is received,
* allowing for standardized volume tracking across different implementations.
*/
interface IInterchainTransferReceived {
/**
* @dev Emitted when an interchain transfer is received, providing details for volume tracking.
* @param sourceChain The Axelar chain identifier of the source chain.
* @param sourceAddress The address of the contract that initiated the transfer on the source chain.
* @param sender The address of the sender in case it is different from the source contract address
* @param recipient The address of the final recipient of the transferred assets on the destination chain.
* @param token The address of the token contract on the destination chain.
* @param amount The amount (in atomic units) of tokens received.
*/
event InterchainTransferReceived(
string sourceChain,
string sourceAddress,
bytes sender,
bytes recipient,
npty marked this conversation as resolved.
Show resolved Hide resolved
address token,
npty marked this conversation as resolved.
Show resolved Hide resolved
uint256 amount
);
}
26 changes: 17 additions & 9 deletions contracts/test/executable/GMPExecutableWithTokenTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,40 @@
pragma solidity ^0.8.0;

import { AxelarGMPExecutableWithToken } from '../../executable/AxelarGMPExecutableWithToken.sol';
import { IInterchainTransferReceived } from '../../interfaces/IAxelarGMPTransfer.sol';

contract GMPExecutableWithTokenTest is AxelarGMPExecutableWithToken {
contract GMPExecutableWithTokenTest is AxelarGMPExecutableWithToken, IInterchainTransferReceived {
event Received(uint256 num);
event ReceivedWithToken(uint256 num, address tokenAddress, uint256 amount);

constructor(address gatewayAddress) AxelarGMPExecutableWithToken(gatewayAddress) {}

function _execute(
bytes32, /*commandId*/
string calldata, /*sourceChain*/
string calldata, /*sourceAddress*/
bytes32 /*commandId*/,
string calldata /*sourceChain*/,
string calldata /*sourceAddress*/,
bytes calldata payload
) internal override {
uint256 num = abi.decode(payload, (uint256));
emit Received(num);
}

function _executeWithToken(
bytes32, /*commandId*/
string calldata, /*sourceChain*/
string calldata, /*sourceAddress*/
bytes32 /*commandId*/,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) internal override {
uint256 num = abi.decode(payload, (uint256));
emit ReceivedWithToken(num, gatewayWithToken().tokenAddresses(tokenSymbol), amount);
// Emit InterchainTransferReceived event
emit InterchainTransferReceived(
npty marked this conversation as resolved.
Show resolved Hide resolved
sourceChain,
sourceAddress,
payload,
npty marked this conversation as resolved.
Show resolved Hide resolved
abi.encodePacked(address(this)),
gatewayWithToken().tokenAddresses(tokenSymbol),
amount
);
}
}
13 changes: 9 additions & 4 deletions test/executable/GMPExecutableWithToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ describe('GMPExecutableWithToken', () => {
);

await expect(execute)
.to.emit(GMPExecutableWithToken, 'ReceivedWithToken')
.withArgs(num, tokenA.address, swapAmount)
.to.emit(tokenA, 'Transfer')
.withArgs(destinationChainGateway.address, GMPExecutableWithToken.address, swapAmount);
.to.emit(GMPExecutableWithToken, 'InterchainTransferReceived')
.withArgs(
sourceChain,
userWallet.address.toString(),
payload,
GMPExecutableWithToken.address.toLowerCase(),
await destinationChainGateway.tokenAddresses(symbolA),
swapAmount,
);
});
});

Expand Down
Loading