Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci-starknet-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
tool-versions: target_chains/starknet/contracts/.tool-versions
- name: Install Starkli
run: curl https://get.starkli.sh | sh && . ~/.config/.starkli/env && starkliup -v $(awk '/starkli/{print $2}' .tool-versions)
- name: Install Katana
run: curl -L https://install.dojoengine.org | bash && PATH="$PATH:$HOME/.config/.dojo/bin" dojoup -v $(awk '/dojo/{print $2}' .tool-versions)
- name: Install Devnet
run: cargo install starknet-devnet --version $(awk '/starknet-devnet/{print $2}' .tool-versions)
- name: Check formatting
run: scarb fmt --check
- name: Run tests
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Check ABI files
run: |
cat target/dev/pyth_pyth.contract_class.json | jq .abi > /tmp/pyth.json
cat target/dev/pyth_ERC20.contract_class.json | jq .abi > /tmp/erc20.json
cat target/dev/pyth_ERC20Upgradeable.contract_class.json | jq .abi > /tmp/erc20.json
if ! cmp --silent /tmp/pyth.json ../sdk/js/src/abi/pyth.json ; then
>&2 echo ABI file mismatch for sdk/js/src/abi/pyth.json
exit 1
Expand All @@ -46,7 +46,7 @@ jobs:
exit 1
fi
- name: Test local deployment script
run: bash -c 'PATH="$PATH:$HOME/.config/.dojo/bin" katana & . ~/.config/.starkli/env && deploy/deploy.sh'
run: bash -c 'starknet-devnet --seed 0 --account-class cairo1 & . ~/.config/.starkli/env && deploy/deploy.sh'
- name: Verify version
run: |
version1=$(grep version Scarb.toml | cut -d '"' -f 2)
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/ci-starknet-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.78.0
toolchain: 1.86.0
components: rustfmt, clippy
override: true
- uses: actions/checkout@v3
Expand All @@ -35,8 +35,10 @@ jobs:
run: cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_keypair
- name: Check test data
run: |
. ~/.config/.starkli/env && cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_test_data > /tmp/data.cairo
if ! diff ./target_chains/starknet/contracts/tests/data.cairo /tmp/data.cairo; then
. ~/.config/.starkli/env && cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_test_data > ./target_chains/starknet/contracts/data.cairo
cd target_chains/starknet/contracts && scarb fmt data.cairo
if ! diff ./tests/data.cairo data.cairo; then
>&2 echo "Re-run generate_test_data to update data.cairo"
exit 1
fi
rm data.cairo
9 changes: 5 additions & 4 deletions target_chains/starknet/contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scarb 2.5.4
starknet-foundry 0.21.0
dojo 0.6.0
starkli 0.2.8
dojo 1.4.0
starkli 0.4.0
scarb 2.11.1
starknet-foundry 0.38.3
starknet-devnet 0.4.0
2 changes: 1 addition & 1 deletion target_chains/starknet/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run `scarb fmt` to automatically format the source code.
## Local deployment

