improve tcs further
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
fbe0056202
commit
5f7d704911
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@blockworks-foundation/mango-v4",
|
||||
"version": "0.17.30",
|
||||
"version": "0.18.0",
|
||||
"description": "Typescript Client for mango-v4 program.",
|
||||
"repository": "https://github.com/blockworks-foundation/mango-v4",
|
||||
"author": {
|
||||
|
|
|
@ -188,6 +188,10 @@ export class MangoAccount {
|
|||
return this.serum3.filter((serum3) => serum3.isActive());
|
||||
}
|
||||
|
||||
public tokenConditionalSwapsActive(): TokenConditionalSwap[] {
|
||||
return this.tokenConditionalSwaps.filter((tcs) => tcs.hasData);
|
||||
}
|
||||
|
||||
public perpPositionExistsForMarket(perpMarket: PerpMarket): boolean {
|
||||
return this.perps.some(
|
||||
(pp) => pp.isActive() && pp.marketIndex == perpMarket.perpMarketIndex,
|
||||
|
|
|
@ -3577,15 +3577,15 @@ export class MangoClient {
|
|||
public async tokenConditionalSwapCancel(
|
||||
group: Group,
|
||||
account: MangoAccount,
|
||||
tokenConditionalSwapIndex: number,
|
||||
tokenConditionalSwapId: BN,
|
||||
): Promise<TransactionSignature> {
|
||||
const tcs = account
|
||||
.tokenConditionalSwapsActive()
|
||||
.find((tcs) => tcs.id.eq(tokenConditionalSwapId));
|
||||
if (!tcs) {
|
||||
const tokenConditionalSwapIndex = account.tokenConditionalSwaps.findIndex(
|
||||
(tcs) => tcs.id.eq(tokenConditionalSwapId),
|
||||
);
|
||||
if (tokenConditionalSwapIndex == -1) {
|
||||
throw new Error('tcs with id not found');
|
||||
}
|
||||
const tcs = account.tokenConditionalSwaps[tokenConditionalSwapIndex];
|
||||
|
||||
const buyBank = group.banksMapByTokenIndex.get(tcs.buyTokenIndex)![0];
|
||||
const sellBank = group.banksMapByTokenIndex.get(tcs.sellTokenIndex)![0];
|
||||
|
@ -3611,17 +3611,17 @@ export class MangoClient {
|
|||
group: Group,
|
||||
liqee: MangoAccount,
|
||||
liqor: MangoAccount,
|
||||
tokenConditionalSwapIndex: number,
|
||||
tokenConditionalSwapId: BN,
|
||||
maxBuyTokenToLiqee: number,
|
||||
maxSellTokenToLiqor: number,
|
||||
): Promise<TransactionSignature> {
|
||||
const tcs = liqee
|
||||
.tokenConditionalSwapsActive()
|
||||
.find((tcs) => tcs.id.eq(tokenConditionalSwapId));
|
||||
if (!tcs) {
|
||||
const tokenConditionalSwapIndex = liqee.tokenConditionalSwaps.findIndex(
|
||||
(tcs) => tcs.id.eq(tokenConditionalSwapId),
|
||||
);
|
||||
if (tokenConditionalSwapIndex == -1) {
|
||||
throw new Error('tcs with id not found');
|
||||
}
|
||||
const tcs = liqee.tokenConditionalSwaps[tokenConditionalSwapIndex];
|
||||
|
||||
const buyBank = group.banksMapByTokenIndex.get(tcs.buyTokenIndex)![0];
|
||||
const sellBank = group.banksMapByTokenIndex.get(tcs.sellTokenIndex)![0];
|
||||
|
|
|
@ -22,4 +22,6 @@ export const MANGO_V4_ID = {
|
|||
'mainnet-beta': new PublicKey('4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg'),
|
||||
};
|
||||
|
||||
export const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
||||
export const USDC_MINT = new PublicKey(
|
||||
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue