Merge pull request #293 from connext/relayerfee-option

Relayerfee option
This commit is contained in:
Shriya Tyagi 2023-05-03 23:29:51 +05:30 committed by GitHub
commit c034cde7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 13 deletions

View File

@ -22,6 +22,7 @@ contract Helpers is DSMath, Basic {
* @param slippage Maximum amount of slippage the user will accept in BPS.
* @param relayerFee Relayer fee paid in origin native asset.
* @param callData Encoded calldata to send.
* @param nativeRelayerFee booleam choice for relayer fee asset selection.
*/
struct XCallParams {
uint32 destination;
@ -32,9 +33,10 @@ contract Helpers is DSMath, Basic {
uint256 slippage;
uint256 relayerFee;
bytes callData;
bool nativeRelayerFee;
}
function _xcall(XCallParams memory params) internal {
function _xcallFeeNativeAsset(XCallParams memory params) internal {
connext.xcall{ value: params.relayerFee }(
params.destination,
params.to,
@ -45,4 +47,17 @@ contract Helpers is DSMath, Basic {
params.callData
);
}
function _xcallFeeTransactingAsseet(XCallParams memory params) internal {
connext.xcall(
params.destination,
params.to,
params.asset,
params.delegate,
params.amount - params.relayerFee,
params.slippage,
params.callData,
params.relayerFee
);
}
}

View File

@ -2,13 +2,26 @@
pragma solidity ^0.7.0;
interface IConnext {
function xcall(
uint32 _destination,
address _to,
address _asset,
address _delegate,
uint256 _amount,
uint256 _slippage,
bytes calldata _callData
) external payable returns (bytes32);
// ============ BRIDGE ==============
function xcall(
uint32 _destination,
address _to,
address _asset,
address _delegate,
uint256 _amount,
uint256 _slippage,
bytes calldata _callData
) external payable returns (bytes32);
function xcall(
uint32 _destination,
address _to,
address _asset,
address _delegate,
uint256 _amount,
uint256 _slippage,
bytes calldata _callData,
uint256 _relayerFee
) external returns (bytes32);
}

View File

@ -45,7 +45,14 @@ abstract contract ConnextResolver is Helpers {
params.amount = _amount;
approve(tokenContract, connextAddr, _amount);
_xcall(params);
/// check if user provided relayerFee under native asset or transacting asset
if(params.nativeRelayerFee){
_xcallFeeNativeAsset(params);
}
else{
_xcallFeeTransactingAsseet(params);
}
setUint(setId, _amount);
_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)";

View File

@ -97,6 +97,7 @@ describe("Connext Connector [Optimism]", () => {
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const nativeRelayerFee = true;
const xcallParams: any = [
domainId,
@ -106,7 +107,8 @@ describe("Connext Connector [Optimism]", () => {
amount,
slippage,
relayerFee,
callData
callData,
nativeRelayerFee
];
const spells = [
@ -127,6 +129,7 @@ describe("Connext Connector [Optimism]", () => {
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const nativeRelayerFee = true;
const xcallParams: any = [
domainId,
@ -136,7 +139,40 @@ describe("Connext Connector [Optimism]", () => {
amount,
slippage,
relayerFee,
callData
callData,
nativeRelayerFee
];
const spells = [
{
connector: connectorName,
method: "xcall",
args: [xcallParams, 0, 0]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address);
const receipt = await tx.wait();
});
it("should xcall with usdc, relayerfee using transacting asset", async () => {
const amount = ethers.utils.parseUnits("5", 6);
const domainId = 6648936;
const slippage = 10000;
const relayerFee = ethers.utils.parseEther("1");
const callData = "0x";
const nativeRelayerFee = false;
const xcallParams: any = [
domainId,
wallet1.address,
usdcAddr,
wallet1.address,
amount,
slippage,
relayerFee,
callData,
nativeRelayerFee
];
const spells = [