1. Install Starkli (a cli tool for Starknet) by following [the installation instructions](https://github.com/xJonathanLEI/starkli).
2. Install Katana (a local Starknet node) by following [the installation instructions](https://book.starknet.io/ch02-04-katana.html).
2. Install Devnet (a local Starknet node) by following [the installation instructions](https://0xspaceshard.github.io/starknet-devnet/).
3. Run the deployment script:

```bash
Expand Down
132 changes: 128 additions & 4 deletions target_chains/starknet/contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,122 @@ version = 1

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:320185f3e17cf9fafda88b1ce490f5eaed0bfcc273036b56cd22ce4fb8de628f"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a39a4ea1582916c637bf7e3aee0832c3fe1ea3a3e39191955e8dc39d08327f9b"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:7e943a2de32ddca4d48e467e52790e380ab1f49c4daddbbbc4634dd930d0243f"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_finance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:9fa9e91d39b6ccdfa31eef32fdc087cd06c0269cc9c6b86e32d57f5a6997d98b"
dependencies = [
"openzeppelin_access",
"openzeppelin_token",
]

[[package]]
name = "openzeppelin_governance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:c05add2974b3193c3a5c022b9586a84cf98c5970cdb884dcf201c77dbe359f55"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_introspection"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:34e088ecf19e0b3012481a29f1fbb20e600540cb9a5db1c3002a97ebb7f5a32a"

[[package]]
name = "openzeppelin_merkle_tree"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a5341705514a3d9beeeb39cf11464111f7355be621639740d2c5006786aa63dc"

[[package]]
name = "openzeppelin_presets"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:4eb098e2ee3ac0e67b6828115a7de62f781418beab767d4e80b54e176808369d"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_security"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:1deb811a239c4f9cc28fc302039e2ffcb19911698a8c612487207448d70d2e6e"

[[package]]
name = "openzeppelin_token"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:33fcb84a1a76d2d3fff9302094ff564f78d45b743548fd7568c130b272473f66"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_upgrades"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:36f7a03e7e7111577916aacf31f88ad0053de20f33ee10b0ab3804849c3aa373"

[[package]]
name = "openzeppelin_utils"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:fd348b31c4a4407add33adc3c2b8f26dca71dbd7431faaf726168f37a91db0c1"

[[package]]
name = "pyth"
Expand All @@ -14,7 +128,17 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:0cd914b547acd96b4cad99a78e95c0eda001d0c280da4969b2161e286079cf46"

[[package]]
name = "snforge_std"
version = "0.21.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.21.0#2996b8c1dd66b2715fc67e69578089f278a46790"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:d376526fbbe22535ad89ed630b11d6e209f22c50168de6c6430c0591c81c3174"
dependencies = [
"snforge_scarb_plugin",
]
12 changes: 7 additions & 5 deletions target_chains/starknet/contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[package]
name = "pyth"
version = "0.1.0"
edition = "2023_11"
edition = "2024_07"

[dependencies]
starknet = ">=2.5.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }
starknet = "2.11.1"
openzeppelin = "1.0.0"

[dev-dependencies]
snforge_std = "0.38.3"

[lib]

[[target.starknet-contract]]
build-external-contracts = ["openzeppelin::presets::erc20::ERC20"]
build-external-contracts = ["openzeppelin::presets::erc20::ERC20Upgradeable"]
26 changes: 14 additions & 12 deletions target_chains/starknet/contracts/deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Deploys Wormhole and Pyth contracts.
#
# Variables:
# PYTH_DEPLOY_MODE - "katana" or "sepolia" (default: "katana")
# PYTH_DEPLOY_MODE - "devnet" or "sepolia" (default: "devnet")
# PYTH_WORMHOLE_ADDRESS - if set, the script will use it instead of deploying a new Wormhole contract.
# When using sepolia, set STARKNET_ACCOUNT and STARKNET_KEYSTORE as well.

Expand All @@ -13,19 +13,20 @@ set -o pipefail
set -x

if [ -z ${PYTH_DEPLOY_MODE+x} ]; then
PYTH_DEPLOY_MODE=katana
PYTH_DEPLOY_MODE=devnet
fi

if [ "${PYTH_DEPLOY_MODE}" == "katana" ]; then
export STARKNET_ACCOUNT=katana-0
if [ "${PYTH_DEPLOY_MODE}" == "devnet" ]; then
export STARKNET_RPC=http://0.0.0.0:5050
export STARKNET_ACCOUNT=0x064b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
export STARKNET_ACCOUNT_PK=0x0000000000000000000000000000000071d7bb07b9a64f6f78ac4c816aff4da9

chain_id=50075 # starknet_sepolia

# predeployed fee token contract in katana
# predeployed fee token contract in devnet
fee_token_address1=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7

# there is no second fee token pre-deployed in katana
# there is no second fee token pre-deployed in devnet
fee_token_address2=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
elif [ "${PYTH_DEPLOY_MODE}" == "sepolia" ]; then
export STARKNET_RPC=https://starknet-sepolia.public.blastapi.io/rpc/v0_6
Expand Down Expand Up @@ -59,12 +60,13 @@ cd "$(dirname "$0")/.."
scarb build 1>&2

if [ -z ${PYTH_WORMHOLE_ADDRESS+x} ]; then
wormhole_hash=$(starkli declare --watch target/dev/pyth_wormhole.contract_class.json)
starkli account fetch ${STARKNET_ACCOUNT} --output=account.json --rpc=${STARKNET_RPC}
wormhole_hash=$(starkli declare --watch target/dev/pyth_wormhole.contract_class.json --account ./account.json --private-key ${STARKNET_ACCOUNT_PK})

# deploying wormhole with mainnet guardians

# guardian set #4
PYTH_WORMHOLE_ADDRESS=$(starkli deploy --not-unique --salt 0 --watch "${wormhole_hash}" \
PYTH_WORMHOLE_ADDRESS=$(starkli deploy --not-unique --salt 0 --watch "${wormhole_hash}" --account ./account.json --private-key ${STARKNET_ACCOUNT_PK} \
4 `# guardian_set_index` \
19 `# num_guardians` \
0x5893B5A76c3f739645648885bDCcC06cd70a3Cd3 \
Expand Down Expand Up @@ -97,7 +99,7 @@ if [ -z ${PYTH_WORMHOLE_ADDRESS+x} ]; then
fi
echo "PYTH_WORMHOLE_ADDRESS=${PYTH_WORMHOLE_ADDRESS}"

pyth_hash=$(starkli declare --watch target/dev/pyth_pyth.contract_class.json)
pyth_hash=$(starkli declare --watch target/dev/pyth_pyth.contract_class.json --account ./account.json --private-key ${STARKNET_ACCOUNT_PK})

emitter_chain_id1=26
emitter_address1=0xf8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0
Expand All @@ -108,7 +110,7 @@ emitter_address2=0xe101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4a
governance_emitter_chain_id=1
governance_emitter_address=0x5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e

pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" \
pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" --account ./account.json --private-key ${STARKNET_ACCOUNT_PK} \
"${PYTH_WORMHOLE_ADDRESS}" \
"${fee_token_address1}" \
1 0 `# fee_amount1` \
Expand All @@ -122,9 +124,9 @@ pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" \
0 `# governance_initial_sequence` \
)

starkli invoke --watch "${fee_token_address1}" approve "${pyth_address}" 1000 0
starkli invoke --watch "${fee_token_address1}" approve "${pyth_address}" 1000 0 --account ./account.json --private-key ${STARKNET_ACCOUNT_PK}

starkli invoke --watch "${pyth_address}" update_price_feeds \
starkli invoke --watch "${pyth_address}" --account ./account.json --private-key ${STARKNET_ACCOUNT_PK} update_price_feeds \
11 41 141887862745809943100717722154781668656425228150258363002663887732857548075 399793171101922163607717906910020156439802651815166374105600343045575931912 205983572864866548810075966151139050810706099666354694408986588005072300221 151451952208610765038741735376830560508647207417250420083288609153397964481 86500771940909656434129966404881206990783089169853273096126376095161148476 226128071698991949569342896653857259217290864736270016974365368327197190188 377698250859392108521341636250067678937984182266455992791761951028534274645 359481881021010868573625646624159016709204941239347558851817240293252854322 269752247307988210724584131415546296182395279893478036136383326770680756016 1795390197095010264738527441013169771569683827600670029637766897428840143 234116006474879126519208934707397575502368608154160721412947025189419787194 189800847222104556167598630039931285094024694085247523307780296439180585091 286206863474379560841614954761399331434812535348350225390274576176798886031 380778504466325787198909189418135115031120011427014465236265515817642556890 128785010970678423864351132498736713626005612397319240493515416417380099413 395419216432871057204438489759682910781574046646010114747283889104834443397 184981610545658962928833309057692452941395349433458372962283948260273947156 110573687320157468197346423602708230855113764048934963897254568602798981891 359831064918860887692030922920274851680298668214543004760245859301314852951 430048018037020109398934292236837834709370591653776097569938580165539734124 265079002668517523371293797450754079826401787503533883360533359118093613709 118956066417175616647948432812222980193178970842860785889932661265944570805 289275771653255859826082430219295399339085718287922176066620100061685069367 236281080443323007784750945204995275799519083197981738780888611083509567478 251042542087561162756580709366349731114715604419679060279244203132266921212 98235342442817522140724982668491795525073680697047819016960109902179866805 88342865348230190810084665689239940103607621061956069700600977485132311440 362045407519743532711403801060857872682086780812134177115599591240431143367 16066483776176414842828409371714210177224680637354816226962534075790344474 247660009137502548346315865368477795392972486141407802997108167405894850048 3530678887550352072827758533436734366288448089041832078266099519 272101358674132653417860014541384836605087997364704101839695292681479883518 394112423559676785086059691419737479771752814065338155011845462169193807974 151755140354137577506498286435010205890750984061355535849635897370673003944 210196797635098012510106281616028853575843684847951745405842531072933610917 65848881303037889845233189630325925691014776183743685310081069912626992101 110542381473451658848567609117180625628841970992142907142739541724557861958 157546342890129829983246193527213822449181723932011157069167729323808635205 165998047372192053828934221954381957675361960853286466716634704795532379661 28583007876111384456149499846085318299326698960792831530075402396150538907 126290914008245563820443505

>&2 echo Pyth contract has been successfully deployed at "${pyth_address}"
Expand Down
9 changes: 4 additions & 5 deletions target_chains/starknet/contracts/src/byte_buffer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl DebugByteBuffer of Debug<ByteBuffer> {
Option::Some(v) => { write!(f, "{:?}, ", v).unwrap(); },
Option::None => { break; },
}
};
}
write!(f, "]}}")
}
}
Expand All @@ -45,7 +45,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {
let last: u256 = (*data.at(data.len() - 1)).into();
assert!(
last / one_shift_left_bytes_u256(num_last_bytes) == 0,
"ByteBufferImpl::new: last value is too large"
"ByteBufferImpl::new: last value is too large",
);
}
ByteBuffer { num_last_bytes, data }
Expand Down Expand Up @@ -75,8 +75,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {

#[cfg(test)]
mod tests {
use super::{ByteBuffer, ByteBufferImpl};
use pyth::util::array_try_into;
use super::ByteBufferImpl;

#[test]
fn empty_byte_array() {
Expand Down Expand Up @@ -132,7 +131,7 @@ mod tests {
let value2_31_bytes = 0x2122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f;
let value3_5_bytes = 0x4142434445;
let mut array = ByteBufferImpl::new(
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5,
);
assert!(array.len() == 67);
assert!(array.pop_front() == Option::Some((value_31_bytes, 31)));
Expand Down
Loading
Loading