Skip to content

Commit

Permalink
Merge pull request #124 from astraly-labs/feat/lp_pricer_contract
Browse files Browse the repository at this point in the history
feat: LP Pricer Contract
  • Loading branch information
akhercha authored Oct 16, 2024
2 parents b0383eb + 671a74c commit 90954b6
Show file tree
Hide file tree
Showing 22 changed files with 50,083 additions and 49,336 deletions.
1 change: 0 additions & 1 deletion .codespellignore

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
- run: scarb fmt --check
- run: scarb test
- run: scarb test
37 changes: 18 additions & 19 deletions .github/workflows/gas_reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,39 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
result=$(python scripts/gas_usage/compare_snapshot.py| sed 's/\x1b\[[0-9;]*m//g')
result=$(echo "$result" | grep -v "Archive:")
result=$(echo "$result" | grep -v "inflating:")
echo "$result" > temp_result.txt
echo "output<<$EOF" >> $GITHUB_OUTPUT
cat temp_result.txt >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
outputs:
outputs:
output: ${{ steps.run_script.outputs.output }}
display_result:
display_result:
needs: compare_snapshot
runs-on: ubuntu-latest
steps:
- name: Comment on PR
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
output="${{needs.compare_snapshot.outputs.output}}"
echo "Debug: output for PR comment = $output"
pr_number=$(jq -r ".number" "$GITHUB_EVENT_PATH")
repo_full_name=$(jq -r ".repository.full_name" "$GITHUB_EVENT_PATH")
output="${{needs.compare_snapshot.outputs.output}}"
echo "Debug: output for PR comment = $output"
pr_number=$(jq -r ".number" "$GITHUB_EVENT_PATH")
repo_full_name=$(jq -r ".repository.full_name" "$GITHUB_EVENT_PATH")
comment=$(printf "Output from Compare Snapshot:\\n\`\`\`\\n%s\\n\`\`\`" "$output")
comment=$(jq -n --arg body "$comment" '{body: $body}')
comment=$(printf "Output from Compare Snapshot:\\n\`\`\`\\n%s\\n\`\`\`" "$output")
comment=$(jq -n --arg body "$comment" '{body: $body}')
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$repo_full_name/issues/$pr_number/comments \
-d "$comment"
curl \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$repo_full_name/issues/$pr_number/comments \
-d "$comment"
2 changes: 1 addition & 1 deletion .github/workflows/gas_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: gas-snapshot
path: gas_snapshot.json
path: gas_snapshot.json
66 changes: 33 additions & 33 deletions .github/workflows/run_scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ jobs:
run:
working-directory: pragma-deployer
steps:
- uses: actions/checkout@v3
- name: Install Starknet Devnet RS
run: |
wget https://github.com/0xSpaceShard/starknet-devnet-rs/releases/download/v0.1.2/starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
tar -xvf starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
chmod +x starknet-devnet
sudo mv starknet-devnet /usr/local/bin/
rm -f starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
- name: Make script executable
run: chmod +x scripts/devnet.sh
- name: Set up Python and install Poetry
uses: actions/setup-python@v4
with:
python-version: '3.12'
- run: pip install poetry
- name: Install dependencies
run: poetry install
- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
- name: Build with Scarb
run: scarb build
- name: Run Starknet Devnet and scripts
env:
DEVNET_ACCOUNT_ADDRESS: "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201"
DEVNET_PRIVATE_KEY: "0xc10662b7b247c7cecf7e8a30726cff12"
run: bash scripts/devnet.sh
- uses: actions/checkout@v3

- name: Install Starknet Devnet RS
run: |
wget https://github.com/0xSpaceShard/starknet-devnet-rs/releases/download/v0.1.2/starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
tar -xvf starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
chmod +x starknet-devnet
sudo mv starknet-devnet /usr/local/bin/
rm -f starknet-devnet-x86_64-unknown-linux-gnu.tar.gz
- name: Make script executable
run: chmod +x scripts/devnet.sh

- name: Set up Python and install Poetry
uses: actions/setup-python@v4
with:
python-version: "3.12"
- run: pip install poetry

- name: Install dependencies
run: poetry install

- name: Set up Scarb
uses: software-mansion/setup-scarb@v1

- name: Build with Scarb
run: scarb build

- name: Run Starknet Devnet and scripts
env:
DEVNET_ACCOUNT_ADDRESS: "0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201"
DEVNET_PRIVATE_KEY: "0xc10662b7b247c7cecf7e8a30726cff12"
run: bash scripts/devnet.sh
16 changes: 0 additions & 16 deletions .github/workflows/spell_check.yml

This file was deleted.

40 changes: 17 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,65 @@

**Pragma, Starknet's native provable oracle.**

What's Pragma ?
---
## What's Pragma ?

Pragma is a decentralized oracle built natively on Starknet. It leverages cairo to make data feeds computation fully trustless.

