Skip to content

Commit

Permalink
utilize maxAccounts (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler authored Oct 20, 2023
1 parent 02b714d commit 82ccf1c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
24 changes: 12 additions & 12 deletions packages/tokens-to-rent-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import cors from '@fastify/cors';
import { PublicKey } from '@solana/web3.js';
import Fastify, { FastifyInstance } from 'fastify';
import * as jup from './jupiter';
import { HNT_MINT, IOT_MINT, MOBILE_MINT } from '@helium/spl-utils';
import cors from "@fastify/cors";
import { PublicKey } from "@solana/web3.js";
import Fastify, { FastifyInstance } from "fastify";
import * as jup from "./jupiter";
import { HNT_MINT, IOT_MINT, MOBILE_MINT } from "@helium/spl-utils";

const server: FastifyInstance = Fastify({ logger: true });
server.register(cors, { origin: '*' });
server.register(cors, { origin: "*" });

server.get('/health', async (req, res) => {
server.get("/health", async (req, res) => {
res.send({ ok: true });
});

server.post<{
Body: { wallet: string; mint: string };
}>('/fees', async (req, res) => {
}>("/fees", async (req, res) => {
try {
const { wallet, mint } = req.body;
const walletPk = new PublicKey(wallet);
Expand All @@ -32,7 +32,7 @@ server.post<{

server.post<{
Body: { mint: string };
}>('/estimate', async (req, res) => {
}>("/estimate", async (req, res) => {
try {
const { mint } = req.body;
const mintPk = new PublicKey(mint);
Expand All @@ -46,7 +46,7 @@ server.post<{
}
});

server.get<{}>('/estimates', async (req, res) => {
server.get<{}>("/estimates", async (req, res) => {
try {
res.send({
[HNT_MINT.toBase58()]: await jup.estimate({ mint: HNT_MINT }),
Expand All @@ -63,11 +63,11 @@ const start = async () => {
try {
await server.listen({
port: Number(process.env.PORT) || 8081,
host: '0.0.0.0',
host: "0.0.0.0",
});

const address = server.server.address();
const port = typeof address === 'string' ? address : address?.port;
const port = typeof address === "string" ? address : address?.port;
console.log(`Running on 0.0.0.0:${port}`);
} catch (err) {
server.log.error(err);
Expand Down
17 changes: 9 additions & 8 deletions packages/tokens-to-rent-service/src/jupiter.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { HNT_MINT, IOT_MINT, MOBILE_MINT, toBN } from '@helium/spl-utils';
import { HNT_MINT, IOT_MINT, MOBILE_MINT, toBN } from "@helium/spl-utils";
import {
Configuration,
DefaultApi,
Instruction,
AccountMeta,
} from '@jup-ag/api';
import { ACCOUNT_SIZE, NATIVE_MINT, getMint } from '@solana/spl-token';
} from "@jup-ag/api";
import { ACCOUNT_SIZE, NATIVE_MINT, getMint } from "@solana/spl-token";
import {
AddressLookupTableAccount,
PublicKey,
SystemProgram,
TransactionInstruction,
TransactionMessage,
VersionedTransaction,
} from '@solana/web3.js';
import { JUPITER_FEE_ACCOUNT, JUPITER_FEE_BPS, JUPITER_URL } from './env';
import { provider } from './solana';
} from "@solana/web3.js";
import { JUPITER_FEE_ACCOUNT, JUPITER_FEE_BPS, JUPITER_URL } from "./env";
import { provider } from "./solana";

export const instructionDataToTransactionInstruction = (
instruction: Instruction | undefined
Expand All @@ -28,7 +28,7 @@ export const instructionDataToTransactionInstruction = (
isSigner: key.isSigner,
isWritable: key.isWritable,
})),
data: Buffer.from(instruction.data, 'base64'),
data: Buffer.from(instruction.data, "base64"),
});
};

Expand Down Expand Up @@ -94,7 +94,7 @@ export const estimate = async ({
platformFeeBps: Number(JUPITER_FEE_BPS) || 0,
});

if (!quote) throw new Error('Unable to quote');
if (!quote) throw new Error("Unable to quote");
return quote.outAmount;
};

Expand Down Expand Up @@ -127,6 +127,7 @@ export const fundFees = async ({
outputMint: NATIVE_MINT.toBase58(),
slippageBps: 100, // 1%
platformFeeBps: Number(JUPITER_FEE_BPS) || 0,
maxAccounts: 20,
});

// Tx contains instructions to create/close WSOL token account
Expand Down

0 comments on commit 82ccf1c

Please sign in to comment.