Skip to content

Commit

Permalink
solana: separate token accounts (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: A5 Pickle <a5-pickle@users.noreply.github.com>
  • Loading branch information
a5-pickle and a5-pickle authored Mar 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 718b966 commit fe36270
Showing 65 changed files with 6,217 additions and 6,246 deletions.
3 changes: 3 additions & 0 deletions solana/Cargo.toml
Original file line number Diff line number Diff line change
@@ -58,3 +58,6 @@ codegen-units = 1
opt-level = 3
incremental = false
codegen-units = 1

[workspace.lints.clippy]
cast_possible_truncation = "deny"
34 changes: 17 additions & 17 deletions solana/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
SOLANA_CLI="v1.16.16"
ANCHOR_CLI="v0.28.0"

out_mainnet=artifacts-mainnet
out_testnet=artifacts-testnet
out_localnet=artifacts-localnet

.PHONY: all clean check build test lint ci cargo-test

.PHONY: all
all: check

.PHONY: check
check:
cargo check --all-features
cargo check --workspace --all-targets --all-features

.PHONY: clean
clean:
anchor clean
rm -rf node_modules artifacts-mainnet artifacts-testnet artifacts-localnet ts/tests/artifacts

node_modules:
node_modules: package-lock.json
npm ci

cargo-test $(NETWORK):
cargo test --features "$(NETWORK)" --no-default-features
.PHONY: cargo-test
cargo-test:
cargo test --workspace --all-targets --features $(NETWORK)

.PHONY: build
build: $(out_$(NETWORK))
$(out_$(NETWORK)): cargo-test
ifdef out_$(NETWORK)
@@ -30,6 +30,7 @@ ifdef out_$(NETWORK)
cp target/deploy/*.so $(out_$(NETWORK))/
endif

.PHONY: test
test: node_modules
NETWORK=localnet $(MAKE) cargo-test
NETWORK=testnet $(MAKE) cargo-test
@@ -41,13 +42,12 @@ test: node_modules
anchor build --arch sbf -- --features integration-test
anchor test --skip-build

.PHONY: clippy
clippy:
cargo clippy --workspace --no-deps --all-targets --features $(NETWORK) -- -Dwarnings

.PHONY: lint
lint:
cargo fmt --check
cargo clippy --no-deps --all-targets --features testnet -- -D warnings
cargo clippy --no-deps --all-targets --features localnet -- -D warnings

ci:
DOCKER_BUILDKIT=1 docker build -f Dockerfile.ci \
--build-arg SOLANA_CLI=$(SOLANA_CLI) \
--build-arg ANCHOR_CLI=$(ANCHOR_CLI) \
.
NETWORK=localnet $(MAKE) clippy
NETWORK=testnet $(MAKE) clippy
30 changes: 24 additions & 6 deletions solana/modules/common/src/admin/utils/assistant.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
use crate::admin::OwnerAssistant;
use anchor_lang::prelude::*;

pub fn only_owner_assistant<A>(acct: &Account<A>, owner_assistant: &Pubkey) -> bool
pub fn only_owner_assistant<A>(
acct: &Account<A>,
owner_assistant: &Signer,
custom_error: Error,
) -> Result<bool>
where
A: OwnerAssistant + Clone + AccountSerialize + AccountDeserialize,
{
acct.owner_assistant() == owner_assistant
if acct.owner_assistant() == &owner_assistant.key() {
Ok(true)
} else {
Err(custom_error.with_pubkeys((*acct.owner_assistant(), owner_assistant.key())))
}
}

pub fn only_authorized<A>(acct: &Account<A>, owner_or_assistant: &Pubkey) -> bool
pub fn only_authorized<A>(
acct: &Account<A>,
owner_or_assistant: &Signer,
custom_error: Error,
) -> Result<bool>
where
A: OwnerAssistant + Clone + AccountSerialize + AccountDeserialize,
{
acct.owner() == owner_or_assistant || acct.owner_assistant() == owner_or_assistant
if acct.owner() == &owner_or_assistant.key()
|| acct.owner_assistant() == &owner_or_assistant.key()
{
Ok(true)
} else {
Err(custom_error)
}
}

pub fn transfer_owner_assistant<A>(acct: &mut Account<A>, new_assistant: &Pubkey)
pub fn transfer_owner_assistant<A>(acct: &mut Account<A>, new_assistant: &AccountInfo)
where
A: OwnerAssistant + Clone + AccountSerialize + AccountDeserialize,
{
*acct.owner_assistant_mut() = *new_assistant;
*acct.owner_assistant_mut() = new_assistant.key();
}
12 changes: 8 additions & 4 deletions solana/modules/common/src/admin/utils/ownable.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use crate::admin::Ownable;
use anchor_lang::prelude::*;

pub fn only_owner<A>(acct: &Account<A>, owner: &Pubkey) -> bool
pub fn only_owner<A>(acct: &Account<A>, owner: &Signer, custom_error: Error) -> Result<bool>
where
A: Ownable + Clone + AccountSerialize + AccountDeserialize,
{
*acct.owner() == *owner
if acct.owner() == &owner.key() {
Ok(true)
} else {
Err(custom_error.with_pubkeys((*acct.owner(), owner.key())))
}
}

pub fn transfer_ownership<A>(acct: &mut Account<A>, new_owner: &Pubkey)
pub fn transfer_ownership<A>(acct: &mut Account<A>, new_owner: &AccountInfo)
where
A: Ownable + Clone + AccountSerialize + AccountDeserialize,
{
*acct.owner_mut() = *new_owner;
*acct.owner_mut() = new_owner.key();
}
5 changes: 4 additions & 1 deletion solana/programs/matching-engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -34,4 +34,7 @@ ruint.workspace = true
cfg-if.workspace = true

[dev-dependencies]
hex-literal.workspace = true
hex-literal.workspace = true

[lints]
workspace = true
Loading

0 comments on commit fe36270

Please sign in to comment.