Skip to content

Commit

Permalink
dex/networks/eth: ETH fidelity bonds contract
Browse files Browse the repository at this point in the history
This diff introduces the solidity contract that supports posting fidelity
bonds on ETH.
  • Loading branch information
martonp committed Mar 22, 2024
1 parent d85fa03 commit 25f61a7
Show file tree
Hide file tree
Showing 10 changed files with 1,174 additions and 0 deletions.
47 changes: 47 additions & 0 deletions dex/networks/eth/bondcontracts/updatecontract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# This script does 3 things:
#
# 1. Updates contract.go to reflect updated solidity code.
# 2. Generates the runtime bytecoode. This is used to compare against the runtime
# bytecode on chain in order to verify that the expected contract is deployed.
# 3. Updates the bytecode in the harness test.

if [ "$#" -ne 1 ]
then
echo "Usage: $0 version" >&2
exit 1
fi

VERSION=$1
PKG_NAME=v${VERSION}
CONTRACT_NAME=ETHBond
SOLIDITY_FILE=./v${VERSION}/contracts/${CONTRACT_NAME}V${VERSION}.sol
if [ ! -f ${SOLIDITY_FILE} ]
then
echo "${SOLIDITY_FILE} does not exist" >&2
exit 1
fi

mkdir temp

solc --abi --bin --bin-runtime --overwrite --optimize ${SOLIDITY_FILE} -o ./temp/
BYTECODE=$(<./temp/${CONTRACT_NAME}.bin-runtime)

cat > "./${PKG_NAME}/BinRuntimeV${VERSION}.go" <<EOF
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package ${PKG_NAME}
const ${CONTRACT_NAME}RuntimeBin = "${BYTECODE}"
EOF

abigen --abi ./temp/${CONTRACT_NAME}.abi --bin ./temp/${CONTRACT_NAME}.bin --pkg ${PKG_NAME} \
--type ${CONTRACT_NAME} --out ./${PKG_NAME}/contract.go

BYTECODE=$(<./temp/${CONTRACT_NAME}.bin)
sed -i.tmp "s/BOND_V${VERSION}=.*/BOND_V${VERSION}=\"${BYTECODE}\"/" ../../../testing/eth/harness.sh
# mac needs a temp file specified above.
rm ../../../testing/eth/harness.sh.tmp

rm -fr temp
12 changes: 12 additions & 0 deletions dex/networks/eth/bondcontracts/v0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# dependencies
/node_modules
/typechain-types

# build artifacts
/artifacts
/cache

# local network
/.hardhat

package-lock.json
6 changes: 6 additions & 0 deletions dex/networks/eth/bondcontracts/v0/BinRuntimeV0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 25f61a7

Please sign in to comment.