ts: reuse tcs creation function
This commit is contained in:
parent
27dadbb6bc
commit
f462c62816
|
@ -180,8 +180,8 @@ async function main() {
|
||||||
account,
|
account,
|
||||||
MINTS.get('SOL')!,
|
MINTS.get('SOL')!,
|
||||||
MINTS.get('USDC')!,
|
MINTS.get('USDC')!,
|
||||||
100000000,
|
new BN(100000000),
|
||||||
20000, // liqee only has 1k USDC-native, leverage does not go that far!
|
new BN(20000), // liqee only has 1k USDC-native, leverage does not go that far!
|
||||||
null,
|
null,
|
||||||
0.0,
|
0.0,
|
||||||
1000000.0,
|
1000000.0,
|
||||||
|
@ -204,8 +204,8 @@ async function main() {
|
||||||
account,
|
account,
|
||||||
MINTS.get('SOL')!,
|
MINTS.get('SOL')!,
|
||||||
MINTS.get('USDC')!,
|
MINTS.get('USDC')!,
|
||||||
1000,
|
new BN(1000),
|
||||||
1000,
|
new BN(1000),
|
||||||
null,
|
null,
|
||||||
0.0,
|
0.0,
|
||||||
1000000.0,
|
1000000.0,
|
||||||
|
@ -228,8 +228,8 @@ async function main() {
|
||||||
account,
|
account,
|
||||||
MINTS.get('SOL')!,
|
MINTS.get('SOL')!,
|
||||||
MINTS.get('USDC')!,
|
MINTS.get('USDC')!,
|
||||||
1000,
|
new BN(1000),
|
||||||
1000,
|
new BN(1000),
|
||||||
Date.now() / 1000 + 15, // expire in 15s
|
Date.now() / 1000 + 15, // expire in 15s
|
||||||
0.0,
|
0.0,
|
||||||
1000000.0,
|
1000000.0,
|
||||||
|
|
|
@ -3587,9 +3587,6 @@ export class MangoClient {
|
||||||
upperLimit = thresholdPrice;
|
upperLimit = thresholdPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
const expiryTimestampBn =
|
|
||||||
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN;
|
|
||||||
|
|
||||||
if (!pricePremium) {
|
if (!pricePremium) {
|
||||||
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
||||||
buyBank.tokenIndex,
|
buyBank.tokenIndex,
|
||||||
|
@ -3621,19 +3618,55 @@ export class MangoClient {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await this.tokenConditionalSwapCreateRaw(
|
||||||
|
group,
|
||||||
|
account,
|
||||||
|
buyBank.mint,
|
||||||
|
sellBank.mint,
|
||||||
|
maxBuy,
|
||||||
|
maxSell,
|
||||||
|
expiryTimestamp,
|
||||||
|
lowerLimit,
|
||||||
|
upperLimit,
|
||||||
|
pricePremiumRate,
|
||||||
|
allowCreatingDeposits,
|
||||||
|
allowCreatingBorrows,
|
||||||
|
thresholdPriceInSellPerBuyToken
|
||||||
|
? 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
|
const tcsIx = await this.program.methods
|
||||||
.tokenConditionalSwapCreateV2(
|
.tokenConditionalSwapCreateV2(
|
||||||
maxBuy,
|
maxBuy,
|
||||||
maxSell,
|
maxSell,
|
||||||
expiryTimestampBn,
|
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN,
|
||||||
lowerLimit,
|
priceLowerLimit,
|
||||||
upperLimit,
|
priceUpperLimit,
|
||||||
pricePremiumRate,
|
pricePremiumRate,
|
||||||
allowCreatingDeposits,
|
allowCreatingDeposits,
|
||||||
allowCreatingBorrows,
|
allowCreatingBorrows,
|
||||||
thresholdPriceInSellPerBuyToken
|
priceDisplayStyle,
|
||||||
? TokenConditionalSwapDisplayPriceStyle.sellTokenPerBuyToken
|
|
||||||
: TokenConditionalSwapDisplayPriceStyle.buyTokenPerSellToken,
|
|
||||||
intention,
|
intention,
|
||||||
)
|
)
|
||||||
.accounts({
|
.accounts({
|
||||||
|
@ -3664,64 +3697,6 @@ export class MangoClient {
|
||||||
return await this.sendAndConfirmTransactionForGroup(group, ixs);
|
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(
|
public async tokenConditionalSwapCancel(
|
||||||
group: Group,
|
group: Group,
|
||||||
account: MangoAccount,
|
account: MangoAccount,
|
||||||
|
|
Loading…
Reference in New Issue