Skip to content

Commit f01ac04

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 sanity rename (judgement call): - `handle_make_escrow` → `handle_save_offer` (body now constructs an `Offer`, not an `Escrow`; also matches Anchor's `handle_save_offer`). 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`, `handle_withdraw_tokens_and_close_refund`). The `_refund` suffix reads worse as `_cancel_offer`. - PDA seed bytes (`b"escrow"`). Changing them would alter PDA derivation (behaviour change). This is rename-only. Verification: cd tokens/escrow/anchor && cargo check Finished `dev` profile [unoptimized + debuginfo] target(s) in 38.87s cd tokens/escrow/quasar && cargo check Finished `dev` profile [unoptimized + debuginfo] target(s) in 23.40s cd tokens/escrow/quasar && cargo check --tests Finished `dev` profile [unoptimized + debuginfo] target(s) in 41.77s (The Quasar warnings about never-read fields are a `#[account]` codegen quirk and pre-date this change.)
1 parent 586902b commit f01ac04

9 files changed

Lines changed: 265 additions & 265 deletions

File tree

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
use {
2-
crate::state::Escrow,
2+
crate::state::Offer,
33
quasar_lang::prelude::*,
44
quasar_spl::prelude::*,
55
};
66

77
#[derive(Accounts)]
8-
pub struct Refund {
8+
pub struct CancelOffer {
99
#[account(mut)]
1010
pub maker: Signer,
1111
#[account(
1212
mut,
1313
has_one(maker),
1414
close(dest = maker),
15-
address = Escrow::seeds(maker.address())
15+
address = Offer::seeds(maker.address())
1616
)]
17-
pub escrow: Account<Escrow>,
18-
pub mint_a: Account<Mint>,
17+
pub offer: Account<Offer>,
18+
pub token_mint_a: Account<Mint>,
1919
#[account(
2020
mut,
2121
init(idempotent),
2222
payer = maker,
23-
token(mint = mint_a, authority = maker, token_program = token_program),
23+
token(mint = token_mint_a, authority = maker, token_program = token_program),
2424
)]
25-
pub maker_ta_a: Account<Token>,
25+
pub maker_token_account_a: Account<Token>,
2626
#[account(mut)]
27-
pub vault_ta_a: Account<Token>,
27+
pub vault: Account<Token>,
2828
pub rent: Sysvar<Rent>,
2929
pub token_program: Program<TokenProgram>,
3030
pub system_program: Program<SystemProgram>,
3131
}
3232

