Skip to content

Commit c8f47bb

Browse files
Added Python Tokens example + Tests
1 parent 3c224fa commit c8f47bb

File tree

18 files changed

+1737
-0
lines changed

18 files changed

+1737
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
**/*.rs.bk
6+
node_modules
7+
test-ledger
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
node_modules
6+
dist
7+
build
8+
test-ledger
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[features]
2+
seeds = true
3+
skip-lint = false
4+
[programs.localnet]
5+
seahorse = "5KCV219sxBAZMfXWP5EZ57D6K9568krgPKGe1Lq2nkxH"
6+
7+
[registry]
8+
url = "https://api.apr.dev"
9+
10+
[provider]
11+
cluster = "Localnet"
12+
wallet = "~/.config/solana/id.json"
13+
14+
[scripts]
15+
test = "python3 tests/seahorse.py"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
members = [
3+
"programs/*"
4+
]
5+
6+
[profile.release]
7+
overflow-checks = true
8+
lto = "fat"
9+
codegen-units = 1
10+
[profile.release.build-override]
11+
opt-level = 3
12+
incremental = false
13+
codegen-units = 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# seahorse
2+
3+
This project was created by Seahorse 0.2.7.
4+
5+
To get started, just add your code to **programs_py/seahorse.py** and run `seahorse build`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Migrations are an early feature. Currently, they're nothing more than this
2+
// single deploy script that's invoked from the CLI, injecting a provider
3+
// configured from the workspace's Anchor.toml.
4+
5+
const anchor = require("@coral-xyz/anchor");
6+
7+
module.exports = async function (provider) {
8+
// Configure client to use the provider.
9+
anchor.setProvider(provider);
10+
11+
// Add your deploy script here.
12+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"scripts": {
3+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
4+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
5+
},
6+
"dependencies": {
7+
"@coral-xyz/anchor": "^0.27.0"
8+
},
9+
"devDependencies": {
10+
"chai": "^4.3.4",
11+
"mocha": "^9.0.3",
12+
"ts-mocha": "^10.0.0",
13+
"@types/bn.js": "^5.1.0",
14+
"@types/chai": "^4.3.0",
15+
"@types/mocha": "^9.0.0",
16+
"typescript": "^4.3.5",
17+
"prettier": "^2.6.2"
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "seahorse"
3+
version = "0.1.0"
4+
description = "Created with Anchor"
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
name = "seahorse"
10+
11+
[features]
12+
no-entrypoint = []
13+
no-idl = []
14+
no-log-ix-name = []
15+
cpi = ["no-entrypoint"]
16+
default = []
17+
18+
[dependencies]
19+
anchor-lang = "0.27.0"
20+
anchor-spl = "0.27.0"
21+
pyth-sdk-solana = { version = "0.7.1", optional = true }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod program;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#![allow(unused_imports)]
2+
#![allow(unused_variables)]
3+
#![allow(unused_mut)]
4+
use crate::{id, seahorse_util::*};
5+
use anchor_lang::{prelude::*, solana_program};
6+
use anchor_spl::token::{self, Mint, Token, TokenAccount};
7+
use std::{cell::RefCell, rc::Rc};
8+
9+
pub fn create_associated_token_account_handler<'info>(
10+
mut token_account: Empty<SeahorseAccount<'info, '_, TokenAccount>>,
11+
mut mint: SeahorseAccount<'info, '_, Mint>,
12+
mut signer: SeahorseSigner<'info, '_>,
13+
) -> () {
14+
token_account.account.clone();
15+
}
16+
17+
pub fn create_token_handler<'info>(
18+
mut mint: Empty<SeahorseAccount<'info, '_, Mint>>,
19+
mut signer: SeahorseSigner<'info, '_>,
20+
) -> () {
21+
mint.account.clone();
22+
}
23+
24+
pub fn mint_token_handler<'info>(
25+
mut mint: SeahorseAccount<'info, '_, Mint>,
26+
mut recipient: SeahorseAccount<'info, '_, TokenAccount>,
27+
mut signer: SeahorseSigner<'info, '_>,
28+
mut amount: u64,
29+
) -> () {
30+
token::mint_to(
31+
CpiContext::new(
32+
mint.programs.get("token_program"),
33+
token::MintTo {
34+
mint: mint.to_account_info(),
35+
authority: signer.clone().to_account_info(),
36+
to: recipient.clone().to_account_info(),
37+
},
38+
),
39+
(amount * <u64 as TryFrom<_>>::try_from(10).unwrap().pow(6)),
40+
)
41+
.unwrap();
42+
}
43+
44+
pub fn transfer_handler<'info>(
45+
mut signer_token_account: SeahorseAccount<'info, '_, TokenAccount>,
46+
mut recipient: SeahorseAccount<'info, '_, TokenAccount>,
47+
mut signer: SeahorseSigner<'info, '_>,
48+
mut amount: u64,
49+
) -> () {
50+
token::transfer(
51+
CpiContext::new(
52+
signer_token_account.programs.get("token_program"),
53+
token::Transfer {
54+
from: signer_token_account.to_account_info(),
55+
authority: signer.clone().to_account_info(),
56+
to: recipient.clone().to_account_info(),
57+
},
58+
),
59+
(amount * <u64 as TryFrom<_>>::try_from(10).unwrap().pow(6)),
60+
)
61+
.unwrap();
62+
}

0 commit comments

Comments
 (0)