ts: reuse tcs creation function
This commit is contained in:
parent
27dadbb6bc
commit
f462c62816
|
@ -180,8 +180,8 @@ async function main() {
|
|||
account,
|
||||
MINTS.get('SOL')!,
|
||||
MINTS.get('USDC')!,
|
||||
100000000,
|
||||
20000, // liqee only has 1k USDC-native, leverage does not go that far!
|
||||
new BN(100000000),
|
||||
new BN(20000), // liqee only has 1k USDC-native, leverage does not go that far!
|
||||
null,
|
||||
0.0,
|
||||
1000000.0,
|
||||
|
@ -204,8 +204,8 @@ async function main() {
|
|||
account,
|
||||
MINTS.get('SOL')!,
|
||||
MINTS.get('USDC')!,
|
||||
1000,
|
||||
1000,
|
||||
new BN(1000),
|
||||
new BN(1000),
|
||||
null,
|
||||
0.0,
|
||||
1000000.0,
|
||||
|
@ -228,8 +228,8 @@ async function main() {
|
|||
account,
|
||||
MINTS.get('SOL')!,
|
||||
MINTS.get('USDC')!,
|
||||
1000,
|
||||
1000,
|
||||
new BN(1000),
|
||||
new BN(1000),
|
||||
Date.now() / 1000 + 15, // expire in 15s
|
||||
0.0,
|
||||
1000000.0,
|
||||
|
|
|
@ -3587,9 +3587,6 @@ export class MangoClient {
|
|||
upperLimit = thresholdPrice;
|
||||
}
|
||||
|
||||
const expiryTimestampBn =
|
||||
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN;
|
||||
|
||||
if (!pricePremium) {
|
||||
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
||||
buyBank.tokenIndex,
|
||||
|
@ -3621,11 +3618,14 @@ export class MangoClient {
|
|||
break;
|
||||
}
|
||||
|
||||
const tcsIx = await this.program.methods
|
||||
.tokenConditionalSwapCreateV2(
|
||||
return await this.tokenConditionalSwapCreateRaw(
|
||||
group,
|
||||
account,
|
||||
buyBank.mint,
|
||||
sellBank.mint,
|
||||
maxBuy,
|
||||
maxSell,
|
||||
expiryTimestampBn,
|
||||
expiryTimestamp,
|
||||
lowerLimit,
|
||||
upperLimit,
|
||||
pricePremiumRate,
|
||||
|
@ -3635,6 +3635,39 @@ export class MangoClient {
|
|||
? TokenConditionalSwapDisplayPriceStyle.sellTokenPerBuyToken
|
||||
: TokenConditionalSwapDisplayPriceStyle.buyTokenPerSellToken,
|
||||
intention,
|
||||
);
|
||||
}
|
||||
|
||||
public async tokenConditionalSwapCreateRaw(
|
||||
group: Group,
|
||||
account: MangoAccount,
|
||||
buyMintPk: PublicKey,
|
||||
sellMintPk: PublicKey,
|
||||
maxBuy: BN,
|
||||
maxSell: BN,
|
||||
expiryTimestamp: number | null,
|
||||
priceLowerLimit: number,
|
||||
priceUpperLimit: number,
|
||||
pricePremiumRate: number,
|
||||
allowCreatingDeposits: boolean,
|
||||
allowCreatingBorrows: boolean,
|
||||
priceDisplayStyle: TokenConditionalSwapDisplayPriceStyle,
|
||||
intention: TokenConditionalSwapIntention,
|
||||
): Promise<TransactionSignature> {
|
||||
const buyBank: Bank = group.getFirstBankByMint(buyMintPk);
|
||||
const sellBank: Bank = group.getFirstBankByMint(sellMintPk);
|
||||
const tcsIx = await this.program.methods
|
||||
.tokenConditionalSwapCreateV2(
|
||||
maxBuy,
|
||||
maxSell,
|
||||
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN,
|
||||
priceLowerLimit,
|
||||
priceUpperLimit,
|
||||
pricePremiumRate,
|
||||
allowCreatingDeposits,
|
||||
allowCreatingBorrows,
|
||||
priceDisplayStyle,
|
||||
intention,
|
||||
)
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
|
@ -3664,64 +3697,6 @@ export class MangoClient {
|
|||
return await this.sendAndConfirmTransactionForGroup(group, ixs);
|
||||
}
|
||||
|
||||
public async tokenConditionalSwapCreateRaw(
|
||||
group: Group,
|
||||
account: MangoAccount,
|
||||
buyMintPk: PublicKey,
|
||||
sellMintPk: PublicKey,
|
||||
maxBuy: number,
|
||||
maxSell: number,
|
||||
expiryTimestamp: number | null,
|
||||
priceLowerLimit: number,
|
||||
priceUpperLimit: number,
|
||||
pricePremiumRate: number,
|
||||
allowCreatingDeposits: boolean,
|
||||
allowCreatingBorrows: boolean,
|
||||
priceDisplayStyle: TokenConditionalSwapDisplayPriceStyle,
|
||||
intention: TokenConditionalSwapIntention,
|
||||
): Promise<TransactionSignature> {
|
||||
const buyBank: Bank = group.getFirstBankByMint(buyMintPk);
|
||||
const sellBank: Bank = group.getFirstBankByMint(sellMintPk);
|
||||
const ix = await this.program.methods
|
||||
.tokenConditionalSwapCreateV2(
|
||||
new BN(maxBuy),
|
||||
new BN(maxSell),
|
||||
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN,
|
||||
priceLowerLimit,
|
||||
priceUpperLimit,
|
||||
pricePremiumRate,
|
||||
allowCreatingDeposits,
|
||||
allowCreatingBorrows,
|
||||
priceDisplayStyle,
|
||||
intention,
|
||||
)
|
||||
.accounts({
|
||||
group: group.publicKey,
|
||||
account: account.publicKey,
|
||||
authority: (this.program.provider as AnchorProvider).wallet.publicKey,
|
||||
buyBank: buyBank.publicKey,
|
||||
sellBank: sellBank.publicKey,
|
||||
})
|
||||
.instruction();
|
||||
|
||||
const ixs = [ix];
|
||||
if (account.tokenConditionalSwaps.length == 0) {
|
||||
ixs.push(
|
||||
await this.accountExpandV2Ix(
|
||||
group,
|
||||
account,
|
||||
account.tokens.length,
|
||||
account.serum3.length,
|
||||
account.perps.length,
|
||||
account.perpOpenOrders.length,
|
||||
8,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return await this.sendAndConfirmTransactionForGroup(group, ixs);
|
||||
}
|
||||
|
||||
public async tokenConditionalSwapCancel(
|
||||
group: Group,
|
||||
account: MangoAccount,
|
||||
|
|
Loading…
Reference in New Issue