feat: Add Cargo files, CI, configs and README

This commit is contained in:
Diana Carvalho
2025-01-16 12:53:28 +00:00
parent a2784be122
commit c27b253ef5
17 changed files with 3980 additions and 1 deletions

3
.cargo/config.toml Normal file
View File

@@ -0,0 +1,3 @@
[build]
# this flag is used to build tokio-console correctly.
rustflags = ["--cfg", "tokio_unstable"]

1
.clippy.toml Normal file
View File

@@ -0,0 +1 @@
allow-dbg-in-tests = true

17
.github/workflows/ci.yaml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: Continuous Integration
on:
pull_request:
permissions:
id-token: write
contents: read
jobs:
tests-and-lints:
uses: ./.github/workflows/tests-and-lints-template.yaml
secrets:
eth_rpc_url: ${{ secrets.ETH_RPC_URL }}
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}

View File

@@ -0,0 +1,123 @@
name: Continuous Integration
on:
workflow_call:
inputs:
runs_on:
required: false
type: string
default: ubuntu-latest
timeout_minutes:
required: false
type: number
default: 15
secrets:
eth_rpc_url:
required: true
app_id:
required: true
app_private_key:
required: true
permissions:
id-token: write
contents: read
env:
CARGO_TERM_COLOR: always
ETH_RPC_URL: ${{ secrets.eth_rpc_url }}
jobs:
compile_and_test:
name: Compile & Test
runs-on: ${{ inputs.runs_on }}
timeout-minutes: ${{ inputs.timeout_minutes }}
strategy:
matrix:
toolchain:
- stable
steps:
- name: Generate a token
id: generate-token
uses: getsentry/action-github-app-token@v2
with:
app_id: ${{ secrets.app_id }}
private_key: ${{ secrets.app_private_key }}
- name: Install git
run: sudo apt update && sudo apt install -y git
- name: Checkout
uses: actions/checkout@v3
- name: Setup git to use https
run: |
git config --global credential.helper store
echo "https://${{ steps.generate-token.outputs.token }}@github.com" > ~/.git-credentials
git config --global url."https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com".insteadOf ssh://github.com
- name: Setup toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install latest nextest release
uses: taiki-e/install-action@nextest
- name: Test
run: cargo nextest run --workspace --lib --all-targets --all-features && cargo test --doc
lint:
name: Code Lint
runs-on: ${{ inputs.runs_on }}
timeout-minutes: ${{ inputs.timeout_minutes }}
steps:
- name: Generate a token
id: generate-token
uses: getsentry/action-github-app-token@v2
with:
app_id: ${{ secrets.app_id }}
private_key: ${{ secrets.app_private_key }}
- name: Install git
run: sudo apt update && sudo apt install -y git
- name: Checkout
uses: actions/checkout@v3
- name: Setup git to use https
run: |
git config --global credential.helper store
echo "https://${{ steps.generate-token.outputs.token }}@github.com" > ~/.git-credentials
git config --global url."https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com".insteadOf ssh://github.com
- name: Setup clippy toolchain - stable
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: clippy
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --lib --all-targets --all-features -- -D clippy::dbg-macro
env:
RUSTFLAGS: -Dwarnings
- run: cargo check --no-default-features
env:
RUSTFLAGS: -Dwarnings
- name: Setup rustfmt toolchain - nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo +nightly fmt --all --check

42
.github/workflows/v2-main-workflow.yaml vendored Normal file
View File

@@ -0,0 +1,42 @@
name: Main workflow
on:
push:
branches:
- main
jobs:
tests-and-lints:
uses: ./.github/workflows/tests-and-lints-template.yaml
secrets:
eth_rpc_url: ${{ secrets.ETH_RPC_URL }}
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
check-release:
uses: propeller-heads/ci-cd-templates/.github/workflows/release-v2.yaml@main
with:
args: --dry-run --no-ci
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
secrets:
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
release:
needs:
- tests-and-lints
- check-release
if: needs.check-release.outputs.verify_release_version != ''
uses: propeller-heads/ci-cd-templates/.github/workflows/release-v2.yaml@main
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
secrets:
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}

