4

dYdX has an event called LogDeposit(address indexed accountOwner, uint256 accountNumber, uint256 market, BalanceUpdate update, address from) within their SoloMargin contract. I am trying to get the signature hash for this using the following code:

from Crypto.Hash import keccak
keccak_hash = keccak.new(digest_bits=256)
keccak_hash.update(b'LogDeposit(address,uint256,uint256,BalanceUpdate,address)')
print(keccak_hash.hexdigest())

This produces the following signature hash: ad66b490ac5d24d41e7e33a2a9ac6645bf66b577553f31d1e2917df2f83f15a6. However, I do not think it is right. When I search for this topic in etherscan nothing is returned.

I am wondering if it has to do with the BalanceUpdate parameter. I am used to searching for the other types such as address and uint256, but this one I haven't seen and do not know if I am doing this right.

2
  • Can you edit your question to show what BalanceUpdate is composed of? dYdX contains many contracts, I'm not easily able to find it. Commented Nov 8, 2019 at 19:03
  • I updated the original question. It is within their Solo Margin contract. The Balance update is a struct that contains the following: ` struct BalanceUpdate { Types.Wei deltaWei; Types.Par; }`
    – Brandon
    Commented Nov 8, 2019 at 20:52

2 Answers 2

3

When calculating the signature of an event that uses structs, each struct is represented as a tuple of the types of the variables it contains. To create the tuple for your question, we need to look at the source of SoloMargin.

Based on the source published to Etherscan, I extracted the code needed to create the event:

pragma solidity 0.5.7;
pragma experimental ABIEncoderV2;

contract SoloMiningLogEvent {

    struct Wei {
        bool sign;
        uint256 value;
    }

    struct Par {
        bool sign;
        uint128 value;
    }

    struct BalanceUpdate {
        Wei deltaWei;
        Par newPar;
    }

    event LogDeposit(
        address indexed accountOwner,
        uint256 accountNumber,
        uint256 market,
        BalanceUpdate update,
        address from
    );

}

We can see that BalanceUpdate is composed of two structs:

  • Wei, a tuple of (bool,uint256)
  • Par, a tuple of (bool,uint128)

So our tuple representation for BalanceUpdate is:

((bool,uint256),(bool,uint128))

Thus the entire signature to generate the hash is written as:

LogDeposit(address,uint256,uint256,((bool,uint256),(bool,uint128)),address)

which results in a hash of:

0x2bad8bc95088af2c247b30fa2b2e6a0886f88625e0945cd3051008e0e270198f
0
3

This event's signature is:

0x2bad8bc95088af2c247b30fa2b2e6a0886f88625e0945cd3051008e0e270198f

This is keccak256 hash of the following string:

LogDeposit(address,uint256,uint256,((bool,uint256),(bool,uint128)),address)

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.