mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	
		
			
				
	
	
	
		
			2.8 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			2.8 KiB
		
	
	
	
	
	
	
	
How to add a new connector
You can create a new PR to add a new connector. To get the PR merged, certain requirements needs to be met which will be explained here.
New connector should follow the current directory structure
Common files for all connectors are in contracts/common directory.
- math.solhas methods for mathematical operations (- DSMath)
- interfaces.solcontains the common interfaces- TokenInterfacefor ERC-20 interface including WETH
 
- stores.solcontains the global constants as well as methods- getId&- setId(- Stores)
- basic.solinherits- DSMath&- Storescontracts. This contains few details explained below- Wrapping & unwrapping ETH (convertEthToWeth&convertWethToEth)
- Getting token & ETH balance of DSA
 
- Wrapping & unwrapping ETH (
Connectors are under contracts/connectors directory, and should be formatted as follows:
- Connector events should be in a separate contract: events.sol
- Interfaces should be defined in a seperate file: interface.sol
- If the connector has helper methods & constants (including interface instances), this should be defined in a separate file: helpers.sol- Helperscontract should inherit- Basiccontract from common directory
- If the connector doesn't have any helper methods, the main contract should inherit Basiccontract
 
- The main logic of the contract should be under main.sol, and the contract should inheritHelpers(if exists, otherwiseBasic) &Events
Few things to consider while writing the connector:
- Connector should have a public string declared name, which will be the name of the connector. This will be versioned. Ex:Compound-v1
- User interacting methods (externalmethods) will not be emitting events, rather the methods will be returning 2 variables:- _eventNameof- stringtype: This will be the event signture defined in the- Eventscontract. Ex:- LogDeposit(address,address,uint256,uint256,uint256)
- _eventParamof- bytestype: This will be the abi encoded event parameters
 
- The contracts should not have selfdestruct()
- The contracts should not have delegatecall()
- Use uint(-1)oftype(uint256).maxfor maximum amount everywhere
- Use ethAddr(declared inStores) to denote Ethereum (non-ERC20)
- Use address(this)instead ofmsg.senderfor fetching balance on-chain, etc
- Only approve()limited amount while giving ERC20 allowance, which strictly needs to be 0 by the end of the spell.
- Use getUint()(declared inStores) for getting value that saved from previous spell
- Use setUint()(declared inStores) for setting value to save for the future spell
Support
If you can't find something you're looking for or have any questions, ask them at our developers community on Discord or simply send an Email.