19
.github/workflows/v2-validate-pr.yaml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: Validate PR title
on:
pull_request_target:
branches:
- main
- release/*
types:
- opened
- edited
- synchronize
jobs:
validate-pr:
uses: propeller-heads/ci-cd-templates/.github/workflows/validate-pr.yaml@main
secrets:
app_id: ${{ secrets.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}

28
.gitignore vendored Normal file
View File

@@ -0,0 +1,28 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# MacOS
.DS_Store
# data folder
.data/
# VS Code
.vscode
# Pycharm User-specific stuff
.idea/*
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
.env

14
.taplo.toml Normal file
View File

@@ -0,0 +1,14 @@
[schema]
path = "https://json.schemastore.org/cargo.json"
enabled = true
[formatting]
reorder_keys = false
[[rule]]
include = ["**/Cargo.toml"]
keys = ["dependencies"]
[rule.formatting]
reorder_keys = true

1
CODEOWNERS Normal file
View File

@@ -0,0 +1 @@
@propeller-heads

3595
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

24
Cargo.toml Normal file
View File

@@ -0,0 +1,24 @@
[package]
name = "tycho-execution"
version = "0.1.0"
edition = "2021"
[dependencies]
dotenv = "0.15.0"
lazy_static = "1.4.0"
num-bigint = "0.4.6"
tokio = { version = "1.38.0", features = ["full"] }
alloy = { version = "0.5.4", features = ["providers"] }
alloy-sol-types = { version = "0.8.14" }
alloy-primitives = { version = "0.8.9" }
tycho-core = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-core", tag = "0.46.0" }
hex = "0.4.3"
anyhow = "1.0.95"
num-traits = "0.2.19"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
[profile.bench]
debug = true

View File

@@ -1 +1,7 @@
# tycho-execution # Tycho Execution
TODO: add banner
Tycho Execution makes it easy to trade on different DEXs by handling the complex encoding for you. Instead of creating
custom code for each DEX, you get a simple, ready-to-use tool that generates the necessary data to execute trades. Its
designed to be safe, straightforward, and quick to set up, so anyone can start trading without extra effort.

5
check.sh Executable file
View File

@@ -0,0 +1,5 @@
set -e
cargo +nightly fmt --all --check
cargo clippy --workspace --lib --all-targets --all-features -- -D clippy::dbg-macro
cargo nextest run --workspace --lib --all-targets --all-features

87
release.config.js Normal file
View File

@@ -0,0 +1,87 @@
const config = {
branches: [
"release/+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
name: "prerelease",
prerelease: "pre",
},
],
tagFormat: "${version}",
ci: true,
debug: true,
plugins: [
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
releaseRules: [
{type: "breaking", release: "major"},
{type: "feat", release: "minor"},
{type: "fix", release: "patch"},
{type: "refactor", release: "patch"},
{type: "security", release: "patch"},
{type: "style", release: "patch"},
{type: "test", release: false},
{type: "docs", release: false},
{type: "ci", release: false},
{type: "chore", release: false},
],
},
],
[
"@semantic-release/exec",
{
verifyReleaseCmd:
'echo "VERIFY_RELEASE_VERSION=${nextRelease.version}" >> $GITHUB_OUTPUT',
publishCmd:
'echo "NEXT_RELEASE_VERSION=${nextRelease.version}" >> $GITHUB_OUTPUT',
prepareCmd: [
"toml set --toml-path Cargo.toml package.version ${nextRelease.version}",
"cargo update -p tycho-execution",
].join(" && "),
},
],
[
"@semantic-release/release-notes-generator",
{
preset: "conventionalcommits",
},
],
[
"@semantic-release/github",
{
successComment:
"This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:",
labels: true,
releasedLabels: true,
},
],
],
};
const ref = process.env.GITHUB_REF;
const branch = ref.split("/").pop();
if (
config.branches.some(
(it) => it === branch || (it.name === branch && !it.prerelease),
)
) {
config.plugins.push("@semantic-release/changelog", [
"@semantic-release/git",
{
assets: [
"CHANGELOG.md",
"Cargo.toml",
"Cargo.lock",
],
message:
"chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
},
]);
}
module.exports = config;

3
rust-toolchain.toml Normal file
View File

@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rustfmt"]

11
rustfmt.toml Normal file
View File

@@ -0,0 +1,11 @@
reorder_imports = true
imports_granularity = "Crate"
use_small_heuristics = "Max"
comment_width = 100
wrap_comments = true
binop_separator = "Back"
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
chain_width=40
group_imports = "StdExternalCrate"

0
src/lib.rs Normal file
View File