Permissioned crank integration test (#203)
This commit is contained in:
parent
57b9281374
commit
f1a6be3c4c
|
@ -26,7 +26,7 @@
|
|||
"@project-serum/anchor": "^0.18.2",
|
||||
"@project-serum/anchor-cli": "^0.18.2",
|
||||
"@project-serum/common": "^0.0.1-beta.3",
|
||||
"@project-serum/serum": "^0.13.55",
|
||||
"@project-serum/serum": "^0.13.61",
|
||||
"@solana/spl-token": "^0.1.6",
|
||||
"mocha": "^9.0.3"
|
||||
}
|
||||
|
|
|
@ -156,6 +156,28 @@ impl MarketMiddleware for Identity {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Accounts:
|
||||
///
|
||||
/// 0. Authorization token (revoked).
|
||||
/// ..
|
||||
fn consume_events_permissioned(&self, ctx: &mut Context, _limit: &mut u16) -> ProgramResult {
|
||||
verify_revoked_and_strip_auth(ctx)?;
|
||||
|
||||
let market_idx = ctx.accounts.len() - 3;
|
||||
let auth_idx = ctx.accounts.len() - 1;
|
||||
|
||||
// Sign with the consume_events authority.
|
||||
let market = &ctx.accounts[market_idx];
|
||||
ctx.seeds.push(consume_events_authority! {
|
||||
program = ctx.program_id,
|
||||
dex_program = ctx.dex_program_id,
|
||||
market = market.key
|
||||
});
|
||||
|
||||
ctx.accounts[auth_idx] = Self::prepare_pda(&ctx.accounts[auth_idx]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Accounts:
|
||||
///
|
||||
/// 0. Authorization token.
|
||||
|
@ -227,6 +249,21 @@ macro_rules! prune_authority {
|
|||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! consume_events_authority {
|
||||
(
|
||||
program = $program:expr,
|
||||
dex_program = $dex_program:expr,
|
||||
market = $market:expr
|
||||
) => {
|
||||
prune_authority!(
|
||||
program = $program,
|
||||
dex_program = $dex_program,
|
||||
market = $market
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// Error.
|
||||
|
||||
#[error]
|
||||
|
|
|
@ -343,7 +343,7 @@ async function crankEventQueue(provider, marketProxy) {
|
|||
while (eq.length > 0) {
|
||||
const tx = new Transaction();
|
||||
tx.add(
|
||||
marketProxy.market.makeConsumeEventsInstruction([eq[0].openOrders], 1)
|
||||
marketProxy.instruction.consumeEventsPermissioned([eq[0].openOrders], 1)
|
||||
);
|
||||
await provider.send(tx);
|
||||
eq = await marketProxy.market.loadEventQueue(provider.connection);
|
||||
|
|
|
@ -136,6 +136,11 @@ async function list({
|
|||
DEX_PID,
|
||||
proxyProgramId
|
||||
),
|
||||
crankAuthority: await Identity.consumeEventsAuthority(
|
||||
market.publicKey,
|
||||
DEX_PID,
|
||||
proxyProgramId
|
||||
),
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ const {
|
|||
OpenOrdersPda,
|
||||
Logger,
|
||||
ReferralFees,
|
||||
PermissionedCrank,
|
||||
MarketProxyBuilder,
|
||||
} = require("@project-serum/serum");
|
||||
|
||||
|
@ -71,6 +72,14 @@ class Identity {
|
|||
...ix.keys,
|
||||
];
|
||||
}
|
||||
consumeEventsPermissioned(ix) {
|
||||
ix.keys = [
|
||||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isWritable: false, isSigner: false },
|
||||
...ix.keys,
|
||||
];
|
||||
// PDA: so ensure the signer is false.
|
||||
ix.keys[ix.keys.length-1].isSigner = false;
|
||||
}
|
||||
static async pruneAuthority(market, dexProgramId, proxyProgramId) {
|
||||
const [addr] = await PublicKey.findProgramAddress(
|
||||
[
|
||||
|
@ -82,6 +91,10 @@ class Identity {
|
|||
);
|
||||
return addr;
|
||||
}
|
||||
|
||||
static async consumeEventsAuthority(market, dexProgramId, proxyProgramId) {
|
||||
return Identity.pruneAuthority(market, dexProgramId, proxyProgramId);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in New Issue