feat: create buy script for solana tokens

This commit is contained in:
Filip Dunder
2024-01-03 20:56:45 +01:00
parent eaf37c456d
commit d22b1dc261
17 changed files with 1771 additions and 0 deletions

1
utils/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './utils';

25
utils/utils.ts Normal file
View File

@ -0,0 +1,25 @@
/**
* Runs the function `fn`
* and retries automatically if it fails.
*
* Tries max `1 + retries` times
* with `retryIntervalMs` milliseconds between retries.
*
* From https://mtsknn.fi/blog/js-retry-on-fail/
*/
export const retry = async <T>(
fn: () => Promise<T> | T,
{ retries, retryIntervalMs }: { retries: number; retryIntervalMs: number },
): Promise<T> => {
try {
return await fn();
} catch (error) {
if (retries <= 0) {
throw error;
}
await sleep(retryIntervalMs);
return retry(fn, { retries: retries - 1, retryIntervalMs });
}
};
export const sleep = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));