Skip to content

Commit 91c6203

Browse files
authored
admin: More logging and test set_fee_account (#107)
* Add more loggin to admin instructions: * Test AdminSetFeeAccount * Clean up * Admin: Admin fee B account set to -> Admin: Fee account B set to * Clean up
1 parent 1efe2e2 commit 91c6203

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

stable-swap-program/program/src/processor/admin.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ fn ramp_a(token_swap: &mut SwapInfo, target_amp: u64, stop_ramp_ts: i64) -> Prog
125125
return Err(SwapError::InvalidInput.into());
126126
}
127127

128+
msg!("Admin: Current A {}", current_amp);
128129
token_swap.initial_amp_factor = current_amp;
129130
token_swap.target_amp_factor = target_amp;
130131
token_swap.start_ramp_ts = clock.unix_timestamp;
@@ -183,16 +184,22 @@ fn set_fee_account<'a, 'b: 'a, I: Iterator<Item = &'a AccountInfo<'b>>>(
183184

184185
let new_admin_fee_account =
185186
utils::unpack_token_account(&new_fee_account_info.data.borrow_mut())?;
187+
msg!(
188+
"Admin: New fee account owner {}",
189+
new_admin_fee_account.owner
190+
);
186191
if new_admin_fee_account.mint == token_swap.token_a.mint {
192+
msg!("Admin: Old fee account A {}", token_swap.token_a.admin_fees);
187193
token_swap.token_a.admin_fees = *new_fee_account_info.key;
188194
msg!(
189-
"Admin: Setting admin fee A account to {}",
195+
"Admin: Fee account A set to {}",
190196
token_swap.token_a.admin_fees
191197
);
192198
} else if new_admin_fee_account.mint == token_swap.token_b.mint {
199+
msg!("Admin: Old fee account B {}", token_swap.token_b.admin_fees);
193200
token_swap.token_b.admin_fees = *new_fee_account_info.key;
194201
msg!(
195-
"Admin: Setting admin fee B account to {}",
202+
"Admin: Fee account B set to {}",
196203
token_swap.token_b.admin_fees
197204
);
198205
} else {
@@ -212,6 +219,7 @@ fn apply_new_admin(token_swap: &mut SwapInfo) -> ProgramResult {
212219
return Err(SwapError::AdminDeadlineExceeded.into());
213220
}
214221

222+
msg!("Admin: old admin {}", token_swap.admin_key);
215223
token_swap.admin_key = token_swap.future_admin_key;
216224
token_swap.future_admin_key = Pubkey::default();
217225
token_swap.future_admin_deadline = ZERO_TS;
@@ -246,8 +254,9 @@ fn commit_new_admin<'a, 'b: 'a, I: Iterator<Item = &'a AccountInfo<'b>>>(
246254

247255
/// Set new fees
248256
fn set_new_fees(token_swap: &mut SwapInfo, new_fees: &Fees) -> ProgramResult {
257+
msg!("Admin: Old fees {:?}", token_swap.fees);
249258
token_swap.fees = *new_fees;
250-
msg!("Admin: New fees set");
259+
msg!("Admin: New fees {:?}", token_swap.fees);
251260
Ok(())
252261
}
253262

stable-swap-program/sdk/test/admin.int.test.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { SignerWallet } from "@saberhq/solana-contrib";
1+
import type { Provider } from "@saberhq/solana-contrib";
2+
import { SignerWallet, TransactionEnvelope } from "@saberhq/solana-contrib";
23
import {
34
createAdminApplyNewAdminInstruction,
45
createAdminCommitNewAdminInstruction,
6+
createAdminSetFeeAccountInstruction,
57
deployNewSwap,
68
StableSwap,
79
SWAP_PROGRAM_ID,
810
ZERO_TS,
911
} from "@saberhq/stableswap-sdk";
10-
import { u64 } from "@saberhq/token-utils";
11-
import type { Signer } from "@solana/web3.js";
12+
import { getOrCreateATA, u64 } from "@saberhq/token-utils";
13+
import type { Signer, TransactionInstruction } from "@solana/web3.js";
1214
import {
1315
Connection,
1416
Keypair,
@@ -77,6 +79,44 @@ describe("admin test", () => {
7779
stableSwap = newSwap;
7880
}, BOOTSTRAP_TIMEOUT);
7981

82+
it("Set fee account", async () => {
83+
const fetchedStableSwap = await StableSwap.load(
84+
connection,
85+
stableSwapAccount.publicKey,
86+
stableSwapProgramId
87+
);
88+
89+
const provider = new SignerWallet(owner).createProvider(connection);
90+
const tokenOwner = Keypair.generate();
91+
const { address: expectedFeeAccount, instruction } = await getOrCreateATA({
92+
provider,
93+
mint: fetchedStableSwap.state.tokenA.mint,
94+
owner: tokenOwner.publicKey,
95+
});
96+
97+
const instructions: TransactionInstruction[] = [];
98+
if (instruction) {
99+
instructions.push(instruction);
100+
}
101+
instructions.push(
102+
createAdminSetFeeAccountInstruction({
103+
config: fetchedStableSwap.config,
104+
state: fetchedStableSwap.state,
105+
tokenAccount: expectedFeeAccount,
106+
})
107+
);
108+
const txEnv = new TransactionEnvelope(provider, instructions);
109+
const pendingTx = await txEnv.send();
110+
await pendingTx.wait();
111+
112+
const newSwap = await StableSwap.load(
113+
connection,
114+
stableSwap.config.swapAccount,
115+
stableSwap.config.swapProgramID
116+
);
117+
expect(newSwap.state.tokenA.adminFeeAccount).toEqual(expectedFeeAccount);
118+
});
119+
80120
it("Commit new admin", async () => {
81121
const fetchedStableSwap = await StableSwap.load(
82122
connection,

0 commit comments

Comments
 (0)