- Pragma is built from the ground up to remove any trust assumptions in current oracles' design.
There isn't any off-chain infrastructure, raw-data is directly pushed on-chain by *whitelisted* data providers. Then the aggregation happens at the smart contract level.
- Pragma is built from the ground up to remove any trust assumptions in current oracles' design.
There isn't any off-chain infrastructure, raw-data is directly pushed on-chain by _whitelisted_ data providers. Then the aggregation happens at the smart contract level.
- Pragma offers a top-notch developer experience, reviewed by key actors of DeFi on Starknet. The goal is to make the life of DeFi protocols as easy as possible.

Overview
---
## Overview

- <a href="/src/account">Account contract</a> mostly use for testing purposes and as a reference.
- <a href="/src/admin">Ownable contract</a> used for access control.
- <a href="/src/entry">Entry & Data Structures</a> defines data structures used within the protocol along with generic aggregations methods. It is designed from the ground up to ensure that adding new entry types is done seamlessly without involving any breaking changes.
- <a href="/src/operations">Operations</a> defines a few utilities libraries (time series, sorting, bits manipulation) that will be used for different aggregation methods and optimizing storage operations.
- <a href="/src/oracle">Oracle</a> is the main entrypoint of the protocol. It is the contract that end developers will interact with to fetch any kind of data. It's been thought and built for retro-compatibility and heavily leverages unique aspects of Cairo, notably enums, traits and generics.
- <a href="/src/publisher_registry">Publisher Registry</a> handles the registration of different publishers along with the sources they are allowed to push data from.
- <a href="/src/compute_engines">Summary Stats</a> acts as a proxy contract for more sophisticated kind of data aggregation such as *volatility* and *mean*.
- <a href="/src/compute_engines">Summary Stats</a> acts as a proxy contract for more sophisticated kind of data aggregation such as _volatility_ and _mean_.
- <a href="/src/randomness">Randomness</a> is the VRF requestor implementation, also includes an example on how to request random words.
- <a href="/src/lp_pricer">LP Pricer</a> is a Pricing contract for LP tokens. It allows registering pools (which underlying assets are supported by Pragma) and prices them in USD.

## Testing

- <a href="/src/tests">Test suite</a>, unit tests are provided under the functions' implementations directly whereas full flow integration tests lie within this test suite. It uses cairo-test for now and test thoroughly for any edge case.

A few key testing features are missing such as *fuzzing* and proper hooks, mocking cheatcodes. This will come as cairo tooling matures and improves.
A few key testing features are missing such as _fuzzing_ and proper hooks, mocking cheatcodes. This will come as cairo tooling matures and improves.

Documentation
---
## Documentation

