Skip to content

Commit 2caa491

Browse files
add shank example by joe and clockwork reference
1 parent 9831611 commit 2caa491

31 files changed

+1790
-0
lines changed

tools/clockwork/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Clockwork is an automation infrastructure for Solana. It allows you to schedule transactions and build automated, event driven programs.
2+
3+
Here is a link to the Clockwork Program Examples repository: [Clockwork](https://github.com/clockwork-xyz/clockwork)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[v1]
2+
"shank-cli 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = ["shank"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"installs":{"shank-cli 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)":{"version_req":"0.0.12","bins":["shank"],"features":[],"all_features":false,"no_default_features":false,"profile":"release","target":"aarch64-apple-darwin","rustc":"rustc 1.66.1 (90743e729 2023-01-10)\nbinary: rustc\ncommit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6\ncommit-date: 2023-01-10\nhost: aarch64-apple-darwin\nrelease: 1.66.1\nLLVM version: 15.0.2\n"}}}
5.67 MB
Binary file not shown.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path');
2+
const programDir = path.join(__dirname, 'program');
3+
const idlDir = path.join(programDir, 'idl');
4+
const sdkDir = path.join(__dirname, 'tests', 'generated');
5+
const binaryInstallDir = path.join(__dirname, '.crates');
6+
7+
module.exports = {
8+
idlGenerator: 'shank',
9+
programName: 'car_rental_service',
10+
idlDir,
11+
sdkDir,
12+
binaryInstallDir,
13+
programDir,
14+
};
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Shank & Solita
2+
3+
The devs at Metaplex created Shank & Solita for native Solana programs to be able to take advantage of serialization & IDLs just like Anchor programs.
4+
5+
### Shank
6+
7+
[Shank](https://docs.metaplex.com/developer-tools/shank) is the Rust crate responsible for generating an IDL for your program.
8+
9+
It's super easy to use in your Rust code:
10+
11+
Add this annotation to any struct to mark it as an account:
12+
```rust
13+
#[derive(ShankAccount)]
14+
```
15+
ex:
16+
```rust
17+
#[derive(BorshDeserialize, BorshSerialize, Clone, ShankAccount)]
18+
pub struct Car {
19+
pub year: u16,
20+
pub make: String,
21+
pub model: String,
22+
}
23+
```
24+
25+
Add this annotation to any enum to mark it as an instruction enum:
26+
```rust
27+
#[derive(ShankInstruction)]
28+
```
29+
ex:
30+
```rust
31+
#[derive(BorshDeserialize, BorshSerialize, Clone, ShankInstruction)]
32+
pub enum CarRentalServiceInstruction {
33+
AddCar(Car),
34+
BookRental(RentalOrder),
35+
PickUpCar,
36+
ReturnCar,
37+
}
38+
```
39+
40+
Then you just need to add the Shank CLI:
41+
```shell
42+
cargo install shank-cli
43+
```
44+
```shell
45+
USAGE:
46+
shank <SUBCOMMAND>
47+
48+
OPTIONS:
49+
-h, --help Print help information
50+
51+
SUBCOMMANDS:
52+
help Print this message or the help of the given subcommand(s)
53+
idl
54+
```
55+
56+
> Note: You do have to make use of `declare_id` in order for Shank to work properly:
57+
```rust
58+
declare_id!("8avNGHVXDwsELJaWMSoUZ44CirQd4zyU9Ez4ZmP4jNjZ");
59+
```
60+
61+
### Solita
62+
63+
[Solita](https://docs.metaplex.com/developer-tools/solita/) is the JavaScript SDK responsible for building client-side SDK types from your program's IDL.
64+
65+
> Note: Solita will work with an IDL from Shank or from Anchor!
66+
67+
First add Solita to your project:
68+
```shell
69+
yarn add -D @metaplex-foundation/solita
70+
```
71+
Then add a Solita config `.solitarc.js`:
72+
```javascript
73+
const path = require('path');
74+
const programDir = path.join(__dirname, 'program');
75+
const idlDir = path.join(programDir, 'idl');
76+
const sdkDir = path.join(__dirname, 'tests', 'generated');
77+
const binaryInstallDir = path.join(__dirname, '.crates');
78+
79+
module.exports = {
80+
idlGenerator: 'shank',
81+
programName: 'car_rental_service',
82+
idlDir,
83+
sdkDir,
84+
binaryInstallDir,
85+
programDir,
86+
};
87+
```
88+
89+
Once you've got that file configured to match your repository layout, go ahead and run:
90+
```shell
91+
yarn solita
92+
```
93+
94+
That should build all your types from your IDL! Check for a folder called `generated` to see them!
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"scripts": {
3+
"test": "ts-mocha -p ./tests/tsconfig.test.json -t 1000000 ./tests/test.ts"
4+
},
5+
"devDependencies": {
6+
"@metaplex-foundation/solita": "^0.19.3",
7+
"@types/chai": "^4.3.4",
8+
"@types/mocha": "^10.0.1",
9+
"chai": "^4.3.7",
10+
"mocha": "^10.2.0",
11+
"ts-mocha": "^10.0.0",
12+
"typescript": "^4.9.4"
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "car-rental-service"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
borsh = "0.9.3"
8+
borsh-derive = "0.9.3"
9+
shank = "0.0.12"
10+
solana-program = "1.14.13"
11+
12+
[lib]
13+
crate-type = ["cdylib", "lib"]

0 commit comments

Comments
 (0)