Skip to content

Commit

Permalink
add test-oracle fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomir-streamflow committed Oct 25, 2024
1 parent ca391dd commit d0115f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlignedAirdropsProgramType>;
Expand Down Expand Up @@ -53,10 +53,13 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien
data: ICreateAlignedDistributorData,
accounts: NewDistributorAccounts,
): Promise<TransactionInstruction> {
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({
Expand All @@ -69,7 +72,7 @@ export default class SolanaAlignedDistributorClient extends BaseDistributorClien
clawbackReceiver,
mint,
tokenProgram,
priceOracle: new PublicKey(data.oracleAddress),
priceOracle: oracle,
})
.instruction();

Expand Down
1 change: 1 addition & 0 deletions packages/distributor/solana/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion packages/distributor/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit d0115f2

Please sign in to comment.