Skip to content

Commit

Permalink
eth v1 contract
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
buck54321 committed Nov 13, 2024
1 parent 96ef8ee commit f7c5296
Show file tree
Hide file tree
Showing 47 changed files with 4,435 additions and 1,880 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ client/cmd/translationsreport/translationsreport
client/cmd/translationsreport/worksheets
server/cmd/dexadm/dexadm
server/cmd/geogame/geogame
server/cmd/dcrdex/evm-protocol-overrides.json
13 changes: 8 additions & 5 deletions client/asset/eth/cmd/getgas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func mainErr() error {
flag.BoolVar(&useMainnet, "mainnet", false, "use mainnet")
flag.BoolVar(&useTestnet, "testnet", false, "use testnet")
flag.BoolVar(&useSimnet, "simnet", false, "use simnet")
flag.BoolVar(&trace, "trace", false, "use simnet")
flag.BoolVar(&debug, "debug", false, "use simnet")
flag.BoolVar(&trace, "trace", false, "use trace logging")
flag.BoolVar(&debug, "debug", false, "use debug logging")
flag.IntVar(&maxSwaps, "n", 5, "max number of swaps per transaction. minimum is 2. test will run from 2 swap up to n swaps.")
flag.StringVar(&chain, "chain", "eth", "symbol of the base chain")
flag.StringVar(&token, "token", "", "symbol of the token. if token is not specified, will check gas for base chain")
Expand Down Expand Up @@ -125,7 +125,8 @@ func mainErr() error {

wParams := new(eth.GetGasWalletParams)
wParams.BaseUnitInfo = bui
if token != chain {
isToken := token != chain
if isToken {
var exists bool
tkn, exists := tokens[assetID]
if !exists {
Expand All @@ -139,16 +140,18 @@ func mainErr() error {
}
swapContract, exists := netToken.SwapContracts[contractVer]
if !exists {
return nil, fmt.Errorf("no verion %d contract for %s token on %s network %s", contractVer, tkn.Name, chain, net)
return nil, fmt.Errorf("no version %d contract for %s token on %s network %s", contractVer, tkn.Name, chain, net)
}
wParams.Gas = &swapContract.Gas
} else {
wParams.UnitInfo = bui
g, exists := gases[contractVer]
if !exists {
return nil, fmt.Errorf("no verion %d contract for %s network %s", contractVer, chain, net)
return nil, fmt.Errorf("no version %d contract for %s network %s", contractVer, chain, net)
}
wParams.Gas = g
}
if !isToken || contractVer == 1 {
cs, exists := contracts[contractVer]
if !exists {
return nil, fmt.Errorf("no version %d base chain swap contract on %s", contractVer, chain)
Expand Down
Loading

0 comments on commit f7c5296

Please sign in to comment.