Skip to content

Commit c6bd633

Browse files
committed
solana: fix beneficiary in add history entry
1 parent c0d0308 commit c6bd633

File tree

4 files changed

+20
-91
lines changed

4 files changed

+20
-91
lines changed

solana/programs/matching-engine/src/processor/auction/history/add_entry.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
},
99
};
1010
use anchor_lang::{prelude::*, system_program};
11-
use anchor_spl::token;
1211

1312
#[derive(Accounts)]
1413
pub struct AddAuctionHistoryEntry<'info> {
@@ -62,21 +61,13 @@ pub struct AddAuctionHistoryEntry<'info> {
6261
)]
6362
auction: Account<'info, Auction>,
6463

65-
/// CHECK: This account will either be the owner of the fee recipient token account (if there
66-
/// was no auction) or the owner of the initial offer token account.
67-
#[account(mut)]
68-
beneficiary: UncheckedAccount<'info>,
69-
64+
/// CHECK: This account is whoever originally created the auction account (see
65+
/// [Auction::prepared_by].
7066
#[account(
71-
token::authority = beneficiary,
72-
address = {
73-
match &auction.info {
74-
Some(info) => info.initial_offer_token,
75-
None => custodian.fee_recipient_token,
76-
}
77-
}
67+
mut,
68+
address = auction.prepared_by,
7869
)]
79-
beneficiary_token: Account<'info, token::TokenAccount>,
70+
beneficiary: UncheckedAccount<'info>,
8071

8172
system_program: Program<'info, system_program::System>,
8273
}

solana/ts/src/idl/json/matching_engine.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@
6565
{
6666
"name": "beneficiary",
6767
"docs": [
68-
"was no auction) or the owner of the initial offer token account."
68+
"[Auction::prepared_by]."
6969
],
7070
"writable": true
7171
},
72-
{
73-
"name": "beneficiary_token"
74-
},
7572
{
7673
"name": "system_program"
7774
}

solana/ts/src/idl/ts/matching_engine.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@ export type MatchingEngine = {
7171
{
7272
"name": "beneficiary",
7373
"docs": [
74-
"was no auction) or the owner of the initial offer token account."
74+
"[Auction::prepared_by]."
7575
],
7676
"writable": true
7777
},
78-
{
79-
"name": "beneficiaryToken"
80-
},
8178
{
8279
"name": "systemProgram"
8380
}

solana/ts/tests/01__matchingEngine.ts

+13-69
Original file line numberDiff line numberDiff line change
@@ -3881,35 +3881,20 @@ describe("Matching Engine", function () {
38813881
);
38823882
});
38833883

