diff --git a/lib/client/client.ts b/lib/client/client.ts index e5b145b..d81e198 100644 --- a/lib/client/client.ts +++ b/lib/client/client.ts @@ -31,7 +31,7 @@ import { TwapObservation } from "@/types/prices"; import { TransactionProcessingUpdate } from "@/types/transactions"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { CreateProposalInstruction, ProposalOnChainFields, diff --git a/lib/client/indexer/dao.ts b/lib/client/indexer/dao.ts index d4573a6..d6f71a5 100644 --- a/lib/client/indexer/dao.ts +++ b/lib/client/indexer/dao.ts @@ -12,6 +12,7 @@ import { dao_details_bool_exp } from "./__generated__"; import { PublicKey } from "@solana/web3.js"; +import BN from "bn.js"; export class FutarchyIndexerDaoClient implements FutarchyDaoClient { private protocolMap: Map; @@ -234,12 +235,17 @@ export class FutarchyIndexerDaoClient implements FutarchyDaoClient { : undefined, proposalCount: d.proposals_aggregate.aggregate?.count, passThresholdBps: d.pass_threshold_bps, - slotsPerProposal: d.slots_per_proposal, - twapInitialObservation: d.twap_initial_observation, - twapMaxObservationChangePerUpdate: - d.twap_max_observation_change_per_update, - minBaseFutarchicLiquidity: d.min_base_futarchic_liquidity, - minQuoteFutarchicLiquidity: d.min_quote_futarchic_liquidity + slotsPerProposal: new BN(d.slots_per_proposal ?? 0), + twapInitialObservation: new BN(d.twap_initial_observation ?? 0), + twapMaxObservationChangePerUpdate: new BN( + d.twap_max_observation_change_per_update ?? 0 + ), + minBaseFutarchicLiquidity: new BN( + d.min_base_futarchic_liquidity ?? 0 + ), + minQuoteFutarchicLiquidity: new BN( + d.min_quote_futarchic_liquidity ?? 0 + ) }, publicKey: new PublicKey(d.dao_acct), protocol: this.protocolMap.get(d.program_acct) diff --git a/lib/client/indexer/markets.ts b/lib/client/indexer/markets.ts index 0bf2b78..608e3a8 100644 --- a/lib/client/indexer/markets.ts +++ b/lib/client/indexer/markets.ts @@ -32,7 +32,7 @@ import { import { Client as GQLWebSocketClient } from "graphql-ws"; import { FutarchyMarketsRPCClient } from "../rpc/markets"; import { PriceMath } from "@metadaoproject/futarchy"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { public openbook: FutarchyIndexerOpenbookMarketsClient; @@ -135,10 +135,7 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { return market; } - watchCurrentTwapPrice( - marketKey: PublicKey, - includeOracleData?: boolean - ): Observable { + watchCurrentTwapPrice(marketKey: PublicKey): Observable { const queryForGenerate = { twap_chart_data: { __args: { @@ -166,26 +163,6 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { twaps: undefined as any }; - if (includeOracleData) { - queryForGenerate.twaps = { - __args: { - where: { - market_acct: { _eq: marketKey.toString() } - }, - order_by: [ - { - created_at: "desc" as order_by - } - ], - limit: 1 - }, - last_observation: true, - last_price: true, - observation_agg: true, - updated_slot: true - }; - } - const { query, variables } = generateSubscriptionOp(queryForGenerate); return new Observable((subscriber) => { @@ -204,20 +181,12 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { }; }; }[]; - twaps: { - last_observation: number; - last_price: number; - observation_agg: number; - updated_slot: number; - }[]; }>( { query, variables }, { next: ({ data }) => { - const twaps = data?.twaps; const twapObservations = data?.twap_chart_data?.map((d, i) => { - const latestTwaps = twaps?.[i]; return { priceUi: PriceMath.getHumanPrice( new BN(d.token_amount), @@ -226,14 +195,7 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { ), priceRaw: d.token_amount, createdAt: new Date(d.interv), - oracleData: latestTwaps - ? { - lastObservation: latestTwaps.last_observation, - lastPrice: latestTwaps.last_price, - observationAgg: latestTwaps.observation_agg, - updatedSlot: latestTwaps.updated_slot - } - : null + oracleData: null }; }); subscriber.next(twapObservations); @@ -377,7 +339,7 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { const twapObservations = data.data?.twap_chart_data_stream?.map((d) => ({ priceUi: PriceMath.getHumanPrice( - new BN(d.token_amount), + new BN(d.token_amount ?? 0), d.market?.tokenByBaseMintAcct.decimals!!, d.market?.tokenByQuoteMintAcct.decimals!! ), diff --git a/lib/client/indexer/proposals.ts b/lib/client/indexer/proposals.ts index 58b2c3f..a65c39c 100644 --- a/lib/client/indexer/proposals.ts +++ b/lib/client/indexer/proposals.ts @@ -29,7 +29,7 @@ import { ProposalDetails, ProposalInputs } from "@/types/createProp"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { PriceMath } from "@metadaoproject/futarchy"; import { Observable } from "rxjs"; import { Client as GQLWebSocketClient } from "graphql-ws"; @@ -452,7 +452,7 @@ export class FutarchyIndexerProposalsClient implements FutarchyProposalsClient { prev + PriceMath.getHumanAmount( new BN(curr.filled_base_amount), - new BN(proposal.dao.tokenByBaseAcct?.decimals ?? 6) + proposal.dao.tokenByBaseAcct?.decimals ?? 6 ) * curr.quote_price, 0 @@ -463,7 +463,7 @@ export class FutarchyIndexerProposalsClient implements FutarchyProposalsClient { prev + PriceMath.getHumanAmount( new BN(curr.filled_base_amount), - new BN(proposal.dao.tokenByBaseAcct?.decimals ?? 6) + proposal.dao.tokenByBaseAcct?.decimals ?? 6 ) * curr.quote_price, 0 diff --git a/lib/client/rpc/balances.ts b/lib/client/rpc/balances.ts index a25a312..43d077c 100644 --- a/lib/client/rpc/balances.ts +++ b/lib/client/rpc/balances.ts @@ -3,9 +3,7 @@ import { getAssociatedTokenAddressSync } from "@solana/spl-token"; import { - Dao, DaoAggregate, - FutarchyProtocol, TokenProps, TokenWithBalance, TokenWithBalancePDAAndProposal, @@ -14,8 +12,9 @@ import { import { FutarchyBalancesClient } from "@/client"; import { PublicKey } from "@solana/web3.js"; import { Proposal } from "@/types/proposals"; -import { BN, Provider } from "@coral-xyz/anchor"; +import { Provider } from "@coral-xyz/anchor"; import { Observable, retry } from "rxjs"; +import BN from "bn.js"; const PASS_USDC_URL = "https://imagedelivery.net/HYEnlujCFMCgj6yA728xIw/f38677ab-8ec6-4706-6606-7d4e0a3cfc00/public"; @@ -155,11 +154,12 @@ export class FutarchyRPCBalancesClient implements FutarchyBalancesClient { tokenWithPDA.pda, (accountInfo) => { const accountData = AccountLayout.decode(accountInfo.data); - const dividedTokenAmount = - new BN(accountData.amount) / - new BN(10).pow(new BN(tokenWithPDA.token.decimals)); + const dividedTokenAmount = new BN(Number(accountData.amount)).div( + new BN(10).pow(new BN(tokenWithPDA.token.decimals)) + ); + // this is bugged if value is decimal/between 0 and 1 const tokenVal: TokenWithBalance = { - balance: dividedTokenAmount, + balance: dividedTokenAmount.toNumber(), token: tokenWithPDA.token }; subscriber.next(tokenVal); diff --git a/lib/client/rpc/dao.ts b/lib/client/rpc/dao.ts index f89eb67..c64918c 100644 --- a/lib/client/rpc/dao.ts +++ b/lib/client/rpc/dao.ts @@ -1,4 +1,4 @@ -import { BN, Program, Provider } from "@coral-xyz/anchor"; +import { Program, Provider } from "@coral-xyz/anchor"; import { AutocratProgram, FutarchyProtocol, @@ -13,6 +13,7 @@ import { PublicKey } from "@solana/web3.js"; import { createSlug } from "@/utils"; import { Autocrat, IDL as AUTOCRAT_V0_3_IDL } from "@/idl/autocrat_v0.3"; import { AUTOCRAT_PROGRAM_ID } from "@metadaoproject/futarchy"; +import BN from "bn.js"; export class FutarchyRPCDaoClient implements FutarchyDaoClient { private futarchyProtocols: FutarchyProtocol[]; @@ -118,7 +119,7 @@ export class FutarchyRPCDaoClient implements FutarchyDaoClient { const slotsPerProposal: BN = protocol.deploymentVersion === "V0" ? new BN(2160000) - : daoAccount.slotsPerProposal; + : daoAccount.slotsPerProposal ?? new BN(2160000); const quoteMint = daoAccount.usdcMint; if (baseMint) { const baseToken = await enrichTokenMetadata(baseMint, this.rpcProvider); diff --git a/lib/client/rpc/market-clients/ammMarkets.ts b/lib/client/rpc/market-clients/ammMarkets.ts index 1772f4e..20b5271 100644 --- a/lib/client/rpc/market-clients/ammMarkets.ts +++ b/lib/client/rpc/market-clients/ammMarkets.ts @@ -11,7 +11,8 @@ import { SwapPreview } from "@/types/amm"; import { TransactionProcessingUpdate } from "@/types/transactions"; -import { BN, Program, Provider } from "@coral-xyz/anchor"; +import anchor from "@coral-xyz/anchor"; +import BN from "bn.js"; import { AMM_PROGRAM_ID, AmmAccount, @@ -27,14 +28,14 @@ import { AccountInfo, PublicKey } from "@solana/web3.js"; import { Observable } from "rxjs"; export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { - private rpcProvider: Provider; - private amm: Program; + private rpcProvider: anchor.Provider; + private amm: anchor.Program; private ammClient: AmmClient; private transactionSender: TransactionSender | undefined; constructor( - rpcProvider: Provider, - amm: Program, + rpcProvider: anchor.Provider, + amm: anchor.Program, ammClient: AmmClient, transactionSender: TransactionSender | undefined ) { @@ -113,7 +114,7 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { ); const maxBaseAmountWithSlippage = calculateMaxWithSlippage( - maxBaseAmountArg, + maxBaseAmountArg.toNumber(), slippage ); const baseReserve = ammMarket.baseAmount; @@ -194,7 +195,7 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { ); const maxBaseAmountWithSlippage = calculateMaxWithSlippage( - maxBaseAmountArg, + maxBaseAmountArg.toNumber(), slippage ); @@ -421,7 +422,7 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { slippageBps: BN ): SwapPreview { const swapType = isBuyBase ? { buy: {} } : { sell: {} }; - let startPrice = amm.quoteAmount / amm.baseAmount; + let startPrice = amm.quoteAmount.toNumber() / amm.baseAmount.toNumber(); const { expectedOut, newBaseReserves, newQuoteReserves } = this.ammClient.simulateSwap( @@ -432,16 +433,16 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { slippageBps ); - const finalPrice = newQuoteReserves / newBaseReserves; + const finalPrice = newQuoteReserves.toNumber() / newBaseReserves.toNumber(); // NOTE: Default is selling into USDC - let avgSwapPrice = expectedOut / inputAmount; - let humanInput = inputAmount / 10 ** amm.baseMintDecimals; - let humanOutput = expectedOut / 10 ** amm.quoteMintDecimals; + let avgSwapPrice = expectedOut.toNumber() / inputAmount.toNumber(); + let humanInput = inputAmount.toNumber() / 10 ** amm.baseMintDecimals; + let humanOutput = expectedOut.toNumber() / 10 ** amm.quoteMintDecimals; if (swapType.buy) { - avgSwapPrice = inputAmount / expectedOut; - humanInput = inputAmount / 10 ** amm.quoteMintDecimals; - humanOutput = expectedOut / 10 ** amm.baseMintDecimals; + avgSwapPrice = inputAmount.toNumber() / expectedOut.toNumber(); + humanInput = inputAmount.toNumber() / 10 ** amm.quoteMintDecimals; + humanOutput = expectedOut.toNumber() / 10 ** amm.baseMintDecimals; } const priceImpact = Math.abs(finalPrice - startPrice) / startPrice; @@ -454,7 +455,7 @@ export class FutarchyAmmMarketsRPCClient implements FutarchyAmmMarketsClient { outputUnits: humanOutput, startPrice, finalPrice, - avgSwapPrice: inputAmount / expectedOut, + avgSwapPrice: inputAmount.toNumber() / expectedOut.toNumber(), priceImpact }; } diff --git a/lib/client/rpc/market-clients/openbookMarkets.ts b/lib/client/rpc/market-clients/openbookMarkets.ts index 479225d..1af3b32 100644 --- a/lib/client/rpc/market-clients/openbookMarkets.ts +++ b/lib/client/rpc/market-clients/openbookMarkets.ts @@ -1,4 +1,5 @@ -import { BN, Program, Provider } from "@coral-xyz/anchor"; +import anchor from "@coral-xyz/anchor"; +import BN from "bn.js"; import { Market as OBMarket, Order as OBOrder, @@ -42,14 +43,14 @@ import { SendTransactionResponse } from "@/types/transactions"; export class FutarchyOpenbookMarketsRPCClient implements FutarchyOrderbookMarketsClient { - private openbook: Program; + private openbook: anchor.Program; private openbookClient: OpenBookV2Client; - private rpcProvider: Provider; + private rpcProvider: anchor.Provider; private transactionSender: TransactionSender | undefined; constructor( - rpcProvider: Provider, - openbook: Program, + rpcProvider: anchor.Provider, + openbook: anchor.Program, openbookClient: OpenBookV2Client, transactionSender: TransactionSender | undefined ) { @@ -177,7 +178,7 @@ export class FutarchyOpenbookMarketsRPCClient size: bookSideOrder.size, filled: bookSideOrder.size - - getPartiallyFilledAmountFromBookSideOrder(bookSideOrder), + getPartiallyFilledAmountFromBookSideOrder(bookSideOrder).toNumber(), owner: bookSideOrder.leafNode.owner, clientOrderId: bookSideOrder.leafNode.clientOrderId, market: bookSideOrder.market.pubkey, @@ -236,7 +237,9 @@ export class FutarchyOpenbookMarketsRPCClient const [openOrdersIx, openOrdersAccountAddress] = await this.openbookClient.createOpenOrdersIx( market.publicKey, - `${shortKey(this.transactionSender.owner)}-${shortKey(accountIndex)}`, + `${shortKey(this.transactionSender.owner)}-${shortKey( + accountIndex.toString() + )}`, this.transactionSender.owner, // TODO do we have delegate? null, @@ -246,7 +249,7 @@ export class FutarchyOpenbookMarketsRPCClient const placeLimitOrderArgs = this.createPlaceOrderArgs({ orderType: placeOrderType, - accountIndex, + accountIndex: accountIndex.toNumber(), market: market.marketInstance, isAsk: order.side === "ask", amount: order.size, @@ -343,7 +346,7 @@ export class FutarchyOpenbookMarketsRPCClient const _priceLots = market.priceUiToLots(priceCalc); const maxBaseLots = market.baseUiToLots(amount); let maxQuoteLotsIncludingFees = market.quoteUiToLots( - priceLots.mul(maxBaseLots) + priceLots.mul(maxBaseLots).toNumber() ); if (_priceLots === priceLots) { diff --git a/lib/client/rpc/markets.ts b/lib/client/rpc/markets.ts index 1d492ca..8336951 100644 --- a/lib/client/rpc/markets.ts +++ b/lib/client/rpc/markets.ts @@ -23,6 +23,7 @@ import { import { PublicKey } from "@solana/web3.js"; import { Observable } from "rxjs"; import { prices_chart_data_bool_exp } from "../indexer/__generated__"; +import { BN_0 } from "@/constants"; export class FutarchyMarketsRPCClient implements FutarchyMarketsClient { // we have generic interface for orderbooks. when adding phoenix, this could be rethunk @@ -109,11 +110,11 @@ export class FutarchyMarketsRPCClient implements FutarchyMarketsClient { subscriber.next([ { priceUi: PriceMath.getHumanPrice( - twapPrice, + twapPrice ?? BN_0, market?.baseToken.decimals!!, market?.quoteToken.decimals!! ), - priceRaw: twapPrice.toNumber(), + priceRaw: twapPrice?.toNumber(), createdAt: new Date() } ]); @@ -130,8 +131,8 @@ export class FutarchyMarketsRPCClient implements FutarchyMarketsClient { .fetchMarket(new AmmMarketFetchRequest(marketKey)) .then((market) => { const ammPrice = PriceMath.getAmmPriceFromReserves( - market?.baseAmount, - market?.quoteAmount + market?.baseAmount ?? BN_0, + market?.quoteAmount ?? BN_0 ); subscriber.next([ { diff --git a/lib/client/rpc/proposals/createProposal.ts b/lib/client/rpc/proposals/createProposal.ts index f96c54d..b83dcbe 100644 --- a/lib/client/rpc/proposals/createProposal.ts +++ b/lib/client/rpc/proposals/createProposal.ts @@ -26,7 +26,7 @@ import { OpenbookMarketParams } from "@/types/createProp"; import { TransactionProcessingUpdate } from "@/types/transactions"; -import { AnchorProvider, Program, BN, utils } from "@coral-xyz/anchor"; +import { AnchorProvider, Program, utils } from "@coral-xyz/anchor"; import { AutocratClient, InstructionUtils, @@ -55,6 +55,7 @@ import { ConditionalVault as Conditional_vault_v0_2 } from "@/idl/conditional_va import { Observable } from "rxjs"; import { buildMemoInstruction } from "@/instructions/builder/memo"; import { buildTransferInstruction } from "@/instructions/builder/transfer"; +import BN from "bn.js"; export class CreateProposalClient implements CreateProposal { private proposalsClient: FutarchyProposalsClient; @@ -529,8 +530,8 @@ export class CreateProposalClient implements CreateProposal { dao.publicKey, url, onPassIx.instruction, - marketParams.baseLiquidity, - marketParams.quoteLiquidity + new BN(marketParams.baseLiquidity), + new BN(marketParams.quoteLiquidity) ); const txResp = this.transactionSender?.send( diff --git a/lib/client/rpc/proposals/proposals.ts b/lib/client/rpc/proposals/proposals.ts index 1da0302..7e99e8c 100644 --- a/lib/client/rpc/proposals/proposals.ts +++ b/lib/client/rpc/proposals/proposals.ts @@ -3,7 +3,7 @@ import { Transaction, TransactionInstruction } from "@solana/web3.js"; -import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; +import { AnchorProvider, Program } from "@coral-xyz/anchor"; import { TOKEN_PROGRAM_ID, createAssociatedTokenAccountIdempotentInstruction, @@ -47,6 +47,7 @@ import { import { FinalizeProposalClient } from "./finalizeProposal"; import { CreateProposalClient } from "./createProposal"; import { autocratVersionToConditionalVaultMap } from "@/constants"; +import BN from "bn.js"; export class FutarchyRPCProposalsClient implements FutarchyProposalsClient { public rpcProvider: AnchorProvider; diff --git a/lib/constants/index.ts b/lib/constants/index.ts index 02f0447..9d89f29 100644 --- a/lib/constants/index.ts +++ b/lib/constants/index.ts @@ -1,15 +1,15 @@ export * from "./twap"; export * from "./conditionalVault"; export * from "./markets"; -export * from "./reactions" +export * from "./reactions"; import { PublicKey } from "@solana/web3.js"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { AutocratProgram, ProgramVersion } from "@/types"; -import AUTOCRAT_V0_IDL from "@/idl/autocrat_v0.json" assert {type: "json"}; -import AUTOCRAT_V0_1_IDL from "@/idl/autocrat_v0.1.json" assert {type: "json"}; -import AUTOCRAT_V0_2_IDL from "@/idl/autocrat_v0.2.json" assert {type: "json"}; -import AUTOCRAT_V0_3_IDL from "@/idl/autocrat_v0.3.json" assert {type: "json"}; +import AUTOCRAT_V0_IDL from "@/idl/autocrat_v0.json" assert { type: "json" }; +import AUTOCRAT_V0_1_IDL from "@/idl/autocrat_v0.1.json" assert { type: "json" }; +import AUTOCRAT_V0_2_IDL from "@/idl/autocrat_v0.2.json" assert { type: "json" }; +import AUTOCRAT_V0_3_IDL from "@/idl/autocrat_v0.3.json" assert { type: "json" }; export const SYSTEM_PROGRAM: PublicKey = new PublicKey( "11111111111111111111111111111111" diff --git a/lib/constants/markets.ts b/lib/constants/markets.ts index 2ca2955..ce1a582 100644 --- a/lib/constants/markets.ts +++ b/lib/constants/markets.ts @@ -1,19 +1,19 @@ -import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; +import BN from "bn.js"; // TODO: Review this number as max safe doesn't work export const MAX_MARKET_PRICE = 100000000; export const autocratProgramToLoSizeMap: Record< - string, - { baseLotSize: BN; quoteLotSize: BN } + string, + { baseLotSize: BN; quoteLotSize: BN } > = { - "fut5MzSUFcmxaEHMvo9qQThrAL4nAv5FQ52McqhniSt": { - baseLotSize: new BN(1e12), - quoteLotSize: new BN(100), - }, - "metaRK9dUBnrAdZN6uUDKvxBVKW5pyCbPVmLtUZwtBp": { - baseLotSize: new BN(1e8), - quoteLotSize: new BN(100) - } -} -export const makerFee = new BN(0) -export const takerFee = new BN(0) \ No newline at end of file + fut5MzSUFcmxaEHMvo9qQThrAL4nAv5FQ52McqhniSt: { + baseLotSize: new BN(1e12), + quoteLotSize: new BN(100) + }, + metaRK9dUBnrAdZN6uUDKvxBVKW5pyCbPVmLtUZwtBp: { + baseLotSize: new BN(1e8), + quoteLotSize: new BN(100) + } +}; +export const makerFee = new BN(0); +export const takerFee = new BN(0); diff --git a/lib/constants/twap.ts b/lib/constants/twap.ts index 424a5f1..255cf24 100644 --- a/lib/constants/twap.ts +++ b/lib/constants/twap.ts @@ -1,6 +1,5 @@ import { PublicKey } from "@solana/web3.js"; -import { Idl } from "@coral-xyz/anchor"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { ProgramVersionLabel } from "@/types"; import { diff --git a/lib/markets.ts b/lib/markets.ts index 2a8b9d2..bf91f22 100644 --- a/lib/markets.ts +++ b/lib/markets.ts @@ -1,4 +1,4 @@ -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { Market, MarketType, ProgramVersionLabel } from "./types"; export function getMarketTypeFromProtocolVersion( diff --git a/lib/nonce.ts b/lib/nonce.ts index 55dffe3..c810461 100644 --- a/lib/nonce.ts +++ b/lib/nonce.ts @@ -1,4 +1,3 @@ -import { BN } from "@coral-xyz/anchor"; import { Connection, Keypair, @@ -6,10 +5,11 @@ import { SystemProgram, Transaction } from "@solana/web3.js"; +import BN from "bn.js"; const NONCE_ACCOUNT_LENGTH = 5; -export async function createNonce(connection: Connection): BN { +export async function createNonce(connection: Connection): Promise { const nonceAuthKeypair = new Keypair(); const newNonceTx = new Transaction(); const rent = await connection.getMinimumBalanceForRentExemption( @@ -52,8 +52,6 @@ export async function createNonce(connection: Connection): BN { const nonceAccount = NonceAccount.fromAccountData(accountInfo.data); return new BN(Number(nonceAccount.nonce)); - - return; } catch (error) { console.error("Failed to create nonce account: ", error); throw error; diff --git a/lib/proposal.ts b/lib/proposal.ts index d36082e..800c7fa 100644 --- a/lib/proposal.ts +++ b/lib/proposal.ts @@ -53,8 +53,8 @@ export function getProposalFromAccount( passMarket: new PublicKey(passMarket ?? 5), publicKey, // TODO: Review - startSlot: account.slotEnqueued, - endSlot: account.slotEnqueued + (86400000 / 400) * 3, + startSlot: account.slotEnqueued.toNumber(), + endSlot: account.slotEnqueued.toNumber() + (86400000 / 400) * 3, // TODO: We can do better than this ;) creationDate: new Date(), // TODO: :) diff --git a/lib/types/amm.ts b/lib/types/amm.ts index 322d143..e2d9b23 100644 --- a/lib/types/amm.ts +++ b/lib/types/amm.ts @@ -1,6 +1,6 @@ import { PublicKey } from "@solana/web3.js"; import { Market, MarketFetchRequest } from "./markets"; -import { BN } from "@coral-xyz/anchor"; +import BN from "bn.js"; import { TokenProps } from "./tokens"; export class AmmMarketFetchRequest implements MarketFetchRequest { diff --git a/lib/types/markets.ts b/lib/types/markets.ts index 107187f..208993e 100644 --- a/lib/types/markets.ts +++ b/lib/types/markets.ts @@ -1,5 +1,4 @@ import { PublicKey } from "@solana/web3.js"; -import { BN } from "@coral-xyz/anchor"; import { TokenProps } from "@/types"; export type OrderBookSideType = "ask" | "bid"; @@ -79,4 +78,4 @@ export type OrderbookMarket = Market & { export type ConditionalMarkets = { pass: M; fail: M; -}; \ No newline at end of file +}; diff --git a/lib/types/openbook.ts b/lib/types/openbook.ts index 80bdc9f..d55483e 100644 --- a/lib/types/openbook.ts +++ b/lib/types/openbook.ts @@ -1,4 +1,4 @@ -import { BN, IdlAccounts, IdlTypes, Program } from "@coral-xyz/anchor"; +import { IdlAccounts, IdlTypes, Program } from "@coral-xyz/anchor"; import { Keypair, PublicKey } from "@solana/web3.js"; import { MarketAccount, @@ -6,7 +6,7 @@ import { OpenOrdersAccount, LeafNode, Market as OBMarket, - OracleConfigParams, + OracleConfigParams } from "@openbook-dex/openbook-v2"; import { AccountWithKey, @@ -16,11 +16,12 @@ import { VaultAccount, Market, MarketFetchRequest, - OrderbookMarket, + OrderbookMarket } from "@/types"; import { OpenbookTwapV0_1 } from "@/idl/openbook_twap_v0.1"; import { OpenbookTwapV0_2 } from "@/idl/openbook_twap_v0.2"; import { OpenbookTwap } from "@/idl/openbook_twap"; +import BN from "bn.js"; /** * Order diff --git a/package.json b/package.json index 1889e38..e00482d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@metadaoproject/futarchy-sdk", - "version": "4.0.0-alpha.48", + "version": "4.0.0-alpha.49", "type": "module", "main": "dist", "scripts": { @@ -30,8 +30,10 @@ "@solana/spl-token": "^0.3.11", "@solana/wallet-adapter-base": "^0.9.23", "@solana/web3.js": "^1.91.7", + "@types/bn.js": "^5.1.5", "@types/bun": "^1.1.0", "@types/numeral": "^2.0.4", + "bn.js": "^5.2.1", "bs58": "^6.0.0", "camelcase": "^8.0.0", "dayjs": "^1.11.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a4a0b4..38b2f8e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,12 +50,18 @@ dependencies: '@solana/web3.js': specifier: ^1.91.7 version: 1.91.7 + '@types/bn.js': + specifier: ^5.1.5 + version: 5.1.5 '@types/bun': specifier: ^1.1.0 version: 1.1.0 '@types/numeral': specifier: ^2.0.4 version: 2.0.4 + bn.js: + specifier: ^5.2.1 + version: 5.2.1 bs58: specifier: ^6.0.0 version: 6.0.0 @@ -1982,6 +1988,12 @@ packages: engines: {node: '>=8'} dev: false + /@types/bn.js@5.1.5: + resolution: {integrity: sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A==} + dependencies: + '@types/node': 20.12.7 + dev: false + /@types/bun@1.1.0: resolution: {integrity: sha512-QGK0yU4jh0OK1A7DyhPkQuKjHQCC5jSJa3dpWIEhHv/rPfb6zLfdArc4/uUUZBMTcjilsafRXnPWO+1owb572Q==} dependencies: diff --git a/tests/client/rpc/createProposal.test.ts b/tests/client/rpc/createProposal.test.ts index d99ec62..593a383 100644 --- a/tests/client/rpc/createProposal.test.ts +++ b/tests/client/rpc/createProposal.test.ts @@ -1,5 +1,5 @@ import { JitoBundler, TransactionSender } from "@/transactions"; -import { AnchorProvider, BN, utils } from "@coral-xyz/anchor"; +import { AnchorProvider, utils } from "@coral-xyz/anchor"; import { Connection, PublicKey, @@ -18,6 +18,7 @@ import { } from "@metadaoproject/futarchy"; import { createMockWallet } from "tests/test-utils"; import { FutarchyRPCClient } from "@/client/rpc"; +import BN from "bn.js"; // export const provider = AnchorProvider.env(); // setProvider(provider); diff --git a/tests/client/rpc/markets.test.ts b/tests/client/rpc/markets.test.ts index 2c7e11f..56be835 100644 --- a/tests/client/rpc/markets.test.ts +++ b/tests/client/rpc/markets.test.ts @@ -2,7 +2,7 @@ import { FutarchyRPCClient } from "@/client"; import { autocratVersionToTwapMap } from "@/constants"; import { TransactionSender } from "@/transactions"; import { AmmMarketFetchRequest, OpenbookMarketFetchRequest } from "@/types"; -import { AnchorProvider, BN, Program } from "@coral-xyz/anchor"; +import { AnchorProvider, Program } from "@coral-xyz/anchor"; import { Connection, PublicKey } from "@solana/web3.js"; import { describe, test, expect, beforeAll } from "bun:test"; import { createMockWallet } from "tests/test-utils"; @@ -18,7 +18,7 @@ describe("FutarchyRPCClient Integration Test", () => { if (wallet.publicKey === null) return; provider = new AnchorProvider(connection, wallet, { - commitment: "processed", + commitment: "processed" }); // Setup TransactionSender - assumed to be available or mock as needed