Skip to content

Commit 01ef6ca

Browse files
committed
eth v1 contract
Implements the version 1 contracts for ethereum and tokens. Based on feedback in #1426, everything is now encoded in the "contract data". This "contract data", is the msgjson.Init.Contract -> msgjson.Audit.Contract -> MatchMetaData.Proof.CounterContract, AuditInfo.Contract -> Redemption.Spends.Contract. A few new terms are introduced to differentiate various encodings and data sets. The aforementioned contract data did encode a version and a secret hash. It now encodes a version and a "locator", which is a []byte whose length and content depend on the version. For version 0, the locator is still just the secretHash[:]. For v1, the locator encodes all of the immutable data that defines the swap. This immutable data is now collected in something called a "vector" (dexeth.SwapVector). For version 0, some vector data is stored on-chain indexed by the secret hash. For version 1, all vector data is encoded in the locator. I've also made an effort to standardize the use of status/step, and eliminated the use of ambiguous "ver" variables throughout. A "status" is now the collection of mutable contract data: the step, the init block height, and the secret. The status and vector collectively fully characterize the swap. client/asset/eth: New contractV1 and tokenContractorV1 interfaces. To avoid duplication, the ERC20 parts of the tokenContractors are separated into a new type erc20Contractor that is embedded by both versions. Getters for status and vector are added in place of the old method "swap". assetWallet and embedding types are updated to work with the new version-dependent locators and the status and vector model. dex/networks/{eth,erc20}: New contracts added. New methods for dealing with locators. Simnet entries added for eth and dextt.eth in the ContractAddresses and Tokens maps. txDataHandler interace is replaced with versioned package-level functions. server/asset/eth: Server is fully switched to version 1. No option to use version 0. Translation to new version was straightforward, with one notable difference that we can no longer get a block height from the contract once the swap is redeemed.
1 parent 05d7092 commit 01ef6ca

47 files changed

Lines changed: 4435 additions & 1880 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ server/cmd/dexadm/dexadm
5151
client/tor/build
5252
server/cmd/geogame/geogame
5353
internal/libsecp256k1/secp256k1
54+
server/cmd/dcrdex/evm-protocol-overrides.json

client/asset/eth/cmd/getgas/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func mainErr() error {
4848
flag.BoolVar(&useMainnet, "mainnet", false, "use mainnet")
4949
flag.BoolVar(&useTestnet, "testnet", false, "use testnet")
5050
flag.BoolVar(&useSimnet, "simnet", false, "use simnet")
51-
flag.BoolVar(&trace, "trace", false, "use simnet")
52-
flag.BoolVar(&debug, "debug", false, "use simnet")
51+
flag.BoolVar(&trace, "trace", false, "use trace logging")
52+
flag.BoolVar(&debug, "debug", false, "use debug logging")
5353
flag.IntVar(&maxSwaps, "n", 5, "max number of swaps per transaction. minimum is 2. test will run from 2 swap up to n swaps.")
5454
flag.StringVar(&chain, "chain", "eth", "symbol of the base chain")
5555
flag.StringVar(&token, "token", "", "symbol of the token. if token is not specified, will check gas for base chain")
@@ -125,7 +125,8 @@ func mainErr() error {
125125

126126
wParams := new(eth.GetGasWalletParams)
127127
wParams.BaseUnitInfo = bui
128-
if token != chain {
128+
isToken := token != chain
129+
if isToken {
129130
var exists bool
130131
tkn, exists := tokens[assetID]
131132
if !exists {
@@ -139,16 +140,18 @@ func mainErr() error {
139140
}
140141
swapContract, exists := netToken.SwapContracts[contractVer]
141142
if !exists {
142-
return nil, fmt.Errorf("no verion %d contract for %s token on %s network %s", contractVer, tkn.Name, chain, net)
143+
return nil, fmt.Errorf("no version %d contract for %s token on %s network %s", contractVer, tkn.Name, chain, net)
143144
}
144145
wParams.Gas = &swapContract.Gas
145146
} else {
146147
wParams.UnitInfo = bui
147148
g, exists := gases[contractVer]
148149
if !exists {
149-
return nil, fmt.Errorf("no verion %d contract for %s network %s", contractVer, chain, net)
150+
return nil, fmt.Errorf("no version %d contract for %s network %s", contractVer, chain, net)
150151
}
151152
wParams.Gas = g
153+
}
154+
if !isToken || contractVer == 1 {
152155
cs, exists := contracts[contractVer]
153156
if !exists {
154157
return nil, fmt.Errorf("no version %d base chain swap contract on %s", contractVer, chain)

0 commit comments

Comments
 (0)