diff --git a/packages/distributor/solana/clients/SolanaAlignedDistributorClient.ts b/packages/distributor/solana/clients/SolanaAlignedDistributorClient.ts index 93af95d..651ed44 100644 --- a/packages/distributor/solana/clients/SolanaAlignedDistributorClient.ts +++ b/packages/distributor/solana/clients/SolanaAlignedDistributorClient.ts @@ -15,7 +15,7 @@ import BaseDistributorClient, { IInitOptions } from "./BaseDistributorClient.js" import { AlignedDistributor as AlignedAirdropsProgramType } from "../descriptor/aligned_distributor.js"; import StreamflowAlignedAirdropsIDL from "../descriptor/idl/aligned_distributor.json"; import { ALIGNED_PRECISION_FACTOR_POW } from "../constants.js"; -import { getAlignedDistributorPda } from "../utils.js"; +import { getAlignedDistributorPda, getTestOraclePda } from "../utils.js"; export default class SolanaAlignedDistributorClient extends BaseDistributorClient { private alignedProxyProgram: Program; @@ -53,10 +53,13 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien data: ICreateAlignedDistributorData, accounts: NewDistributorAccounts, ): Promise { - const { distributor, mint, clawbackReceiver, tokenProgram, tokenVault } = accounts; + const { distributor, mint, clawbackReceiver, tokenProgram, tokenVault, admin } = accounts; const baseArgs = this.getNewDistributorArgs(data); const alignedArgs = this.getNewAlignedDistributorArgs(data); + const oracle = data.oracleAddress + ? new PublicKey(data.oracleAddress) + : getTestOraclePda(this.alignedProxyProgram.programId, mint, admin); const newDistributorIx = await this.alignedProxyProgram.methods .newDistributor({ @@ -69,7 +72,7 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien clawbackReceiver, mint, tokenProgram, - priceOracle: new PublicKey(data.oracleAddress), + priceOracle: oracle, }) .instruction(); diff --git a/packages/distributor/solana/constants.ts b/packages/distributor/solana/constants.ts index f1b7c5f..4192d4c 100644 --- a/packages/distributor/solana/constants.ts +++ b/packages/distributor/solana/constants.ts @@ -5,6 +5,7 @@ export const DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41; export const DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201; export const ALIGNED_DISTRIBUTOR_PREFIX = Buffer.from("aligned-distributor", "utf-8"); +export const TEST_ORACLE_PREFIX = Buffer.from("test-oracle", "utf-8"); export const ALIGNED_PRECISION_FACTOR_POW = 9; export const ONE_IN_BASIS_POINTS = BigInt(10_000); diff --git a/packages/distributor/solana/utils.ts b/packages/distributor/solana/utils.ts index aea8298..942b733 100644 --- a/packages/distributor/solana/utils.ts +++ b/packages/distributor/solana/utils.ts @@ -6,12 +6,16 @@ import { ContractError, divCeilN } from "@streamflow/common"; import { ConfirmationParams, signAndExecuteTransaction, ThrottleParams } from "@streamflow/common/solana"; import { fromTxError } from "./generated/errors/index.js"; -import { ONE_IN_BASIS_POINTS, ALIGNED_DISTRIBUTOR_PREFIX } from "./constants.js"; +import { ONE_IN_BASIS_POINTS, ALIGNED_DISTRIBUTOR_PREFIX, TEST_ORACLE_PREFIX } from "./constants.js"; export const getAlignedDistributorPda = (programId: PublicKey, distributor: PublicKey): PublicKey => { return PublicKey.findProgramAddressSync([ALIGNED_DISTRIBUTOR_PREFIX, distributor.toBuffer()], programId)[0]; }; +export const getTestOraclePda = (programId: PublicKey, mint: PublicKey, creator: PublicKey): PublicKey => { + return PublicKey.findProgramAddressSync([TEST_ORACLE_PREFIX, mint.toBuffer(), creator.toBuffer()], programId)[0]; +}; + export function getDistributorPda(programId: PublicKey, mint: PublicKey, version: number): PublicKey { // Constructing the seed for the PDA const seeds = [