Skip to content

Commit a0aa8f1

Browse files
author
Mike MacCana
committed
chore(escrow): align Quasar and Anchor escrow naming for side-by-side comparison
Mike's writing an Anchor-vs-Quasar comparison doc. The two implementations diverged cosmetically: Anchor had been refactored to canonical names (`make_offer`/`take_offer`/`cancel_offer`, `Offer` state, `token_mint_a`, `maker_token_account_a`, etc.), but Quasar still used the older `make`/`take`/ `refund` with `Escrow` state and `mint_a`/`maker_ta_a`-style fields. Those surface-level differences make it hard to compare framework syntax without also tracking name differences. This commit renames Quasar to match Anchor. Renames in Quasar (rename-only, no behaviour change): Handlers: - `make` → `make_offer` - `take` → `take_offer` - `refund` → `cancel_offer` Account structs (+ associated `*Bumps`): - `Make` → `MakeOffer` - `Take` → `TakeOffer` - `Refund` → `CancelOffer` State type: - `Escrow` → `Offer` (in `src/state.rs`) Account fields: - `mint_a` → `token_mint_a` - `mint_b` → `token_mint_b` - `maker_ta_a` → `maker_token_account_a` - `maker_ta_b` → `maker_token_account_b` - `taker_ta_a` → `taker_token_account_a` - `taker_ta_b` → `taker_token_account_b` - `vault_ta_a` → `vault` - `escrow` → `offer` (the state account field on each instruction) Source files: - `src/instructions/make.rs` → `make_offer.rs` - `src/instructions/take.rs` → `take_offer.rs` - `src/instructions/refund.rs` → `cancel_offer.rs` Internal helper renames: - `handle_make_escrow` → `handle_make_offer` (natural pairing with the public `make_offer` handler; body constructs an `Offer`, not an `Escrow`). - `handle_withdraw_tokens_and_close_refund` → `handle_withdraw_tokens_and_close_cancel_offer` (pairs with the public `cancel_offer` handler; "refund" is dead as a verb in the rename spec). Deliberately NOT renamed: - Crate / directory names (`tokens/escrow/anchor/programs/escrow/`, `tokens/escrow/quasar/`). The program is called "escrow"; the state inside is called "Offer". Both correct. - Other internal helpers (`handle_deposit_tokens`, `handle_transfer_tokens`, `handle_withdraw_tokens_and_close_take`). Breaking changes: - PDA seed for the offer state account changed from `b"escrow"` to `b"offer"` in the Quasar program, matching Anchor. This alters PDA derivation, but this is an example program with no deployed users and the alignment is worth it. Verification: cd tokens/escrow/anchor && cargo check Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.80s cd tokens/escrow/quasar && cargo check Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.46s cd tokens/escrow/quasar && cargo check --tests Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.33s (The Quasar warnings about never-read fields are a `#[account]` codegen quirk and pre-date this change.)
1 parent 586902b commit a0aa8f1

10 files changed

Lines changed: 309 additions & 309 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use {
2+
crate::state::Offer,
3+
quasar_lang::prelude::*,
4+
quasar_spl::prelude::*,
5+
};
6+
7+
#[derive(Accounts)]
8+
pub struct CancelOffer {
9+
#[account(mut)]
10+
pub maker: Signer,
11+
#[account(
12+
mut,
13+
has_one(maker),
14+
close(dest = maker),
15+
address = Offer::seeds(maker.address())
16+
)]
17+
pub offer: Account<Offer>,
18+
pub token_mint_a: Account<Mint>,
19+
#[account(
20+
mut,
21+
init(idempotent),
22+
payer = maker,
23+
token(mint = token_mint_a, authority = maker, token_program = token_program),
24+
)]
25+
pub maker_token_account_a: Account<Token>,
26+
#[account(mut)]
27+
pub vault: Account<Token>,
28+
pub rent: Sysvar<Rent>,
29+
pub token_program: Program<TokenProgram>,
30+
pub system_program: Program<SystemProgram>,
31+
}
32+
33+
#[inline(always)]
34+
pub fn handle_withdraw_tokens_and_close_cancel_offer(accounts: &mut CancelOffer, bumps: &CancelOfferBumps) -> Result<(), ProgramError> {
35+
let bump = [bumps.offer];
36+
let seeds = [
37+
Seed::from(b"offer" as &[u8]),
38+
Seed::from(accounts.maker.address().as_ref()),
39+
Seed::from(bump.as_ref()),
40+
];
41+
42+
accounts.token_program
43+
.transfer(
44+
&accounts.vault,
45+
&accounts.maker_token_account_a,
46+
&accounts.offer,
47+
accounts.vault.amount(),
48+
)
49+
.invoke_signed(&seeds)?;
50+
51+
accounts.token_program
52+
.close_account(&accounts.vault, &accounts.maker, &accounts.offer)
53+
.invoke_signed(&seeds)?;
54+
Ok(())
55+
}

tokens/escrow/quasar/src/instructions/make.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use {
2+
crate::state::{Offer, OfferInner},
3+
quasar_lang::prelude::*,
4+
quasar_spl::prelude::*,
5+
};
6+
7+
#[derive(Accounts)]
8+
pub struct MakeOffer {
9+
#[account(mut)]
10+
pub maker: Signer,
11+
#[account(mut, init, payer = maker, address = Offer::seeds(maker.address()))]
12+
pub offer: Account<Offer>,
13+
pub token_mint_a: Account<Mint>,
14+
pub token_mint_b: Account<Mint>,
15+
#[account(mut)]
16+
pub maker_token_account_a: Account<Token>,
17+
#[account(
18+
mut,
19+
init(idempotent),
20+
payer = maker,
21+
token(mint = token_mint_b, authority = maker, token_program = token_program),
22+
)]
23+
pub maker_token_account_b: Account<Token>,
24+
#[account(
25+
mut,
26+
init(idempotent),
27+
payer = maker,
28+
token(mint = token_mint_a, authority = offer, token_program = token_program),
29+
)]
30+
pub vault: Account<Token>,
31+
pub rent: Sysvar<Rent>,
32+
pub token_program: Program<TokenProgram>,
33+
pub system_program: Program<SystemProgram>,
34+
}
35+
36+
#[inline(always)]
37+
pub fn handle_make_offer(accounts: &mut MakeOffer, receive: u64, bumps: &MakeOfferBumps) -> Result<(), ProgramError> {
38+
accounts.offer.set_inner(OfferInner {
39+
maker: *accounts.maker.address(),
40+
token_mint_a: *accounts.token_mint_a.address(),
41+
token_mint_b: *accounts.token_mint_b.address(),
42+
maker_token_account_b: *accounts.maker_token_account_b.address(),
43+
receive,
44+
bump: bumps.offer,
45+
});
46+
Ok(())
47+
}
48+
49+
#[inline(always)]
50+
pub fn handle_deposit_tokens(accounts: &mut MakeOffer, amount: u64) -> Result<(), ProgramError> {
51+
accounts.token_program
52+
.transfer(&accounts.maker_token_account_a, &accounts.vault, &accounts.maker, amount)
53+
.invoke()
54+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pub mod make;
2-
pub use make::*;
1+
pub mod make_offer;
2+
pub use make_offer::*;
33

4-
pub mod take;
5-
pub use take::*;
4+
pub mod take_offer;
5+
pub use take_offer::*;
66

7-
pub mod refund;
8-
pub use refund::*;
7+
pub mod cancel_offer;
8+
pub use cancel_offer::*;

tokens/escrow/quasar/src/instructions/refund.rs

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

tokens/escrow/quasar/src/instructions/take.rs

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

0 commit comments

Comments
 (0)