Skip to content

Commit 8da293e

Browse files
authored
fix(price_feeds/starknet): fix deploy script and add readme (#17)
* chore(price_feeds/starknet): rename local_deploy to deploy.js * fix(price_feeds/starknet): fix deploy script and add readme
1 parent 4070041 commit 8da293e

File tree

4 files changed

+107
-66
lines changed

4 files changed

+107
-66
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Send-USD example for Starknet
2+
3+
This contract demonstrates usage of Pyth Price Feeds on Starknet. See [this page](https://docs.pyth.network/price-feeds/use-real-time-data/starknet) for more information.
4+
5+
## Setting up your environment
6+
7+
1. Install Scarb (the Cairo and Starknet development toolchain) by following [the installation instructions](https://docs.swmansion.com/scarb/download).
8+
2. Install Starknet Foundry by following [the installation instructions](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html).
9+
3. Install Starkli (a cli tool for Starknet) by following [the installation instructions](https://github.com/xJonathanLEI/starkli).
10+
4. Install Katana (a local Starknet node) by following [the installation instructions](https://book.starknet.io/ch02-04-katana.html).
11+
12+
The `.tool-versions` file in the `contract` directory specifies the tool versions used by the contract.
13+
14+
## Local deployment
15+
16+
1. Start `katana` and keep it running in a separate shell.
17+
2. Deploy pyth contract to katana by running the following commands:
18+
19+
```bash
20+
git clone https://github.com/pyth-network/pyth-crosschain.git
21+
cd pyth-crosschain/target_chains/starknet/contracts
22+
deploy/deploy.sh > ~/pyth.env
23+
```
24+
25+
This generates `~/pyth.env` file that should contain the address of the deployed contract, for example:
26+
27+
```bash
28+
$ cat ~/pyth.env
29+
PYTH_WORMHOLE_ADDRESS=0x07fa5a689a768982ecb60ed05f39ca8f6efe623dd32ee6f3608662e3452a104c
30+
PYTH_CONTRACT_ADDRESS=0x00f61bf0314a478bfc865c71d33cc53c77d0f994ea4a228ccf888d14435a8821
31+
```
32+
33+
3. Apply these variables to your current shell:
34+
35+
```bash
36+
export $(xargs < ~/pyth.env)
37+
```
38+
39+
4. Run Send-USD deploy script:
40+
41+
```bash
42+
cd pyth-examples/price_feeds/starknet/send_usd/contract
43+
deploy/deploy.sh > ~/send_usd.env
44+
```
45+
46+
To verify your deployment, do the following steps:
47+
48+
1. Apply `SEND_USD_CONTRACT_ADDRESS` variable to your current shell:
49+
50+
```bash
51+
export $(xargs < ~/send_usd.env)
52+
```
53+
54+
2. Set the following variables:
55+
56+
```bash
57+
export ACCOUNT_PRIVATE_KEY=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
58+
export ACCOUNT_ADDRESS=0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca
59+
```
60+
This account should be pre-deployed and pre-funded in katana, so you will be able to send transactions from it.
61+
62+
3. Run the client:
63+
64+
```bash
65+
cd ../client
66+
npm install
67+
npm run start
68+
```

price_feeds/starknet/send_usd/client/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ async function main() {
1818

1919
const destination = '0x42';
2020

21-
const sendUsdAddress = process.env.SEND_USD_ADDRESS;
21+
const sendUsdAddress = process.env.SEND_USD_CONTRACT_ADDRESS;
2222
if (sendUsdAddress === undefined) {
23-
throw new Error('missing sendUsdAddress');
23+
throw new Error('missing SEND_USD_CONTRACT_ADDRESS env var');
2424
}
2525

2626
// Create a `Contract` instance to interact with ETH token contract on Starknet.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
set -x
7+
8+
starkli --version 1>&2
9+
scarb --version 1>&2
10+
11+
export STARKNET_ACCOUNT=katana-0
12+
export STARKNET_RPC=http://0.0.0.0:5050
13+
14+
cd "$(dirname "$0")/.."
15+
scarb build 1>&2
16+
17+
# predeployed fee token contract in katana
18+
fee_token_address=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
19+
20+
if [ -z ${PYTH_CONTRACT_ADDRESS+x} ]; then
21+
>&2 echo "Missing PYTH_CONTRACT_ADDRESS env var"
22+
exit 1
23+
fi
24+
25+
send_usd_hash=$(starkli declare --watch target/dev/send_usd_send_usd.contract_class.json)
26+
27+
# STRK/USD
28+
price_feed_id=0x6a182399ff70ccf3e06024898942028204125a819e519a335ffa4579e66cd870
29+
30+
send_usd_address=$(starkli deploy --watch "${send_usd_hash}" \
31+
"${PYTH_CONTRACT_ADDRESS}" \
32+
"${fee_token_address}" \
33+
)
34+
35+
>&2 echo send_usd contract has been successfully deployed at "${send_usd_address}"
36+
37+
echo "SEND_USD_CONTRACT_ADDRESS=${send_usd_address}"

price_feeds/starknet/send_usd/contract/deploy/local_deploy

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)