@marinade.finance/kamino-sdk
Version:
74 lines • 3.49 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.swap = 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.u64('amount'),
borsh.u64('otherAmountThreshold'),
borsh.u128('sqrtPriceLimitX64'),
borsh.bool('isBaseInput'),
]);
/**
* Swaps one token for as much as possible of another token across a single pool
*
* # Arguments
*
* * `ctx` - The context of accounts
* * `amount` - Arranged in pairs with other_amount_threshold. (amount_in, amount_out_minimum) or (amount_out, amount_in_maximum)
* * `other_amount_threshold` - For slippage check
* * `sqrt_price_limit` - The Q64.64 sqrt price √P limit. If zero for one, the price cannot
* * `is_base_input` - swap base input or swap base output
*
*/
function swap(args, accounts) {
const keys = [
{ pubkey: accounts.payer, isSigner: true, isWritable: false },
{ pubkey: accounts.ammConfig, isSigner: false, isWritable: false },
{ pubkey: accounts.poolState, isSigner: false, isWritable: true },
{ pubkey: accounts.inputTokenAccount, isSigner: false, isWritable: true },
{ pubkey: accounts.outputTokenAccount, isSigner: false, isWritable: true },
{ pubkey: accounts.inputVault, isSigner: false, isWritable: true },
{ pubkey: accounts.outputVault, isSigner: false, isWritable: true },
{ pubkey: accounts.observationState, isSigner: false, isWritable: true },
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.tickArray, isSigner: false, isWritable: true },
];
const identifier = Buffer.from([248, 198, 158, 145, 225, 117, 135, 200]);
const buffer = Buffer.alloc(1000);
const len = exports.layout.encode({
amount: args.amount,
otherAmountThreshold: args.otherAmountThreshold,
sqrtPriceLimitX64: args.sqrtPriceLimitX64,
isBaseInput: args.isBaseInput,
}, 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.swap = swap;
//# sourceMappingURL=swap.js.map