3884-
it("Cannot Add Entry from Settled Complete Auction with Beneficiary Token != Initial Offer Token", async function () {
3884+
it("Cannot Add Entry from Settled Complete Auction with Beneficiary != Auction's Preparer", async function () {
38853885
await addAuctionHistoryEntryForTest(
38863886
{
38873887
payer: payer.publicKey,
38883888
history: engine.auctionHistoryAddress(0),
3889-
beneficiary: payer.publicKey,
3889+
beneficiary: Keypair.generate().publicKey,
38903890
},
38913891
{
38923892
settlementType: "complete",
3893-
errorMsg: "beneficiary_token. Error Code: ConstraintAddress",
3893+
errorMsg: "beneficiary. Error Code: ConstraintAddress",
38943894
},
38953895
);
38963896
});
38973897

3898-
it("Cannot Add Entry from Settled Complete Auction with Beneficiary != Initial Offer Token Owner", async function () {
3899-
await addAuctionHistoryEntryForTest(
3900-
{
3901-
payer: payer.publicKey,
3902-
history: engine.auctionHistoryAddress(0),
3903-
beneficiary: payer.publicKey,
3904-
beneficiaryToken: splToken.getAssociatedTokenAddressSync(
3905-
USDC_MINT_ADDRESS,
3906-
playerOne.publicKey,
3907-
),
3908-
},
3909-
{ settlementType: "complete", errorMsg: "Error Code: ConstraintTokenOwner" },
3910-
);
3911-
});
3912-
39133898
it("Add Entry from Settled Complete Auction After Expiration Time", async function () {
39143899
await addAuctionHistoryEntryForTest(
39153900
{
@@ -3936,30 +3921,17 @@ describe("Matching Engine", function () {
39363921
);
39373922
});
39383923

3939-
it("Cannot Close Auction Account from Settled Auction None with Beneficiary Token != Fee Recipient Token", async function () {
3924+
it("Cannot Close Auction Account from Settled Auction None with Beneficiary != Auction's Preparer", async function () {
39403925
await addAuctionHistoryEntryForTest(
39413926
{
39423927
payer: payer.publicKey,
39433928
history: engine.auctionHistoryAddress(0),
3944-
beneficiary: payer.publicKey,
3929+
beneficiary: Keypair.generate().publicKey,
39453930
},
39463931
{
39473932
settlementType: "none",
3948-
errorMsg: "beneficiary_token. Error Code: ConstraintAddress",
3949-
},
3950-
);
3951-
});
3952-
3953-
it("Cannot Close Auction Account from Settled Auction None with Beneficiary != Fee Recipient", async function () {
3954-
const { feeRecipientToken } = await engine.fetchCustodian();
3955-
await addAuctionHistoryEntryForTest(
3956-
{
3957-
payer: payer.publicKey,
3958-
history: engine.auctionHistoryAddress(0),
3959-
beneficiary: payer.publicKey,
3960-
beneficiaryToken: feeRecipientToken,
3933+
errorMsg: "beneficiary. Error Code: ConstraintAddress",
39613934
},
3962-
{ settlementType: "none", errorMsg: "Error Code: ConstraintTokenOwner" },
39633935
);
39643936
});
39653937

@@ -4161,7 +4133,6 @@ describe("Matching Engine", function () {
41614133
auction?: PublicKey;
41624134
history: PublicKey;
41634135
beneficiary?: PublicKey;
4164-
beneficiaryToken?: PublicKey;
41654136
},
41664137
opts: ForTestOpts &
41674138
ObserveCctpOrderVaasOpts &
@@ -4194,8 +4165,8 @@ describe("Matching Engine", function () {
41944165
return result!.auction;
41954166
} else if (settlementType == "none") {
41964167
const result = await settleAuctionNoneCctpForTest(
4197-
{ payer: payer.publicKey },
4198-
{ vaaTimestamp },
4168+
{ payer: playerOne.publicKey },
4169+
{ vaaTimestamp, signers: [playerOne] },
41994170
);
42004171
return result!.auction;
42014172
} else {
@@ -4209,47 +4180,19 @@ describe("Matching Engine", function () {
42094180
await waitUntilTimestamp(connection, current + timeToWait);
42104181
}
42114182

4212-
const { beneficiary, beneficiaryToken } = await (async () => {
4213-
if (accounts.beneficiary !== undefined) {
4214-
return {
4215-
beneficiary: accounts.beneficiary,
4216-
beneficiaryToken:
4217-
accounts.beneficiaryToken ??
4218-
splToken.getAssociatedTokenAddressSync(
4219-
USDC_MINT_ADDRESS,
4220-
accounts.beneficiary,
4221-
),
4222-
};
4223-
} else {
4224-
const { info } = await engine.fetchAuction({ address: auction });
4225-
const beneficiaryToken = await (async () => {
4226-
if (info === null) {
4227-
const custodian = await engine.fetchCustodian();
4228-
return custodian.feeRecipientToken;
4229-
} else {
4230-
return info!.initialOfferToken;
4231-
}
4232-
})();
4233-
const { owner } = await splToken.getAccount(connection, beneficiaryToken);
4234-
return {
4235-
beneficiary: owner,
4236-
beneficiaryToken: accounts.beneficiaryToken ?? beneficiaryToken,
4237-
};
4238-
}
4239-
})();
4240-
4241-
const { vaaHash, vaaTimestamp, info } = await engine.fetchAuction({
4183+
const { vaaHash, vaaTimestamp, info, preparedBy } = await engine.fetchAuction({
42424184
address: auction,
42434185
});
42444186
expect(info === null).equals(settlementType === "none");
42454187

4188+
const beneficiary = accounts.beneficiary ?? preparedBy;
4189+
42464190
const ix = await engine.program.methods
42474191
.addAuctionHistoryEntry()
42484192
.accounts({
42494193
...accounts,
42504194
auction,
42514195
beneficiary,
4252-
beneficiaryToken,
42534196
custodian: engine.checkedCustodianComposite(),
42544197
systemProgram: SystemProgram.programId,
42554198
})
@@ -4964,11 +4907,12 @@ describe("Matching Engine", function () {
49644907
} else {
49654908
const result = await prepareOrderResponseCctpForTest(
49664909
{
4967-
payer: payer.publicKey,
4910+
payer: accounts.payer,
49684911
},
49694912
{
49704913
...excludedForTestOpts,
49714914
placeInitialOffer: false,
4915+
signers,
49724916
},
49734917
);
49744918
expect(typeof result == "object" && "preparedOrderResponse" in result).is.true;

0 commit comments

Comments
 (0)