More extensive documentation can be found on our [official website](https://docs.pragma.build/).

Audit
---
## Audit

Pragma Starknet has been peer-reviewed by many other key-projects in the industries.
It has also been audited by Nethermind, you can find the full report under the <a href='/audits'>audits</a> folder.


Deployment addresses
---
## Deployment addresses

This repo will gradually replace the previous Pragma implementation in Cairo 0 which you can find [here](https://github.com/Astraly-Labs/pragma-contracts).

**Starknet Sepolia**

- Oracle : [0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a](https://sepolia.voyager.online/contract/0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a)
- Publisher Registry : [0x1b08e27ab436cd491631156da5f3aa7ff04aee1e6ca925eb2ca84397c22b74d](https://sepolia.voyager.online/contract/0x1b08e27ab436cd491631156da5f3aa7ff04aee1e6ca925eb2ca84397c22b74d)
- Summary Stats : [0x54563a0537b3ae0ba91032d674a6d468f30a59dc4deb8f0dce4e642b94be15c](https://sepolia.voyager.online/contract/0x54563a0537b3ae0ba91032d674a6d468f30a59dc4deb8f0dce4e642b94be15c)
- VRF : [0x60c69136b39319547a4df303b6b3a26fab8b2d78de90b6bd215ce82e9cb515c](https://sepolia.voyager.online/contract/0x60c69136b39319547a4df303b6b3a26fab8b2d78de90b6bd215ce82e9cb515c)

**Starknet Mainnet**

- Oracle : [0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b](https://voyager.online/contract/0x2a85bd616f912537c50a49a4076db02c00b29b2cdc8a197ce92ed1837fa875b)
- Publisher Registry : [0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415](https://voyager.online/contract/0x24a55b928496ef83468fdb9a5430fe031ac386b8f62f5c2eb7dd20ef7237415)
- Summary Stats : [0x49eefafae944d07744d07cc72a5bf14728a6fb463c3eae5bca13552f5d455fd](https://voyager.online/contract/0x49eefafae944d07744d07cc72a5bf14728a6fb463c3eae5bca13552f5d455fd)
- VRF : [0x4fb09ce7113bbdf568f225bc757a29cb2b72959c21ca63a7d59bdb9026da661](https://voyager.online/contract/0x4fb09ce7113bbdf568f225bc757a29cb2b72959c21ca63a7d59bdb9026da661)

Local Deployment
---
## Local Deployment

Prerequisites:

- [Scarb](https://docs.swmansion.com/scarb/)
- 3.9 <= Python < 3.13
- 3.9 <= Python < 3.13
- [Poetry](https://python-poetry.org/)

1. Install dependencies
Expand Down Expand Up @@ -94,13 +91,10 @@ STARKNET_NETWORK=devnet poetry run register-publishers

Once the contracts are declared/deployed you'll find them under the `deployments/` folder at the root of the repo.


Questions and feedback
---
## Questions and feedback

For any question or feedback you can send an email to <[email protected]>

License
---
## License

The code is under the GNU AFFERO GENERAL PUBLIC LICENSE v3.0, see <a href="./LICENSE">LICENSE</a>.
2 changes: 1 addition & 1 deletion deployments/devnet/declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pragma_Randomness": "0x2e167703c1deef69c6c5076133d3491fc75d1d1f486e6a8375712d28ff10fa4",
"pragma_ExampleRandomness": "0x2f8197e47fa9776db20a22e009fdeee079f0387cbc823fad5bf0d8e285e81a7",
"pragma_YieldCurve": "0x55a7af6d2df5730c784ec31ca9f71e66f19e8cb78359d23f51aececcc1c04eb"
}
}
2 changes: 1 addition & 1 deletion deployments/devnet/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"address": "0x31ebe9abc10ab3ed81ec52bcd4365f50302e118fdd3c04777b1604465fbeb69",
"tx": "0x77a3bb0df8d8f4236019e4d11c3936733228045ded4564d91436049c3fb4895"
}
}
}
2 changes: 1 addition & 1 deletion deployments/madara_test/declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pragma_Randomness": "0x2e167703c1deef69c6c5076133d3491fc75d1d1f486e6a8375712d28ff10fa4",
"pragma_ExampleRandomness": "0x2f8197e47fa9776db20a22e009fdeee079f0387cbc823fad5bf0d8e285e81a7",
"pragma_YieldCurve": "0x1d59490811990de9a28095a519c045eeae60e5a7c6b976a207fcd56716b4171"
}
}
2 changes: 1 addition & 1 deletion deployments/madara_test/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"address": "0x5bec6ca0be39624d95818d17857428c9995d4db5ddd088aefbf218b6d280f2a",
"tx": "0xfad6c97fc9869d0bee86a5c47bf19d2083e18eedea50781e796fd42a9ef254"
}
}
}
2 changes: 1 addition & 1 deletion deployments/mainnet/declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pragma_Randomness": "0x2e167703c1deef69c6c5076133d3491fc75d1d1f486e6a8375712d28ff10fa4",
"pragma_ExampleRandomness": "0x2f8197e47fa9776db20a22e009fdeee079f0387cbc823fad5bf0d8e285e81a7",
"pragma_YieldCurve": "0x55a7af6d2df5730c784ec31ca9f71e66f19e8cb78359d23f51aececcc1c04eb"
}
}
2 changes: 1 addition & 1 deletion deployments/mainnet/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"address": "0xd2a05a1d1f87da40c77410b91cab00c66d5cbca88103e7206565a918ad2722",
"tx": "0x3fb67ac3529869e76e9e0bbf323cf30a1d355641199f2b8ebd9d7e81e714c5a"
}
}
}
2 changes: 1 addition & 1 deletion deployments/sepolia/declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pragma_Randomness": "0x2e167703c1deef69c6c5076133d3491fc75d1d1f486e6a8375712d28ff10fa4",
"pragma_ExampleRandomness": "0x2f8197e47fa9776db20a22e009fdeee079f0387cbc823fad5bf0d8e285e81a7",
"pragma_YieldCurve": "0x1d59490811990de9a28095a519c045eeae60e5a7c6b976a207fcd56716b4171"
}
}
2 changes: 1 addition & 1 deletion deployments/sepolia/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"address": "0x60c69136b39319547a4df303b6b3a26fab8b2d78de90b6bd215ce82e9cb515c",
"tx": "0x59493788ed2789da7be4fa48fc5fa92cc3e60d5040761d4142fdbe59c15cf0e"
}
}
}
2 changes: 1 addition & 1 deletion deployments/testnet/declarations.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"pragma_Randomness": "0x148bd4c60f4d4bf0f7e903bd3037b683d3d9f7cd42c88ca21beacff06ba7e7",
"pragma_ExampleRandomness": "0x546bab2a16b06f2350fe80e7cdcc8bc08afe28847185833dda0feeae6aa24f3",
"pragma_YieldCurve": "0x55a7af6d2df5730c784ec31ca9f71e66f19e8cb78359d23f51aececcc1c04eb"
}
}
2 changes: 1 addition & 1 deletion deployments/testnet/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"address": "0x2c9a03499f8c1cefbb7ffd07aeb5c534396f3d92ea6c42322c51c933a0065ac",
"tx": "0x63ee5f2eb9b92dec920e81ed28f9bdf630e2ceeca7604c420f16be50025b2a2"
}
}
}
Loading

0 comments on commit 90954b6

Please sign in to comment.