import { utils } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; import { toBeBytes } from "./utils"; import { DIP_MM_PK, DIP_MM_PRICING_SEED, DIP_STATE_SEED, DUAL_MARKET_PK, OPTION_MINT_SEED, VAULT_MINT_SEED, VAULT_QUOTE_SEED, VAULT_SEED, } from "./constants"; /** * Get the public key for MM Pricing account for a DIP. * * @param strike Strike for the DIP in atoms of quote per token of base. * @param expiration Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function pricing( strike: number, expiration: number, baseMint: PublicKey, quoteMint: PublicKey ) { const [dipMmPricing, _dipMmPricingBump] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(DIP_MM_PRICING_SEED)), toBeBytes(strike), toBeBytes(expiration), baseMint.toBuffer(), quoteMint.toBuffer(), ], DIP_MM_PK ); return dipMmPricing; } /** * Get the public key for option token mint for a DIP. * * @param strikeAtomsPerBaseToken Strike for the DIP in atoms of quote per token of base. * @param expirationSec Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function optionMint( strikeAtomsPerBaseToken: number, expirationSec: number, baseMint: PublicKey, quoteMint: PublicKey ) { // Mint that is also considered the long DIP token. const [optionMint] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(OPTION_MINT_SEED)), toBeBytes(strikeAtomsPerBaseToken), toBeBytes(expirationSec), baseMint.toBuffer(), quoteMint.toBuffer(), ], DUAL_MARKET_PK ); return optionMint; } /** * Get the public key for the DIPState. * * @param strike Strike for the DIP in atoms of quote per token of base. * @param expiration Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function state( strike: number, expiration: number, baseMint: PublicKey, quoteMint: PublicKey ): PublicKey { const [state, _stateBump] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(DIP_STATE_SEED)), toBeBytes(strike), toBeBytes(expiration), baseMint.toBuffer(), quoteMint.toBuffer(), ], DUAL_MARKET_PK ); return state; } /** * Get the public key for claim token. This is the receipt that allows * redemption at the end of the lockup period. This is also called the * DIP-short token or in the code, vault token. * * @param strike Strike for the DIP in atoms of quote per token of base. * @param expiration Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function claimMint( strike: number, expiration: number, baseMint: PublicKey, quoteMint: PublicKey ): PublicKey { const [vaultMint, _vaultMintBump] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(VAULT_MINT_SEED)), toBeBytes(strike), toBeBytes(expiration), baseMint.toBuffer(), quoteMint.toBuffer(), ], DUAL_MARKET_PK ); return vaultMint; } /** * Get the public key for the vault, the token account where the collateral * tokens for a DIP are stored. * * @param strike Strike for the DIP in atoms of quote per token of base. * @param expiration Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function vault( strike: number, expiration: number, baseMint: PublicKey, quoteMint: PublicKey ): PublicKey { const [baseVault, _baseVaultBump] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(VAULT_SEED)), toBeBytes(strike), toBeBytes(expiration), baseMint.toBuffer(), quoteMint.toBuffer(), ], DUAL_MARKET_PK ); return baseVault; } /** * Get the public key for the vault quote token account, where the * exercisepayment tokens for a DIP are stored. * * @param strike Strike for the DIP in atoms of quote per token of base. * @param expiration Expiration in unix seconds for the DIP. * @param baseMint Public key for the base token. * @param quoteMint Public key for the quote token. */ export function quoteVault( strike: number, expiration: number, baseMint: PublicKey, quoteMint: PublicKey ): PublicKey { const [quoteVault, _quoteVaultBump] = PublicKey.findProgramAddressSync( [ Buffer.from(utils.bytes.utf8.encode(VAULT_QUOTE_SEED)), toBeBytes(strike), toBeBytes(expiration), baseMint.toBuffer(), quoteMint.toBuffer(), ], DUAL_MARKET_PK ); return quoteVault; }