Skip to content

Commit

Permalink
Add clearing cache before finding vacant base asset index
Browse files Browse the repository at this point in the history
  • Loading branch information
EquilateralDelta committed Apr 10, 2024
1 parent 9f2c0d1 commit 0a9599e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/js/src/plugins/protocolModule/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { COption } from '@convergence-rfq/beet';
import { CustomOptionalF64, CustomOptionalPubkey } from '@convergence-rfq/rfq';
import { PublicKey } from '@solana/web3.js';
import { Convergence } from '@/index';
import { baseAssetsCache } from './cache';
import { Convergence } from '@/Convergence';

export const toCustomOptionalF64 = (
input: COption<number>
Expand Down Expand Up @@ -32,13 +33,15 @@ export const toCustomOptionalPubkey = (
};

export const findVacantBaseAssetIndex = async (cvg: Convergence) => {
await baseAssetsCache.clear(); // clear the cache to use up-to-date base assets

const getRandomNumber = (min: number, max: number) => {
const minCeiled = Math.ceil(min);
const maxFloored = Math.floor(max);
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
};

let elementsToSkip = getRandomNumber(0, 100);

const existingBaseAssets = await cvg.protocol().getBaseAssets();
const existing = existingBaseAssets
.map((el) => el.index)
Expand Down

0 comments on commit 0a9599e

Please sign in to comment.