mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	Merge pull request #293 from connext/relayerfee-option
Relayerfee option
This commit is contained in:
		
						commit
						c034cde7b3
					
				|  | @ -22,6 +22,7 @@ contract Helpers is DSMath, Basic { | ||||||
| 	 * @param slippage Maximum amount of slippage the user will accept in BPS. | 	 * @param slippage Maximum amount of slippage the user will accept in BPS. | ||||||
| 	 * @param relayerFee Relayer fee paid in origin native asset. | 	 * @param relayerFee Relayer fee paid in origin native asset. | ||||||
| 	 * @param callData Encoded calldata to send. | 	 * @param callData Encoded calldata to send. | ||||||
|  | 	 * @param nativeRelayerFee booleam choice for relayer fee asset selection.  | ||||||
| 	 */ | 	 */ | ||||||
| 	struct XCallParams { | 	struct XCallParams { | ||||||
| 		uint32 destination; | 		uint32 destination; | ||||||
|  | @ -32,9 +33,10 @@ contract Helpers is DSMath, Basic { | ||||||
| 		uint256 slippage; | 		uint256 slippage; | ||||||
| 		uint256 relayerFee; | 		uint256 relayerFee; | ||||||
| 		bytes callData; | 		bytes callData; | ||||||
|  | 		bool nativeRelayerFee; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	function _xcall(XCallParams memory params) internal { | 	function _xcallFeeNativeAsset(XCallParams memory params) internal { | ||||||
| 		connext.xcall{ value: params.relayerFee }( | 		connext.xcall{ value: params.relayerFee }( | ||||||
| 			params.destination, | 			params.destination, | ||||||
| 			params.to, | 			params.to, | ||||||
|  | @ -45,4 +47,17 @@ contract Helpers is DSMath, Basic { | ||||||
| 			params.callData | 			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 | ||||||
|  | 		); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,13 +2,26 @@ | ||||||
| pragma solidity ^0.7.0; | pragma solidity ^0.7.0; | ||||||
| 
 | 
 | ||||||
| interface IConnext { | interface IConnext { | ||||||
| 	function xcall( |   // ============ BRIDGE ============== | ||||||
| 		uint32 _destination, | 
 | ||||||
| 		address _to, |   function xcall( | ||||||
| 		address _asset, |     uint32 _destination, | ||||||
| 		address _delegate, |     address _to, | ||||||
| 		uint256 _amount, |     address _asset, | ||||||
| 		uint256 _slippage, |     address _delegate, | ||||||
| 		bytes calldata _callData |     uint256 _amount, | ||||||
| 	) external payable returns (bytes32); |     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); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -45,7 +45,14 @@ abstract contract ConnextResolver is Helpers { | ||||||
| 
 | 
 | ||||||
| 		params.amount = _amount; | 		params.amount = _amount; | ||||||
| 		approve(tokenContract, connextAddr, _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); | 		setUint(setId, _amount); | ||||||
| 		_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)"; | 		_eventName = "LogXCall(uint32,address,address,address,uint256,uint256,uint256,uint256)"; | ||||||
|  |  | ||||||
|  | @ -97,6 +97,7 @@ describe("Connext Connector [Optimism]", () => { | ||||||
|       const slippage = 10000; |       const slippage = 10000; | ||||||
|       const relayerFee = ethers.utils.parseEther("1"); |       const relayerFee = ethers.utils.parseEther("1"); | ||||||
|       const callData = "0x"; |       const callData = "0x"; | ||||||
|  |       const nativeRelayerFee = true; | ||||||
| 
 | 
 | ||||||
|       const xcallParams: any = [ |       const xcallParams: any = [ | ||||||
|         domainId, |         domainId, | ||||||
|  | @ -106,7 +107,8 @@ describe("Connext Connector [Optimism]", () => { | ||||||
|         amount, |         amount, | ||||||
|         slippage, |         slippage, | ||||||
|         relayerFee, |         relayerFee, | ||||||
|         callData |         callData, | ||||||
|  |         nativeRelayerFee | ||||||
|       ]; |       ]; | ||||||
| 
 | 
 | ||||||
|       const spells = [ |       const spells = [ | ||||||
|  | @ -127,6 +129,7 @@ describe("Connext Connector [Optimism]", () => { | ||||||
|       const slippage = 10000; |       const slippage = 10000; | ||||||
|       const relayerFee = ethers.utils.parseEther("1"); |       const relayerFee = ethers.utils.parseEther("1"); | ||||||
|       const callData = "0x"; |       const callData = "0x"; | ||||||
|  |       const nativeRelayerFee = true; | ||||||
| 
 | 
 | ||||||
|       const xcallParams: any = [ |       const xcallParams: any = [ | ||||||
|         domainId, |         domainId, | ||||||
|  | @ -136,7 +139,40 @@ describe("Connext Connector [Optimism]", () => { | ||||||
|         amount, |         amount, | ||||||
|         slippage, |         slippage, | ||||||
|         relayerFee, |         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 = [ |       const spells = [ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Shriya Tyagi
						Shriya Tyagi