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/add gas #106

Merged
merged 4 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions contracts/gas-service/AxelarGasService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ contract AxelarGasService is Upgradable, IAxelarGasService {
);
}

function addGas(
bytes32 txHash,
uint256 logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external override {
_safeTransferFrom(gasToken, msg.sender, gasFeeAmount);

emit GasAdded(txHash, logIndex, gasToken, gasFeeAmount, refundAddress);
}

function addNativeGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable override {
if (msg.value == 0) revert NothingReceived();

emit NativeGasAdded(txHash, logIndex, msg.value, refundAddress);
}

function collectFees(address payable receiver, address[] calldata tokens) external onlyOwner {
for (uint256 i; i < tokens.length; i++) {
address token = tokens[i];
Expand Down
18 changes: 18 additions & 0 deletions contracts/interfaces/IAxelarGasService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
);

event GasAdded(bytes32 indexed txHash, uint256 indexed logIndex, address gasToken, uint256 gasFeeAmount, address refundAddress);

event NativeGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);

// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForContractCall(
address sender,
Expand Down Expand Up @@ -95,6 +99,20 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
) external payable;

function addGas(
bytes32 txHash,
uint256 txIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;

function addNativeGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;

function collectFees(address payable receiver, address[] calldata tokens) external;

function refund(
Expand Down
21 changes: 21 additions & 0 deletions test/gmp/AxelarGasService.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,25 @@ describe('AxelarGasService', () => {
await expect(await gasService.owner()).to.be.equal(userWallet.address);
});
});

it('should emit events when gas is added', async () => {
const txHash = keccak256(defaultAbiCoder.encode(['string'], ['random tx hash']));
const logIndex = 13;
const gasToken = testToken.address;
const gasFeeAmount = 1000;
const nativeGasFeeAmount = parseEther('1.0');

await testToken.connect(userWallet).approve(gasService.address, 1e6);

await expect(gasService.connect(userWallet).addGas(txHash, logIndex, gasToken, gasFeeAmount, userWallet.address))
.to.emit(gasService, 'GasAdded')
.withArgs(txHash, logIndex, gasToken, gasFeeAmount, userWallet.address)
.and.to.emit(testToken, 'Transfer')
.withArgs(userWallet.address, gasService.address, gasFeeAmount);

await expect(await gasService.connect(userWallet).addNativeGas(txHash, logIndex, userWallet.address, { value: nativeGasFeeAmount }))
.to.emit(gasService, 'NativeGasAdded')
.withArgs(txHash, logIndex, nativeGasFeeAmount, userWallet.address)
.and.to.changeEtherBalance(gasService, nativeGasFeeAmount);
});
});