11

Several Ethereum projects use DSProxy to make their protocols more user-friendly. What is DSProxy exactly and how does it work?

1
  • 1
    Update 2022: I ended up building an improved version of DSProxy called PRBProxy. Check it out on GitHub! Commented Apr 6, 2022 at 9:24

1 Answer 1

20

What

DSProxy is a smart wallet built by DappHub that enables developers to execute multiple contract calls in one transaction. This is something that vanilla EOAs can't do; they are limited to interacting with only one contract per transaction.

How

I will explain how you can integrate DSProxy in your project. There are three contracts to be aware of:

  1. DSProxy registry
  2. The DSProxy itself
  3. Target contract with scripts (your custom business logic)

Integrating DSProxy in your project begins with the so-called "proxy registry" contract. This is a factory contract meant to deploy an instance of DSProxy so that you don't have to compile it yourself. MakerDAO (the organisation that created the DSProxy) has deployed the registry at address 0x4678f0a6958e4d2bc4f1baf7bc52e8f3564f3fe4 on Ethereum Mainnet. You simply call the build function and a DSProxy that belongs to msg.sender will be created for you.

Then, there's the target contract. This is where you have to write code. The idea is that you import your contract interfaces and bundle multiple contract calls in one function. For example, this is how a script that makes a deposit in the Compound protocol would look like:

function deposit(
    address token,
    address cToken,
    uint256 amount
) external {
    Erc20Interface(token).transferFrom(msg.sender, address(this), amount);
    Erc20Interface(token).approve(cToken, uint256(-1));
    require(CTokenInterface(cToken).mint(amount) == 0);
}

You would compile your target contract, deploy it to Ethereum and call the execute function of the DSProxy function execute(address _target, bytes memory _data) to finally make the contract call. The _target argument is the address of the target contract, while _data is the the calldata used to identify what function to execute on the target. If you don't know what calldata is, see this thread.

Integrations

DSProxy is running in production in several Ethereum projects:

Note that because the registry caches deployments, it follows that if you use only one of the apps above, you won't have to re-deploy your DSProxy when using the other apps. Decentralised finance FTW!

Further Reading

My answer is but a a high-level overview of DSProxy. To learn more refer to the following resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.