@marinade.finance/kamino-sdk
Version:
104 lines • 5.34 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.openPositionV2 = exports.layout = void 0;
const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@project-serum/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
const programId_1 = require("../programId");
exports.layout = borsh.struct([
borsh.i32('tickLowerIndex'),
borsh.i32('tickUpperIndex'),
borsh.i32('tickArrayLowerStartIndex'),
borsh.i32('tickArrayUpperStartIndex'),
borsh.u128('liquidity'),
borsh.u64('amount0Max'),
borsh.u64('amount1Max'),
borsh.bool('withMatedata'),
borsh.option(borsh.bool(), 'baseFlag'),
]);
/**
* Creates a new position wrapped in a NFT, support Token2022
*
* # Arguments
*
* * `ctx` - The context of accounts
* * `tick_lower_index` - The low boundary of market
* * `tick_upper_index` - The upper boundary of market
* * `tick_array_lower_start_index` - The start index of tick array which include tick low
* * `tick_array_upper_start_index` - The start index of tick array which include tick upper
* * `liquidity` - The liquidity to be added, if zero, calculate liquidity base amount_0_max or amount_1_max according base_flag
* * `amount_0_max` - The max amount of token_0 to spend, which serves as a slippage check
* * `amount_1_max` - The max amount of token_1 to spend, which serves as a slippage check
* * `base_flag` - must be special if liquidity is zero, false: calculate liquidity base amount_0_max otherwise base amount_1_max
*
*/
function openPositionV2(args, accounts) {
const keys = [
{ pubkey: accounts.payer, isSigner: true, isWritable: true },
{ pubkey: accounts.positionNftOwner, isSigner: false, isWritable: false },
{ pubkey: accounts.positionNftMint, isSigner: true, isWritable: true },
{ pubkey: accounts.positionNftAccount, isSigner: false, isWritable: true },
{ pubkey: accounts.metadataAccount, isSigner: false, isWritable: true },
{ pubkey: accounts.poolState, isSigner: false, isWritable: true },
{ pubkey: accounts.protocolPosition, isSigner: false, isWritable: true },
{ pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true },
{ pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true },
{ pubkey: accounts.personalPosition, isSigner: false, isWritable: true },
{ pubkey: accounts.tokenAccount0, isSigner: false, isWritable: true },
{ pubkey: accounts.tokenAccount1, isSigner: false, isWritable: true },
{ pubkey: accounts.tokenVault0, isSigner: false, isWritable: true },
{ pubkey: accounts.tokenVault1, isSigner: false, isWritable: true },
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
{
pubkey: accounts.associatedTokenProgram,
isSigner: false,
isWritable: false,
},
{ pubkey: accounts.metadataProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.tokenProgram2022, isSigner: false, isWritable: false },
{ pubkey: accounts.vault0Mint, isSigner: false, isWritable: false },
{ pubkey: accounts.vault1Mint, isSigner: false, isWritable: false },
];
const identifier = Buffer.from([77, 184, 74, 214, 112, 86, 241, 199]);
const buffer = Buffer.alloc(1000);
const len = exports.layout.encode({
tickLowerIndex: args.tickLowerIndex,
tickUpperIndex: args.tickUpperIndex,
tickArrayLowerStartIndex: args.tickArrayLowerStartIndex,
tickArrayUpperStartIndex: args.tickArrayUpperStartIndex,
liquidity: args.liquidity,
amount0Max: args.amount0Max,
amount1Max: args.amount1Max,
withMatedata: args.withMatedata,
baseFlag: args.baseFlag,
}, buffer);
const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
const ix = new web3_js_1.TransactionInstruction({ keys, programId: programId_1.PROGRAM_ID, data });
return ix;
}
exports.openPositionV2 = openPositionV2;
//# sourceMappingURL=openPositionV2.js.map