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(GasService): adding express methods #237

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions contracts/gas-service/AxelarGasService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ contract AxelarGasService is Upgradable, IAxelarGasService {
);
}

function payGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external override {
IERC20(gasToken).safeTransferFrom(msg.sender, address(this), gasFeeAmount);

emit GasPaidForExpressCall(sender, destinationChain, destinationAddress, keccak256(payload), gasToken, gasFeeAmount, refundAddress);
}

// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForExpressCallWithToken(
address sender,
Expand Down Expand Up @@ -139,6 +153,18 @@ contract AxelarGasService is Upgradable, IAxelarGasService {
);
}

function payNativeGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable override {
if (msg.value == 0) revert NothingReceived();

emit NativeGasPaidForExpressCall(sender, destinationChain, destinationAddress, keccak256(payload), msg.value, refundAddress);
}

// This is called on the source chain before calling the gateway to execute a remote contract.
function payNativeGasForExpressCallWithToken(
address sender,
Expand Down
39 changes: 39 additions & 0 deletions contracts/interfaces/IAxelarGasService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
);

event GasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);

event GasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
Expand All @@ -64,6 +74,15 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
);

event NativeGasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);

event NativeGasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
Expand Down Expand Up @@ -129,6 +148,17 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
) external payable;

// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;

// This is called on the source chain before calling the gateway to execute a remote contract.
function payGasForExpressCallWithToken(
address sender,
Expand All @@ -142,6 +172,15 @@ interface IAxelarGasService is IUpgradable {
address refundAddress
) external;

// This is called on the source chain before calling the gateway to execute a remote contract.
function payNativeGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;

// This is called on the source chain before calling the gateway to execute a remote contract.
function payNativeGasForExpressCallWithToken(
address sender,
Expand Down
35 changes: 35 additions & 0 deletions test/gmp/AxelarGasService.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ describe('AxelarGasService', () => {
)
.and.to.changeEtherBalance(gasService, nativeGasFeeAmount);

await expect(
gasService
.connect(userWallet)
.payGasForExpressCall(
userWallet.address,
destinationChain,
destinationAddress,
payload,
gasToken,
gasFeeAmount,
userWallet.address,
),
)
.to.emit(gasService, 'GasPaidForExpressCall')
.withArgs(userWallet.address, destinationChain, destinationAddress, payloadHash, gasToken, gasFeeAmount, userWallet.address)
.and.to.emit(testToken, 'Transfer')
.withArgs(userWallet.address, gasService.address, gasFeeAmount);

await expect(
gasService
.connect(userWallet)
Expand Down Expand Up @@ -186,6 +204,17 @@ describe('AxelarGasService', () => {
.and.to.emit(testToken, 'Transfer')
.withArgs(userWallet.address, gasService.address, gasFeeAmount);

await expect(
await gasService
.connect(userWallet)
.payNativeGasForExpressCall(userWallet.address, destinationChain, destinationAddress, payload, userWallet.address, {
value: nativeGasFeeAmount,
}),
)
.to.emit(gasService, 'NativeGasPaidForExpressCall')
.withArgs(userWallet.address, destinationChain, destinationAddress, payloadHash, nativeGasFeeAmount, userWallet.address)
.and.to.changeEtherBalance(gasService, nativeGasFeeAmount);

await expect(
await gasService
.connect(userWallet)
Expand Down Expand Up @@ -246,6 +275,12 @@ describe('AxelarGasService', () => {
),
).to.be.revertedWithCustomError(gasService, 'NothingReceived');

await expect(
gasService
.connect(userWallet)
.payNativeGasForExpressCall(userWallet.address, destinationChain, destinationAddress, payload, userWallet.address),
).to.be.revertedWithCustomError(gasService, 'NothingReceived');

await expect(
gasService
.connect(userWallet)
Expand Down
Loading