3333
#[inline(always)]
34-
pub fn handle_withdraw_tokens_and_close_refund(accounts: &mut Refund, bumps: &RefundBumps) -> Result<(), ProgramError> {
35-
let bump = [bumps.escrow];
34+
pub fn handle_withdraw_tokens_and_close_refund(accounts: &mut CancelOffer, bumps: &CancelOfferBumps) -> Result<(), ProgramError> {
35+
let bump = [bumps.offer];
3636
let seeds = [
3737
Seed::from(b"escrow" as &[u8]),
3838
Seed::from(accounts.maker.address().as_ref()),
@@ -41,15 +41,15 @@ pub fn handle_withdraw_tokens_and_close_refund(accounts: &mut Refund, bumps: &Re
4141

4242
accounts.token_program
4343
.transfer(
44-
&accounts.vault_ta_a,
45-
&accounts.maker_ta_a,
46-
&accounts.escrow,
47-
accounts.vault_ta_a.amount(),
44+
&accounts.vault,
45+
&accounts.maker_token_account_a,
46+
&accounts.offer,
47+
accounts.vault.amount(),
4848
)
4949
.invoke_signed(&seeds)?;
5050

5151
accounts.token_program
52-
.close_account(&accounts.vault_ta_a, &accounts.maker, &accounts.escrow)
52+
.close_account(&accounts.vault, &accounts.maker, &accounts.offer)
5353
.invoke_signed(&seeds)?;
5454
Ok(())
5555
}

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_save_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/take.rs

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use {
2+
crate::state::Offer,
3+
quasar_lang::prelude::*,
4+
quasar_spl::prelude::*,
5+
};
6+
7+
#[derive(Accounts)]
8+
pub struct TakeOffer {
9+
#[account(mut)]
10+
pub taker: Signer,
11+
#[account(
12+
mut,
13+
has_one(maker),
14+
has_one(maker_token_account_b),
15+
constraints(offer.receive > 0),
16+
close(dest = taker),
17+
address = Offer::seeds(maker.address())
18+
)]
19+
pub offer: Account<Offer>,
20+
#[account(mut)]
21+
pub maker: UncheckedAccount,
22+
pub token_mint_a: Account<Mint>,
23+
pub token_mint_b: Account<Mint>,
24+
#[account(
25+
mut,
26+
init(idempotent),
27+
payer = taker,
28+
token(mint = token_mint_a, authority = taker, token_program = token_program),
29+
)]
30+
pub taker_token_account_a: Account<Token>,
31+
#[account(mut)]
32+
pub taker_token_account_b: Account<Token>,
33+
#[account(
34+
mut,
35+
init(idempotent),
36+
payer = taker,
37+
token(mint = token_mint_b, authority = maker, token_program = token_program),
38+
)]
39+
pub maker_token_account_b: Account<Token>,
40+
#[account(mut)]
41+
pub vault: Account<Token>,
42+
pub rent: Sysvar<Rent>,
43+
pub token_program: Program<TokenProgram>,
44+
pub system_program: Program<SystemProgram>,
45+
}
46+
47+
#[inline(always)]
48+
pub fn handle_transfer_tokens(accounts: &mut TakeOffer) -> Result<(), ProgramError> {
49+
accounts.token_program
50+
.transfer(
51+
&accounts.taker_token_account_b,
52+
&accounts.maker_token_account_b,
53+
&accounts.taker,
54+
accounts.offer.receive,
55+
)
56+
.invoke()
57+
}
58+
59+
#[inline(always)]
60+
pub fn handle_withdraw_tokens_and_close_take(accounts: &mut TakeOffer, bumps: &TakeOfferBumps) -> Result<(), ProgramError> {
61+
let bump = [bumps.offer];
62+
let seeds = [
63+
Seed::from(b"escrow" as &[u8]),
64+
Seed::from(accounts.maker.address().as_ref()),
65+
Seed::from(bump.as_ref()),
66+
];
67+
68+
accounts.token_program
69+
.transfer(
70+
&accounts.vault,
71+
&accounts.taker_token_account_a,
72+
&accounts.offer,
73+
accounts.vault.amount(),
74+
)
75+
.invoke_signed(&seeds)?;
76+
77+
accounts.token_program
78+
.close_account(&accounts.vault, &accounts.taker, &accounts.offer)
79+
.invoke_signed(&seeds)?;
80+
Ok(())
81+
}

tokens/escrow/quasar/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ mod quasar_escrow {
1818
use super::*;
1919

2020
#[instruction(discriminator = 0)]
21-
pub fn make(ctx: Ctx<Make>, deposit: u64, receive: u64) -> Result<(), ProgramError> {
22-
instructions::make::handle_make_escrow(&mut ctx.accounts, receive, &ctx.bumps)?;
23-
instructions::make::handle_deposit_tokens(&mut ctx.accounts, deposit)
21+
pub fn make_offer(ctx: Ctx<MakeOffer>, deposit: u64, receive: u64) -> Result<(), ProgramError> {
22+
instructions::make_offer::handle_save_offer(&mut ctx.accounts, receive, &ctx.bumps)?;
23+
instructions::make_offer::handle_deposit_tokens(&mut ctx.accounts, deposit)
2424
}
2525

2626
#[instruction(discriminator = 1)]
27-
pub fn take(ctx: Ctx<Take>) -> Result<(), ProgramError> {
28-
instructions::take::handle_transfer_tokens(&mut ctx.accounts)?;
29-
instructions::take::handle_withdraw_tokens_and_close_take(&mut ctx.accounts, &ctx.bumps)
27+
pub fn take_offer(ctx: Ctx<TakeOffer>) -> Result<(), ProgramError> {
28+
instructions::take_offer::handle_transfer_tokens(&mut ctx.accounts)?;
29+
instructions::take_offer::handle_withdraw_tokens_and_close_take(&mut ctx.accounts, &ctx.bumps)
3030
}
3131

3232
#[instruction(discriminator = 2)]
33-
pub fn refund(ctx: Ctx<Refund>) -> Result<(), ProgramError> {
34-
instructions::refund::handle_withdraw_tokens_and_close_refund(&mut ctx.accounts, &ctx.bumps)
33+
pub fn cancel_offer(ctx: Ctx<CancelOffer>) -> Result<(), ProgramError> {
34+
instructions::cancel_offer::handle_withdraw_tokens_and_close_refund(&mut ctx.accounts, &ctx.bumps)
3535
}
3636
}

0 commit comments

Comments
 (0)