Skip to content

Commit

Permalink
feat(GasService): adding express methods (#237)
Browse files Browse the repository at this point in the history
* feat(GasService): adding express methods

* fix(GasService): slither event reentrancy fix

* update gmp sdk version

* update license

---------

Co-authored-by: Milap Sheth <milap@axelar.network>
  • Loading branch information
re1ro and milapsheth authored Aug 30, 2023
1 parent 10b89fb commit eb2ac72
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 14 deletions.
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 {
emit GasPaidForExpressCall(sender, destinationChain, destinationAddress, keccak256(payload), gasToken, gasFeeAmount, refundAddress);

IERC20(gasToken).safeTransferFrom(msg.sender, address(this), gasFeeAmount);
}

// 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 {
IERC20(gasToken).safeTransferFrom(msg.sender, address(this), gasFeeAmount);
}

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
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
"axelar"
],
"author": "axelar-network",
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/axelarnetwork/axelar-cgp-solidity/issues"
},
"homepage": "https://github.com/axelarnetwork/axelar-cgp-solidity#readme",
"dependencies": {
"@axelar-network/axelar-gmp-sdk-solidity": "5.1.0"
"@axelar-network/axelar-gmp-sdk-solidity": "5.2.0"
},
"devDependencies": {
"@axelar-network/axelar-contract-deployments": "git://github.com/axelarnetwork/axelar-contract-deployments.git#74b942fdf10875a27b532d9bd6dfe2bd6db8a094",
Expand All @@ -53,7 +53,7 @@
"solidity-coverage": "^0.8.4"
},
"engines": {
"node": "^16.0.0 || ^18.0.0"
"node": ">=16"
},
"files": [
"artifacts",
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

0 comments on commit eb2ac72

Please sign in to comment.