@lavarage/sdk 6.0.3 → 6.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -1
- package/dist/index.mjs.map +1 -1
- package/index.ts +66 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Lavarage } from './idl/lavarage'
|
|
|
3
3
|
import { Lavarage as LavarageV2 } from './idl/lavaragev2'
|
|
4
4
|
import bs58 from 'bs58'
|
|
5
5
|
import { AddressLookupTableAccount, ComputeBudgetProgram, Keypair, PublicKey, SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from '@solana/web3.js'
|
|
6
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, createTransferInstruction, getAccount, getAssociatedTokenAddressSync, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } from '@solana/spl-token'
|
|
6
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, createTransferInstruction, getAccount, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } from '@solana/spl-token'
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
export function getPda(seed: Buffer | Buffer[], programId: PublicKey) {
|
|
@@ -488,6 +488,71 @@ export const removeTpDelegate = async (lavarageProgram: Program<Lavarage> | Prog
|
|
|
488
488
|
return new VersionedTransaction(messageV0)
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
+
export const partialRepayV1 = async (lavarageProgram: Program<Lavarage>, position: ProgramAccount<{
|
|
492
|
+
pool: PublicKey,
|
|
493
|
+
seed: PublicKey,
|
|
494
|
+
userPaid: BN,
|
|
495
|
+
amount: BN,
|
|
496
|
+
}>, repaymentBps: number) => {
|
|
497
|
+
const { blockhash } = await lavarageProgram.provider.connection.getLatestBlockhash('finalized')
|
|
498
|
+
const pool = await lavarageProgram.account.pool.fetch(position.account.pool)
|
|
499
|
+
const positionAccountPDA = position.publicKey
|
|
500
|
+
const ix = await lavarageProgram.methods.tradingClosePartialRepaySol(new BN(repaymentBps)).accountsStrict({
|
|
501
|
+
systemProgram: SystemProgram.programId,
|
|
502
|
+
positionAccount: positionAccountPDA,
|
|
503
|
+
tradingPool: position.account.pool,
|
|
504
|
+
nodeWallet: pool.nodeWallet,
|
|
505
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
506
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
507
|
+
randomAccountAsId: position.account.seed,
|
|
508
|
+
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
509
|
+
}).instruction()
|
|
510
|
+
const messageV0 = new TransactionMessage({
|
|
511
|
+
payerKey: lavarageProgram.provider.publicKey!,
|
|
512
|
+
recentBlockhash: blockhash,
|
|
513
|
+
instructions: [ix],
|
|
514
|
+
}).compileToV0Message()
|
|
515
|
+
return new VersionedTransaction(messageV0)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export const partialRepayV2 = async (lavarageProgram: Program<LavarageV2>, position: ProgramAccount<{
|
|
519
|
+
pool: PublicKey,
|
|
520
|
+
seed: PublicKey,
|
|
521
|
+
userPaid: BN,
|
|
522
|
+
amount: BN,
|
|
523
|
+
}>, repaymentBps: number) => {
|
|
524
|
+
const { blockhash } = await lavarageProgram.provider.connection.getLatestBlockhash('finalized')
|
|
525
|
+
const pool = await lavarageProgram.account.pool.fetch(position.account.pool)
|
|
526
|
+
const positionAccountPDA = position.publicKey
|
|
527
|
+
const ix = await lavarageProgram.methods.tradingPartialRepaySol(new BN(repaymentBps)).accountsStrict({
|
|
528
|
+
systemProgram: SystemProgram.programId,
|
|
529
|
+
positionAccount: positionAccountPDA,
|
|
530
|
+
tradingPool: position.account.pool,
|
|
531
|
+
nodeWallet: pool.nodeWallet,
|
|
532
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
533
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
534
|
+
randomAccountAsId: position.account.seed,
|
|
535
|
+
fromTokenAccount: getAssociatedTokenAddressSync(pool.qtType, lavarageProgram.provider.publicKey!),
|
|
536
|
+
toTokenAccount: getAssociatedTokenAddressSync(pool.qtType, pool.nodeWallet, true),
|
|
537
|
+
mint: pool.qtType,
|
|
538
|
+
feeTokenAccount: getAssociatedTokenAddressSync(pool.qtType, new PublicKey('6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF')),
|
|
539
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
540
|
+
}).instruction()
|
|
541
|
+
|
|
542
|
+
const messageV0 = new TransactionMessage({
|
|
543
|
+
payerKey: lavarageProgram.provider.publicKey!,
|
|
544
|
+
recentBlockhash: blockhash,
|
|
545
|
+
instructions: [ix],
|
|
546
|
+
}).compileToV0Message()
|
|
547
|
+
|
|
548
|
+
return new VersionedTransaction(messageV0)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/*
|
|
552
|
+
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
|
|
491
556
|
export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position: ProgramAccount<{
|
|
492
557
|
pool: PublicKey,
|
|
493
558
|
seed: PublicKey,
|