Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed May 20, 2024
0 parents commit 9ed1543
Show file tree
Hide file tree
Showing 34 changed files with 868 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig http://EditorConfig.org

# top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.sol]
indent_size = 4

[*.tree]
indent_size = 1
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "CI"

env:
API_KEY_ALCHEMY: ${{ secrets.API_KEY_ALCHEMY }}
FOUNDRY_PROFILE: "ci"

on:
workflow_dispatch:
pull_request:
push:
branches:
- "main"

jobs:
lint:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v4"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Install Bun"
uses: "oven-sh/setup-bun@v1"

- name: "Install the Node.js dependencies"
run: "bun install"

- name: "Lint the code"
run: "bun run lint"

- name: "Add lint summary"
run: |
echo "## Lint result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
build:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v4"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: "Install Bun"
uses: "oven-sh/setup-bun@v1"

- name: "Install the Node.js dependencies"
run: "bun install"

- name: "Build the contracts and print their size"
run: "forge build --sizes"

- name: "Add build summary"
run: |
echo "## Build result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
26 changes: 26 additions & 0 deletions .github/workflows/multibuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Multibuild"

on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 0" # at 3:00am UTC every Sunday

jobs:
multibuild:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v4"

- name: "Install Bun"
uses: "oven-sh/setup-bun@v1"

- name: "Install the Node.js dependencies"
run: "bun install --frozen-lockfile"

- name: "Check that the project can be built with multiple Solidity versions"
uses: "PaulRBerg/foundry-multibuild@v1"
with:
min: "0.8.4"
max: "0.8.25"
skip-test: "true"
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# directories
cache
coverage
node_modules
out

# files
*.env
*.log
.DS_Store
.pnp.*
lcov.info
package-lock.json
pnpm-lock.yaml
yarn.lock

# broadcasts
!broadcast
broadcast/*
broadcast/*/31337/
16 changes: 16 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# directories
cache
coverage
node_modules
out

# files
*.env
*.log
.DS_Store
.pnp.*
bun.lockb
lcov.info
package-lock.json
pnpm-lock.yaml
yarn.lock
7 changes: 7 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bracketSpacing: true
printWidth: 120
proseWrap: "always"
singleQuote: false
tabWidth: 2
trailingComma: "all"
useTabs: false
15 changes: 15 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "solhint:recommended",
"rules": {
"avoid-low-level-calls": "off",
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.4"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"named-parameters-mapping": "warn",
"no-console": "off",
"not-rely-on-time": "off",
"one-contract-per-file": "off"
}
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"editor.formatOnSave": true,
"solidity.formatter": "forge"
}
16 changes: 16 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MIT License

Copyright (c) 2024 Paul Razvan Berg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Sablier Standard Library [![License: MIT][license-badge]][license]

[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg

This repository contains the Sablier Standard Library.

## License

This project is licensed under MIT.
Binary file added bun.lockb
Binary file not shown.
43 changes: 43 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Full reference https://github.com/foundry-rs/foundry/tree/master/crates/config

[profile.default]
auto_detect_solc = false
block_timestamp = 1717200000 # June 1, 2024 at 00:00 GMT
bytecode_hash = "none"
evm_version = "shanghai"
fuzz = { runs = 1_000 }
gas_reports = ["SRF20"]
optimizer = true
optimizer_runs = 10_000
out = "out"
script = "script"
solc = "0.8.25"
src = "src"
test = "test"

[profile.ci]
fuzz = { runs = 10_000 }
verbosity = 4

# Speed up compilation and tests during development
[profile.lite]
optimizer = false

[doc]
ignore = ["**/*.t.sol"]
out = "docs"
repository = "https://github.com/sablier-labs/stdlib"

[fmt]
bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "all"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = true

[rpc_endpoints]
localhost = "http://localhost:8545"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@sablier/stdlib",
"description": "Standard library for SabVM",
"version": "1.0.0",
"author": {
"name": "Sablier Labs Ltd",
"url": "https://sablier.com"
},
"devDependencies": {
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
"prettier": "^3.2.5",
"solhint": "^3.6.2"
},
"keywords": [
"blockchain",
"ethereum",
"forge",
"foundry",
"smart-contracts",
"solidity",
"template"
],
"private": true,
"scripts": {
"clean": "rm -rf cache out",
"build": "forge build",
"lint": "bun run lint:sol && bun run prettier:check",
"lint:sol": "forge fmt --check && bun solhint {script,src,test}/**/*.sol",
"prettier:check": "prettier --check \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"",
"prettier:write": "prettier --write \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"",
"test": "forge test",
"test:coverage": "forge coverage",
"test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage"
}
}
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
forge-std/=node_modules/forge-std/
16 changes: 16 additions & 0 deletions src/Constants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

// import { SubID } from "./Types.sol";

/*//////////////////////////////////////////////////////////////////////////
NATIVE TOKENS
//////////////////////////////////////////////////////////////////////////*/

bytes32 constant DEFAULT_SUB_ID = bytes32(0);

/*//////////////////////////////////////////////////////////////////////////
PRECOMPILES
//////////////////////////////////////////////////////////////////////////*/

address constant PRECOMPILE_NATIVE_TOKENS = address(0x0000000000000000000000000000000000000200);
6 changes: 6 additions & 0 deletions src/Types.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

type AssetID is uint256;

type SubID is bytes32;
36 changes: 36 additions & 0 deletions src/precompiles/native-tokens/INativeTokens.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

/// @notice Interface for the NativeTokens precompile, which can perform operations on native tokens.
/// @dev It is NOT recommended to use this interface directly. Instead, users should use the {NativeTokens} library.
/// This interface is used by the library to ABI encode the precompile calls.
interface INativeTokens {
function burn(address holder, bytes32 subID, uint256 amount) external;
function mint(address recipient, bytes32 subID, uint256 amount) external;
function transfer(address from, address to, bytes32 tokenID, uint256 amount) external;
function transferAndCall(
address from,
address to,
bytes32 tokenID,
uint256 amount,
address callee,
bytes calldata data
)
external;
function transferMultiple(
address from,
address[] calldata to,
bytes32[] calldata assetIDs,
uint256[] calldata amounts
)
external;
function transferMultipleAndCall(
address from,
address[] calldata to,
bytes32[] calldata assetIDs,
uint256[] calldata amounts,
address callee,
bytes calldata data
)
external;
}
Loading

0 comments on commit 9ed1543

Please sign in to comment.