Skip to content

Commit

Permalink
update mip1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Vanderwaal committed Jan 27, 2024
1 parent dc26c1f commit 42855d5
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 54 deletions.
1 change: 1 addition & 0 deletions programs/mmm/src/instructions/mip1/mip1_deposit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct Mip1DepositSell<'info> {
payer = owner,
associated_token::mint = asset_mint,
associated_token::authority = pool,
associated_token::token_program = token_program,
)]
pub sellside_escrow_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
#[account(
Expand Down
11 changes: 6 additions & 5 deletions programs/mmm/src/instructions/mip1/mip1_withdraw_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::collections::HashMap;
use anchor_lang::{prelude::*, solana_program::sysvar, AnchorDeserialize};
use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, TokenAccount},
token_interface::TokenInterface,
token_interface::{Mint, TokenAccount, TokenInterface},
};
use mpl_token_metadata::{
accounts::Metadata,
Expand Down Expand Up @@ -37,7 +36,7 @@ pub struct Mip1WithdrawSell<'info> {
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidMip1AssetParams,
)]
pub asset_mint: Account<'info, Mint>,
pub asset_mint: InterfaceAccount<'info, Mint>,
/// CHECK: will be checked in cpi
asset_master_edition: UncheckedAccount<'info>,
/// CHECK: will be checked in cpi
Expand All @@ -55,17 +54,19 @@ pub struct Mip1WithdrawSell<'info> {
init_if_needed,
associated_token::mint = asset_mint,
associated_token::authority = owner,
associated_token::token_program = token_program,
payer = owner
)]
pub asset_token_account: Box<Account<'info, TokenAccount>>,
pub asset_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
#[account(
mut,
associated_token::mint = asset_mint,
associated_token::authority = pool,
associated_token::token_program = token_program,
constraint = sellside_escrow_token_account.amount == 1 @ MMMErrorCode::InvalidMip1AssetParams,
constraint = args.asset_amount == 1 @ MMMErrorCode::InvalidMip1AssetParams,
)]
pub sellside_escrow_token_account: Box<Account<'info, TokenAccount>>,
pub sellside_escrow_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
/// CHECK: it's a pda, and the private key is owned by the seeds
#[account(
mut,
Expand Down
2 changes: 2 additions & 0 deletions programs/mmm/src/instructions/mip1/sol_mip1_fulfill_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct SolMip1FulfillSell<'info> {
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidMip1AssetParams,
)]
pub asset_mint: InterfaceAccount<'info, Mint>,
/// CHECK: will be checked in cpi
Expand All @@ -84,6 +85,7 @@ pub struct SolMip1FulfillSell<'info> {
mut,
associated_token::mint = asset_mint,
associated_token::authority = pool,
associated_token::token_program = token_program,
constraint = sellside_escrow_token_account.amount == 1 @ MMMErrorCode::InvalidMip1AssetParams,
constraint = args.asset_amount == 1 @ MMMErrorCode::InvalidMip1AssetParams,
)]
Expand Down
8 changes: 4 additions & 4 deletions programs/mmm/src/instructions/ocp/ocp_withdraw_sell.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anchor_lang::{prelude::*, solana_program::sysvar, AnchorDeserialize};
use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, TokenAccount},
token_interface::TokenInterface,
token_interface::{Mint, TokenAccount, TokenInterface},
};

use crate::{
Expand Down Expand Up @@ -31,7 +30,7 @@ pub struct OcpWithdrawSell<'info> {
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidOcpAssetParams,
)]
pub asset_mint: Account<'info, Mint>,
pub asset_mint: InterfaceAccount<'info, Mint>,
/// CHECK: will be checked in cpi
#[account(
seeds = [
Expand All @@ -50,10 +49,11 @@ pub struct OcpWithdrawSell<'info> {
mut,
associated_token::mint = asset_mint,
associated_token::authority = pool,
associated_token::token_program = token_program,
constraint = sellside_escrow_token_account.amount == 1 @ MMMErrorCode::InvalidOcpAssetParams,
constraint = args.asset_amount == 1 @ MMMErrorCode::InvalidOcpAssetParams,
)]
pub sellside_escrow_token_account: Box<Account<'info, TokenAccount>>,
pub sellside_escrow_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
/// CHECK: it's a pda, and the private key is owned by the seeds
#[account(
mut,
Expand Down
3 changes: 3 additions & 0 deletions programs/mmm/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ pub fn get_sol_total_price_and_next_price(
// the price needs to go down
let p = pool.spot_price;
let delta = pool.curve_delta;
msg!("spot price: {}, delta: {}, asset amount: {}", p, delta, n);
msg!("curve type: {}", pool.curve_type);
let ret = match fulfill_buy {
true => {
match pool.curve_type {
Expand Down Expand Up @@ -243,6 +245,7 @@ pub fn get_sol_total_price_and_next_price(
// for loop to prevent overflow
let mut total_price: u64 = 0;
let mut curr_price: u128 = p as u128;
msg!("current price: {}", curr_price);
for _ in 0..n {
total_price = total_price
.checked_add(curr_price as u64)
Expand Down
7 changes: 4 additions & 3 deletions sdk/src/pda.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from '@metaplex-foundation/mpl-token-metadata';
import { MPL_TOKEN_METADATA_PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from '@metaplex-foundation/mpl-token-metadata';
import { PublicKey } from '@solana/web3.js';
import { PREFIXES } from './constants';
import { toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters';

export const getMMMPoolPDA = (
programId: PublicKey,
Expand Down Expand Up @@ -41,12 +42,12 @@ export const getTokenRecordPDA = (mint: PublicKey, tokenAccount: PublicKey) => {
const [key, bump] = PublicKey.findProgramAddressSync(
[
Buffer.from('metadata'),
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
toWeb3JsPublicKey(TOKEN_METADATA_PROGRAM_ID).toBuffer(),
mint.toBuffer(),
Buffer.from('token_record'),
tokenAccount.toBuffer(),
],
TOKEN_METADATA_PROGRAM_ID,
toWeb3JsPublicKey(TOKEN_METADATA_PROGRAM_ID),
);

return { key, bump };
Expand Down
1 change: 0 additions & 1 deletion tests/mmm-any-allowlist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe('mmm-any-allowlist', () => {
const [poolData] = await Promise.all([
createPoolWithExampleDepositsUmi(
program,
connection,
[AllowlistKind.any],
{
owner: wallet.publicKey,
Expand Down
1 change: 0 additions & 1 deletion tests/mmm-creator-royalty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ describe('mmm-creator-royalty', () => {
const [poolData] = await Promise.all([
createPoolWithExampleDepositsUmi(
program,
connection,
[AllowlistKind.mint],
{
owner: wallet.publicKey,
Expand Down
5 changes: 1 addition & 4 deletions tests/mmm-fulfill-linear.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import {
assertFailedTx,
assertIsBetween,
assertTx,
createPoolWithExampleDeposits,
createPoolWithExampleDepositsUmi,
getMetadataURI,
getMetaplexInstance,
getSellStatePDARent,
getTokenAccount2022,
getTokenAccountRent,
Expand All @@ -39,9 +37,8 @@ import {
SIGNATURE_FEE_LAMPORTS,
} from './utils';
import { toWeb3JsPublicKey } from '@metaplex-foundation/umi-web3js-adapters';
import { token } from '@metaplex-foundation/js';

describe.only('mmm-fulfill-linear', () => {
describe('mmm-fulfill-linear', () => {
const TOKEN_PROGRAM_IDS = [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID];

const { connection } = anchor.AnchorProvider.env();
Expand Down
Loading

0 comments on commit 42855d5

Please sign in to comment.