Skip to content

Commit ef3a901

Browse files
authored
feat(target_chains/starknet): scarb & snforge upgrade (#2570)
* upgrade dependencies * fix build issue * fix snforge upgrading issue * regenerate test data * code format * update toolchain version in github workflow ci-starknet-tools * replace dojo with starknet-devnet * update devnet link
1 parent cf1ca49 commit ef3a901

29 files changed

+851
-545
lines changed

.github/workflows/ci-starknet-contract.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
tool-versions: target_chains/starknet/contracts/.tool-versions
2626
- name: Install Starkli
2727
run: curl https://get.starkli.sh | sh && . ~/.config/.starkli/env && starkliup -v $(awk '/starkli/{print $2}' .tool-versions)
28-
- name: Install Katana
29-
run: curl -L https://install.dojoengine.org | bash && PATH="$PATH:$HOME/.config/.dojo/bin" dojoup -v $(awk '/dojo/{print $2}' .tool-versions)
28+
- name: Install Devnet
29+
run: cargo install starknet-devnet --version $(awk '/starknet-devnet/{print $2}' .tool-versions)
3030
- name: Check formatting
3131
run: scarb fmt --check
3232
- name: Run tests
@@ -36,7 +36,7 @@ jobs:
3636
- name: Check ABI files
3737
run: |
3838
cat target/dev/pyth_pyth.contract_class.json | jq .abi > /tmp/pyth.json
39-
cat target/dev/pyth_ERC20.contract_class.json | jq .abi > /tmp/erc20.json
39+
cat target/dev/pyth_ERC20Upgradeable.contract_class.json | jq .abi > /tmp/erc20.json
4040
if ! cmp --silent /tmp/pyth.json ../sdk/js/src/abi/pyth.json ; then
4141
>&2 echo ABI file mismatch for sdk/js/src/abi/pyth.json
4242
exit 1
@@ -46,7 +46,7 @@ jobs:
4646
exit 1
4747
fi
4848
- name: Test local deployment script
49-
run: bash -c 'PATH="$PATH:$HOME/.config/.dojo/bin" katana & . ~/.config/.starkli/env && deploy/deploy.sh'
49+
run: bash -c 'starknet-devnet --seed 0 --account-class cairo1 & . ~/.config/.starkli/env && deploy/deploy.sh'
5050
- name: Verify version
5151
run: |
5252
version1=$(grep version Scarb.toml | cut -d '"' -f 2)

.github/workflows/ci-starknet-tools.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions-rs/toolchain@v1
1515
with:
1616
profile: minimal
17-
toolchain: 1.78.0
17+
toolchain: 1.86.0
1818
components: rustfmt, clippy
1919
override: true
2020
- uses: actions/checkout@v3
@@ -35,8 +35,10 @@ jobs:
3535
run: cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_keypair
3636
- name: Check test data
3737
run: |
38-
. ~/.config/.starkli/env && cargo run --manifest-path ./target_chains/starknet/tools/test_vaas/Cargo.toml --bin generate_test_data > /tmp/data.cairo
39-
if ! diff ./target_chains/starknet/contracts/tests/data.cairo /tmp/data.cairo; then
38+
. ~/.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
39+
cd target_chains/starknet/contracts && scarb fmt data.cairo
40+
if ! diff ./tests/data.cairo data.cairo; then
4041
>&2 echo "Re-run generate_test_data to update data.cairo"
4142
exit 1
4243
fi
44+
rm data.cairo
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
scarb 2.5.4
2-
starknet-foundry 0.21.0
3-
dojo 0.6.0
4-
starkli 0.2.8
1+
dojo 1.4.0
2+
starkli 0.4.0
3+
scarb 2.11.1
4+
starknet-foundry 0.38.3
5+
starknet-devnet 0.4.0

target_chains/starknet/contracts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Run `scarb fmt` to automatically format the source code.
2828
## Local deployment
2929

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

3434
```bash

target_chains/starknet/contracts/Scarb.lock

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,122 @@ version = 1
33

44
[[package]]
55
name = "openzeppelin"
6-
version = "0.10.0"
7-
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
6+
version = "1.0.0"
7+
source = "registry+https://scarbs.xyz/"
8+
checksum = "sha256:320185f3e17cf9fafda88b1ce490f5eaed0bfcc273036b56cd22ce4fb8de628f"
9+
dependencies = [
10+
"openzeppelin_access",
11+
"openzeppelin_account",
12+
"openzeppelin_finance",
13+
"openzeppelin_governance",
14+
"openzeppelin_introspection",
15+
"openzeppelin_merkle_tree",
16+
"openzeppelin_presets",
17+
"openzeppelin_security",
18+
"openzeppelin_token",
19+
"openzeppelin_upgrades",
20+
"openzeppelin_utils",
21+
]
22+
23+
[[package]]
24+
name = "openzeppelin_access"
25+
version = "1.0.0"
26+
source = "registry+https://scarbs.xyz/"
27+
checksum = "sha256:a39a4ea1582916c637bf7e3aee0832c3fe1ea3a3e39191955e8dc39d08327f9b"
28+
dependencies = [
29+
"openzeppelin_introspection",
30+
"openzeppelin_utils",
31+
]
32+
33+
[[package]]
34+
name = "openzeppelin_account"
35+
version = "1.0.0"
36+
source = "registry+https://scarbs.xyz/"
37+
checksum = "sha256:7e943a2de32ddca4d48e467e52790e380ab1f49c4daddbbbc4634dd930d0243f"
38+
dependencies = [
39+
"openzeppelin_introspection",
40+
"openzeppelin_utils",
41+
]
42+
43+
[[package]]
44+
name = "openzeppelin_finance"
45+
version = "1.0.0"
46+
source = "registry+https://scarbs.xyz/"
47+
checksum = "sha256:9fa9e91d39b6ccdfa31eef32fdc087cd06c0269cc9c6b86e32d57f5a6997d98b"
48+
dependencies = [
49+
"openzeppelin_access",
50+
"openzeppelin_token",
51+
]
52+
53+
[[package]]
54+
name = "openzeppelin_governance"
55+
version = "1.0.0"
56+
source = "registry+https://scarbs.xyz/"
57+
checksum = "sha256:c05add2974b3193c3a5c022b9586a84cf98c5970cdb884dcf201c77dbe359f55"
58+
dependencies = [
59+
"openzeppelin_access",
60+
"openzeppelin_account",
61+
"openzeppelin_introspection",
62+
"openzeppelin_token",
63+
"openzeppelin_utils",
64+
]
65+
66+
[[package]]
67+
name = "openzeppelin_introspection"
68+
version = "1.0.0"
69+
source = "registry+https://scarbs.xyz/"
70+
checksum = "sha256:34e088ecf19e0b3012481a29f1fbb20e600540cb9a5db1c3002a97ebb7f5a32a"
71+
72+
[[package]]
73+
name = "openzeppelin_merkle_tree"
74+
version = "1.0.0"
75+
source = "registry+https://scarbs.xyz/"
76+
checksum = "sha256:a5341705514a3d9beeeb39cf11464111f7355be621639740d2c5006786aa63dc"
77+
78+
[[package]]
79+
name = "openzeppelin_presets"
80+
version = "1.0.0"
81+
source = "registry+https://scarbs.xyz/"
82+
checksum = "sha256:4eb098e2ee3ac0e67b6828115a7de62f781418beab767d4e80b54e176808369d"
83+
dependencies = [
84+
"openzeppelin_access",
85+
"openzeppelin_account",
86+
"openzeppelin_finance",
87+
"openzeppelin_introspection",
88+
"openzeppelin_token",
89+
"openzeppelin_upgrades",
90+
"openzeppelin_utils",
91+
]
92+
93+
[[package]]
94+
name = "openzeppelin_security"
95+
version = "1.0.0"
96+
source = "registry+https://scarbs.xyz/"
97+
checksum = "sha256:1deb811a239c4f9cc28fc302039e2ffcb19911698a8c612487207448d70d2e6e"
98+
99+
[[package]]
100+
name = "openzeppelin_token"
101+
version = "1.0.0"
102+
source = "registry+https://scarbs.xyz/"
103+
checksum = "sha256:33fcb84a1a76d2d3fff9302094ff564f78d45b743548fd7568c130b272473f66"
104+
dependencies = [
105+
"openzeppelin_access",
106+
"openzeppelin_account",
107+
"openzeppelin_introspection",
108+
"openzeppelin_utils",
109+
]
110+
111+
[[package]]
112+
name = "openzeppelin_upgrades"
113+
version = "1.0.0"
114+
source = "registry+https://scarbs.xyz/"
115+
checksum = "sha256:36f7a03e7e7111577916aacf31f88ad0053de20f33ee10b0ab3804849c3aa373"
116+
117+
[[package]]
118+
name = "openzeppelin_utils"
119+
version = "1.0.0"
120+
source = "registry+https://scarbs.xyz/"
121+
checksum = "sha256:fd348b31c4a4407add33adc3c2b8f26dca71dbd7431faaf726168f37a91db0c1"
8122

9123
[[package]]
10124
name = "pyth"
@@ -14,7 +128,17 @@ dependencies = [
14128
"snforge_std",
15129
]
16130

131+
[[package]]
132+
name = "snforge_scarb_plugin"
133+
version = "0.38.3"
134+
source = "registry+https://scarbs.xyz/"
135+
checksum = "sha256:0cd914b547acd96b4cad99a78e95c0eda001d0c280da4969b2161e286079cf46"
136+
17137
[[package]]
18138
name = "snforge_std"
19-
version = "0.21.0"
20-
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.21.0#2996b8c1dd66b2715fc67e69578089f278a46790"
139+
version = "0.38.3"
140+
source = "registry+https://scarbs.xyz/"
141+
checksum = "sha256:d376526fbbe22535ad89ed630b11d6e209f22c50168de6c6430c0591c81c3174"
142+
dependencies = [
143+
"snforge_scarb_plugin",
144+
]
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
[package]
22
name = "pyth"
33
version = "0.1.0"
4-
edition = "2023_11"
4+
edition = "2024_07"
55

66
[dependencies]
7-
starknet = ">=2.5.4"
8-
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
9-
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }
7+
starknet = "2.11.1"
8+
openzeppelin = "1.0.0"
9+
10+
[dev-dependencies]
11+
snforge_std = "0.38.3"
1012

1113
[lib]
1214

1315
[[target.starknet-contract]]
14-
build-external-contracts = ["openzeppelin::presets::erc20::ERC20"]
16+
build-external-contracts = ["openzeppelin::presets::erc20::ERC20Upgradeable"]

target_chains/starknet/contracts/deploy/deploy.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Deploys Wormhole and Pyth contracts.
44
#
55
# Variables:
6-
# PYTH_DEPLOY_MODE - "katana" or "sepolia" (default: "katana")
6+
# PYTH_DEPLOY_MODE - "devnet" or "sepolia" (default: "devnet")
77
# PYTH_WORMHOLE_ADDRESS - if set, the script will use it instead of deploying a new Wormhole contract.
88
# When using sepolia, set STARKNET_ACCOUNT and STARKNET_KEYSTORE as well.
99

@@ -13,19 +13,20 @@ set -o pipefail
1313
set -x
1414

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

19-
if [ "${PYTH_DEPLOY_MODE}" == "katana" ]; then
20-
export STARKNET_ACCOUNT=katana-0
19+
if [ "${PYTH_DEPLOY_MODE}" == "devnet" ]; then
2120
export STARKNET_RPC=http://0.0.0.0:5050
21+
export STARKNET_ACCOUNT=0x064b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
22+
export STARKNET_ACCOUNT_PK=0x0000000000000000000000000000000071d7bb07b9a64f6f78ac4c816aff4da9
2223

2324
chain_id=50075 # starknet_sepolia
2425

25-
# predeployed fee token contract in katana
26+
# predeployed fee token contract in devnet
2627
fee_token_address1=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
2728

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

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

6466
# deploying wormhole with mainnet guardians
6567

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

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

102104
emitter_chain_id1=26
103105
emitter_address1=0xf8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0
@@ -108,7 +110,7 @@ emitter_address2=0xe101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4a
108110
governance_emitter_chain_id=1
109111
governance_emitter_address=0x5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e
110112

111-
pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" \
113+
pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" --account ./account.json --private-key ${STARKNET_ACCOUNT_PK} \
112114
"${PYTH_WORMHOLE_ADDRESS}" \
113115
"${fee_token_address1}" \
114116
1 0 `# fee_amount1` \
@@ -122,9 +124,9 @@ pyth_address=$(starkli deploy --not-unique --salt 0 --watch "${pyth_hash}" \
122124
0 `# governance_initial_sequence` \
123125
)
124126

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

127-
starkli invoke --watch "${pyth_address}" update_price_feeds \
129+
starkli invoke --watch "${pyth_address}" --account ./account.json --private-key ${STARKNET_ACCOUNT_PK} update_price_feeds \
128130
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
129131

130132
>&2 echo Pyth contract has been successfully deployed at "${pyth_address}"

target_chains/starknet/contracts/src/byte_buffer.cairo

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl DebugByteBuffer of Debug<ByteBuffer> {
2222
Option::Some(v) => { write!(f, "{:?}, ", v).unwrap(); },
2323
Option::None => { break; },
2424
}
25-
};
25+
}
2626
write!(f, "]}}")
2727
}
2828
}
@@ -45,7 +45,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {
4545
let last: u256 = (*data.at(data.len() - 1)).into();
4646
assert!(
4747
last / one_shift_left_bytes_u256(num_last_bytes) == 0,
48-
"ByteBufferImpl::new: last value is too large"
48+
"ByteBufferImpl::new: last value is too large",
4949
);
5050
}
5151
ByteBuffer { num_last_bytes, data }
@@ -75,8 +75,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {
7575

7676
#[cfg(test)]
7777
mod tests {
78-
use super::{ByteBuffer, ByteBufferImpl};
79-
use pyth::util::array_try_into;
78+
use super::ByteBufferImpl;
8079

8180
#[test]
8281
fn empty_byte_array() {
@@ -132,7 +131,7 @@ mod tests {
132131
let value2_31_bytes = 0x2122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f;
133132
let value3_5_bytes = 0x4142434445;
134133
let mut array = ByteBufferImpl::new(
135-
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5
134+
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5,
136135
);
137136
assert!(array.len() == 67);
138137
assert!(array.pop_front() == Option::Some((value_31_bytes, 31)));

0 commit comments

Comments
 (0)