@saberhq/stableswap-sdk
Advanced tools
Comparing version 1.12.30 to 1.12.31
@@ -5,7 +5,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const token_utils_1 = require("@saberhq/token-utils"); | ||
const BufferLayout = (0, tslib_1.__importStar)(require("@solana/buffer-layout")); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const fees_1 = require("../state/fees"); | ||
const layout_1 = require("../state/layout"); | ||
const _1 = require("."); | ||
const common_1 = require("./common"); | ||
@@ -33,18 +31,9 @@ /** | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
(0, token_utils_1.Uint64Layout)("targetAmp"), | ||
BufferLayout.ns64("stopRampTS"), | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1000), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.RampAIXLayout.span); | ||
_1.RampAIXLayout.encode({ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1000), | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -64,12 +53,8 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
let data = Buffer.alloc(_1.StopRampAIXLayout.span); | ||
const encodeLength = _1.StopRampAIXLayout.encode({ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -90,10 +75,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.PAUSE, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.PauseIXLayout.span); | ||
_1.PauseIXLayout.encode({ | ||
instruction: AdminInstruction.PAUSE, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -114,10 +95,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.UnpauseIXLayout.span); | ||
_1.UnpauseIXLayout.encode({ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -139,10 +116,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.SetFeeAccountIXLayout.span); | ||
_1.SetFeeAccountIXLayout.encode({ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -162,12 +135,7 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.ApplyNewAdminIXLayout.span); | ||
_1.ApplyNewAdminIXLayout.encode({ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -188,12 +156,8 @@ config, | ||
{ pubkey: newAdminAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -214,11 +178,7 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction"), layout_1.FeesLayout]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.SET_NEW_FEES, | ||
fees: (0, fees_1.encodeFees)(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(_1.SetNewFeesIXLayout.span); | ||
_1.SetNewFeesIXLayout.encode({ | ||
instruction: AdminInstruction.SET_NEW_FEES, | ||
fees: (0, fees_1.encodeFees)(fees), | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -225,0 +185,0 @@ config, |
export * from "./admin"; | ||
export { StableSwapConfig } from "./common"; | ||
export * from "./layouts"; | ||
export * from "./swap"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,3 +5,4 @@ "use strict"; | ||
(0, tslib_1.__exportStar)(require("./admin"), exports); | ||
(0, tslib_1.__exportStar)(require("./layouts"), exports); | ||
(0, tslib_1.__exportStar)(require("./swap"), exports); | ||
//# sourceMappingURL=index.js.map |
import type { u64 } from "@saberhq/token-utils"; | ||
import type { PublicKey, TransactionInstruction } from "@solana/web3.js"; | ||
import type { Fees } from "../state"; | ||
import type { Fees, RawFees } from "../state"; | ||
import type { StableSwapConfig } from "./common"; | ||
/** | ||
* Instruction enum. | ||
*/ | ||
export declare enum StableSwapInstruction { | ||
@@ -154,3 +157,6 @@ INITIALIZE = 0, | ||
} | ||
export declare const initializeSwapInstruction: ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }: InitializeSwapInstruction) => TransactionInstruction; | ||
export declare const initializeSwapInstructionRaw: ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }: Omit<InitializeSwapInstruction, "fees"> & { | ||
fees: RawFees; | ||
}) => TransactionInstruction; | ||
export declare const initializeSwapInstruction: ({ fees, ...args }: InitializeSwapInstruction) => TransactionInstruction; | ||
export declare const swapInstruction: ({ config, userAuthority, userSource, poolSource, poolDestination, userDestination, adminDestination, amountIn, minimumAmountOut, }: SwapInstruction) => TransactionInstruction; | ||
@@ -157,0 +163,0 @@ export declare const depositInstruction: ({ config, userAuthority, sourceA, sourceB, tokenAccountA, tokenAccountB, poolTokenMint, poolTokenAccount, tokenAmountA, tokenAmountB, minimumPoolTokenAmount, }: DepositInstruction) => TransactionInstruction; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withdrawOneInstruction = exports.withdrawInstruction = exports.depositInstruction = exports.swapInstruction = exports.initializeSwapInstruction = exports.StableSwapInstruction = void 0; | ||
exports.withdrawOneInstruction = exports.withdrawInstruction = exports.depositInstruction = exports.swapInstruction = exports.initializeSwapInstruction = exports.initializeSwapInstructionRaw = exports.StableSwapInstruction = void 0; | ||
const tslib_1 = require("tslib"); | ||
const token_utils_1 = require("@saberhq/token-utils"); | ||
const BufferLayout = (0, tslib_1.__importStar)(require("@solana/buffer-layout")); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const state_1 = require("../state"); | ||
const common_1 = require("./common"); | ||
const layouts_1 = require("./layouts"); | ||
/** | ||
* Instruction enum. | ||
*/ | ||
var StableSwapInstruction; | ||
@@ -18,3 +19,3 @@ (function (StableSwapInstruction) { | ||
})(StableSwapInstruction = exports.StableSwapInstruction || (exports.StableSwapInstruction = {})); | ||
const initializeSwapInstruction = ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees = state_1.ZERO_FEES, }) => { | ||
const initializeSwapInstructionRaw = ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }) => { | ||
const keys = [ | ||
@@ -33,20 +34,10 @@ { pubkey: config.swapAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
BufferLayout.u8("nonce"), | ||
(0, token_utils_1.Uint64Layout)("ampFactor"), | ||
state_1.FeesLayout, | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: StableSwapInstruction.INITIALIZE, | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees: (0, state_1.encodeFees)(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(layouts_1.InitializeSwapIXLayout.span); | ||
layouts_1.InitializeSwapIXLayout.encode({ | ||
instruction: StableSwapInstruction.INITIALIZE, | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees, | ||
}, data); | ||
return (0, common_1.buildInstruction)({ | ||
@@ -58,11 +49,11 @@ config, | ||
}; | ||
exports.initializeSwapInstructionRaw = initializeSwapInstructionRaw; | ||
const initializeSwapInstruction = (_a) => { | ||
var { fees = state_1.ZERO_FEES } = _a, args = (0, tslib_1.__rest)(_a, ["fees"]); | ||
return (0, exports.initializeSwapInstructionRaw)(Object.assign(Object.assign({}, args), { fees: (0, state_1.encodeFees)(fees) })); | ||
}; | ||
exports.initializeSwapInstruction = initializeSwapInstruction; | ||
const swapInstruction = ({ config, userAuthority, userSource, poolSource, poolDestination, userDestination, adminDestination, amountIn, minimumAmountOut, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
(0, token_utils_1.Uint64Layout)("amountIn"), | ||
(0, token_utils_1.Uint64Layout)("minimumAmountOut"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(layouts_1.SwapIXLayout.span); | ||
layouts_1.SwapIXLayout.encode({ | ||
instruction: StableSwapInstruction.SWAP, | ||
@@ -82,3 +73,2 @@ amountIn: amountIn.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -93,10 +83,4 @@ return (0, common_1.buildInstruction)({ | ||
const depositInstruction = ({ config, userAuthority, sourceA, sourceB, tokenAccountA, tokenAccountB, poolTokenMint, poolTokenAccount, tokenAmountA, tokenAmountB, minimumPoolTokenAmount, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
(0, token_utils_1.Uint64Layout)("tokenAmountA"), | ||
(0, token_utils_1.Uint64Layout)("tokenAmountB"), | ||
(0, token_utils_1.Uint64Layout)("minimumPoolTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(layouts_1.DepositIXLayout.span); | ||
layouts_1.DepositIXLayout.encode({ | ||
instruction: StableSwapInstruction.DEPOSIT, | ||
@@ -118,3 +102,2 @@ tokenAmountA: tokenAmountA.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -129,10 +112,4 @@ return (0, common_1.buildInstruction)({ | ||
const withdrawInstruction = ({ config, userAuthority, poolMint, sourceAccount, tokenAccountA, tokenAccountB, userAccountA, userAccountB, adminFeeAccountA, adminFeeAccountB, poolTokenAmount, minimumTokenA, minimumTokenB, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
(0, token_utils_1.Uint64Layout)("poolTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenA"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenB"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(layouts_1.WithdrawIXLayout.span); | ||
layouts_1.WithdrawIXLayout.encode({ | ||
instruction: StableSwapInstruction.WITHDRAW, | ||
@@ -156,3 +133,2 @@ poolTokenAmount: poolTokenAmount.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -167,9 +143,4 @@ return (0, common_1.buildInstruction)({ | ||
const withdrawOneInstruction = ({ config, userAuthority, poolMint, sourceAccount, baseTokenAccount, quoteTokenAccount, destinationAccount, adminDestinationAccount, poolTokenAmount, minimumTokenAmount, }) => { | ||
const withdrawOneDataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
(0, token_utils_1.Uint64Layout)("poolTokenAmount"), | ||
(0, token_utils_1.Uint64Layout)("minimumTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(withdrawOneDataLayout.span); | ||
withdrawOneDataLayout.encode({ | ||
const data = Buffer.alloc(layouts_1.WithdrawOneIXLayout.span); | ||
layouts_1.WithdrawOneIXLayout.encode({ | ||
instruction: StableSwapInstruction.WITHDRAW_ONE, | ||
@@ -190,3 +161,2 @@ poolTokenAmount: poolTokenAmount.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -193,0 +163,0 @@ return (0, common_1.buildInstruction)({ |
@@ -1,6 +0,4 @@ | ||
import { Uint64Layout } from "@saberhq/token-utils"; | ||
import * as BufferLayout from "@solana/buffer-layout"; | ||
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js"; | ||
import { encodeFees, ZERO_FEES } from "../state/fees"; | ||
import { FeesLayout } from "../state/layout"; | ||
import { ApplyNewAdminIXLayout, PauseIXLayout, RampAIXLayout, SetFeeAccountIXLayout, SetNewFeesIXLayout, StopRampAIXLayout, UnpauseIXLayout, } from "."; | ||
import { buildInstruction } from "./common"; | ||
@@ -28,18 +26,9 @@ /** | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("targetAmp"), | ||
BufferLayout.ns64("stopRampTS"), | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1000), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(RampAIXLayout.span); | ||
RampAIXLayout.encode({ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1000), | ||
}, data); | ||
return buildInstruction({ | ||
@@ -58,12 +47,8 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
let data = Buffer.alloc(StopRampAIXLayout.span); | ||
const encodeLength = StopRampAIXLayout.encode({ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
return buildInstruction({ | ||
@@ -83,10 +68,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.PAUSE, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(PauseIXLayout.span); | ||
PauseIXLayout.encode({ | ||
instruction: AdminInstruction.PAUSE, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -106,10 +87,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(UnpauseIXLayout.span); | ||
UnpauseIXLayout.encode({ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -130,10 +107,6 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(SetFeeAccountIXLayout.span); | ||
SetFeeAccountIXLayout.encode({ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -152,12 +125,7 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(ApplyNewAdminIXLayout.span); | ||
ApplyNewAdminIXLayout.encode({ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -177,12 +145,8 @@ config, | ||
{ pubkey: newAdminAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -202,11 +166,7 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction"), FeesLayout]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: AdminInstruction.SET_NEW_FEES, | ||
fees: encodeFees(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(SetNewFeesIXLayout.span); | ||
SetNewFeesIXLayout.encode({ | ||
instruction: AdminInstruction.SET_NEW_FEES, | ||
fees: encodeFees(fees), | ||
}, data); | ||
return buildInstruction({ | ||
@@ -213,0 +173,0 @@ config, |
export * from "./admin"; | ||
export { StableSwapConfig } from "./common"; | ||
export * from "./layouts"; | ||
export * from "./swap"; | ||
//# sourceMappingURL=index.d.ts.map |
export * from "./admin"; | ||
export * from "./layouts"; | ||
export * from "./swap"; | ||
//# sourceMappingURL=index.js.map |
import type { u64 } from "@saberhq/token-utils"; | ||
import type { PublicKey, TransactionInstruction } from "@solana/web3.js"; | ||
import type { Fees } from "../state"; | ||
import type { Fees, RawFees } from "../state"; | ||
import type { StableSwapConfig } from "./common"; | ||
/** | ||
* Instruction enum. | ||
*/ | ||
export declare enum StableSwapInstruction { | ||
@@ -154,3 +157,6 @@ INITIALIZE = 0, | ||
} | ||
export declare const initializeSwapInstruction: ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }: InitializeSwapInstruction) => TransactionInstruction; | ||
export declare const initializeSwapInstructionRaw: ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }: Omit<InitializeSwapInstruction, "fees"> & { | ||
fees: RawFees; | ||
}) => TransactionInstruction; | ||
export declare const initializeSwapInstruction: ({ fees, ...args }: InitializeSwapInstruction) => TransactionInstruction; | ||
export declare const swapInstruction: ({ config, userAuthority, userSource, poolSource, poolDestination, userDestination, adminDestination, amountIn, minimumAmountOut, }: SwapInstruction) => TransactionInstruction; | ||
@@ -157,0 +163,0 @@ export declare const depositInstruction: ({ config, userAuthority, sourceA, sourceB, tokenAccountA, tokenAccountB, poolTokenMint, poolTokenAccount, tokenAmountA, tokenAmountB, minimumPoolTokenAmount, }: DepositInstruction) => TransactionInstruction; |
@@ -1,6 +0,8 @@ | ||
import { Uint64Layout } from "@saberhq/token-utils"; | ||
import * as BufferLayout from "@solana/buffer-layout"; | ||
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js"; | ||
import { encodeFees, FeesLayout, ZERO_FEES } from "../state"; | ||
import { __rest } from "tslib"; | ||
import { encodeFees, ZERO_FEES } from "../state"; | ||
import { buildInstruction } from "./common"; | ||
import { DepositIXLayout, InitializeSwapIXLayout, SwapIXLayout, WithdrawIXLayout, WithdrawOneIXLayout, } from "./layouts"; | ||
/** | ||
* Instruction enum. | ||
*/ | ||
export var StableSwapInstruction; | ||
@@ -14,3 +16,3 @@ (function (StableSwapInstruction) { | ||
})(StableSwapInstruction || (StableSwapInstruction = {})); | ||
export const initializeSwapInstruction = ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees = ZERO_FEES, }) => { | ||
export const initializeSwapInstructionRaw = ({ config, adminAccount, tokenA: { adminFeeAccount: adminFeeAccountA, mint: tokenMintA, reserve: tokenAccountA, }, tokenB: { adminFeeAccount: adminFeeAccountB, mint: tokenMintB, reserve: tokenAccountB, }, poolTokenMint, destinationPoolTokenAccount, nonce, ampFactor, fees, }) => { | ||
const keys = [ | ||
@@ -29,20 +31,10 @@ { pubkey: config.swapAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
BufferLayout.u8("nonce"), | ||
Uint64Layout("ampFactor"), | ||
FeesLayout, | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode({ | ||
instruction: StableSwapInstruction.INITIALIZE, | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees: encodeFees(fees), | ||
}, data); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(InitializeSwapIXLayout.span); | ||
InitializeSwapIXLayout.encode({ | ||
instruction: StableSwapInstruction.INITIALIZE, | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees, | ||
}, data); | ||
return buildInstruction({ | ||
@@ -54,10 +46,9 @@ config, | ||
}; | ||
export const initializeSwapInstruction = (_a) => { | ||
var { fees = ZERO_FEES } = _a, args = __rest(_a, ["fees"]); | ||
return initializeSwapInstructionRaw(Object.assign(Object.assign({}, args), { fees: encodeFees(fees) })); | ||
}; | ||
export const swapInstruction = ({ config, userAuthority, userSource, poolSource, poolDestination, userDestination, adminDestination, amountIn, minimumAmountOut, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("amountIn"), | ||
Uint64Layout("minimumAmountOut"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(SwapIXLayout.span); | ||
SwapIXLayout.encode({ | ||
instruction: StableSwapInstruction.SWAP, | ||
@@ -77,3 +68,2 @@ amountIn: amountIn.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -87,10 +77,4 @@ return buildInstruction({ | ||
export const depositInstruction = ({ config, userAuthority, sourceA, sourceB, tokenAccountA, tokenAccountB, poolTokenMint, poolTokenAccount, tokenAmountA, tokenAmountB, minimumPoolTokenAmount, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("tokenAmountA"), | ||
Uint64Layout("tokenAmountB"), | ||
Uint64Layout("minimumPoolTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(DepositIXLayout.span); | ||
DepositIXLayout.encode({ | ||
instruction: StableSwapInstruction.DEPOSIT, | ||
@@ -112,3 +96,2 @@ tokenAmountA: tokenAmountA.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -122,10 +105,4 @@ return buildInstruction({ | ||
export const withdrawInstruction = ({ config, userAuthority, poolMint, sourceAccount, tokenAccountA, tokenAccountB, userAccountA, userAccountB, adminFeeAccountA, adminFeeAccountB, poolTokenAmount, minimumTokenA, minimumTokenB, }) => { | ||
const dataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("poolTokenAmount"), | ||
Uint64Layout("minimumTokenA"), | ||
Uint64Layout("minimumTokenB"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode({ | ||
const data = Buffer.alloc(WithdrawIXLayout.span); | ||
WithdrawIXLayout.encode({ | ||
instruction: StableSwapInstruction.WITHDRAW, | ||
@@ -149,3 +126,2 @@ poolTokenAmount: poolTokenAmount.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -159,9 +135,4 @@ return buildInstruction({ | ||
export const withdrawOneInstruction = ({ config, userAuthority, poolMint, sourceAccount, baseTokenAccount, quoteTokenAccount, destinationAccount, adminDestinationAccount, poolTokenAmount, minimumTokenAmount, }) => { | ||
const withdrawOneDataLayout = BufferLayout.struct([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("poolTokenAmount"), | ||
Uint64Layout("minimumTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(withdrawOneDataLayout.span); | ||
withdrawOneDataLayout.encode({ | ||
const data = Buffer.alloc(WithdrawOneIXLayout.span); | ||
WithdrawOneIXLayout.encode({ | ||
instruction: StableSwapInstruction.WITHDRAW_ONE, | ||
@@ -182,3 +153,2 @@ poolTokenAmount: poolTokenAmount.toBuffer(), | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -185,0 +155,0 @@ return buildInstruction({ |
@@ -13,3 +13,3 @@ { | ||
"author": "Saber Team <team@saber.so>", | ||
"version": "1.12.30", | ||
"version": "1.12.31", | ||
"main": "dist/cjs/index.js", | ||
@@ -30,3 +30,3 @@ "module": "dist/esm/index.js", | ||
"@types/lodash.mapvalues": "^4.6.6", | ||
"@types/node": "^16.11.19", | ||
"@types/node": "^16.11.20", | ||
"bn.js": "^5.2.0", | ||
@@ -41,4 +41,4 @@ "jsbi": "^4.1.0" | ||
"dependencies": { | ||
"@saberhq/solana-contrib": "^1.12.30", | ||
"@saberhq/token-utils": "^1.12.30", | ||
"@saberhq/solana-contrib": "^1.12.31", | ||
"@saberhq/token-utils": "^1.12.31", | ||
"@solana/buffer-layout": "^4.0.0", | ||
@@ -55,3 +55,3 @@ "lodash.mapvalues": "^4.6.0", | ||
}, | ||
"gitHead": "486233753e8e1550bff03d0d713a2711ff1a0742" | ||
"gitHead": "e706f6b3f6ce3128a6fdac65339338d8f5574a66" | ||
} |
import type { u64 } from "@saberhq/token-utils"; | ||
import { Uint64Layout } from "@saberhq/token-utils"; | ||
import * as BufferLayout from "@solana/buffer-layout"; | ||
import type { PublicKey, TransactionInstruction } from "@solana/web3.js"; | ||
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js"; | ||
@@ -10,4 +8,11 @@ import type { StableSwapState } from "../state"; | ||
import { encodeFees, ZERO_FEES } from "../state/fees"; | ||
import type { RawFees } from "../state/layout"; | ||
import { FeesLayout } from "../state/layout"; | ||
import { | ||
ApplyNewAdminIXLayout, | ||
PauseIXLayout, | ||
RampAIXLayout, | ||
SetFeeAccountIXLayout, | ||
SetNewFeesIXLayout, | ||
StopRampAIXLayout, | ||
UnpauseIXLayout, | ||
} from "."; | ||
import type { StableSwapConfig } from "./common"; | ||
@@ -47,25 +52,12 @@ import { buildInstruction } from "./common"; | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
targetAmp: Uint8Array; | ||
stopRampTS: number; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("targetAmp"), | ||
BufferLayout.ns64("stopRampTS"), | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1000), | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(RampAIXLayout.span); | ||
RampAIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.RAMP_A, | ||
targetAmp: targetAmp.toBuffer(), | ||
stopRampTS: Math.floor(stopRamp.getTime() / 1_000), | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -91,17 +83,11 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
let data = Buffer.alloc(StopRampAIXLayout.span); | ||
const encodeLength = StopRampAIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.STOP_RAMP_A, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
return buildInstruction({ | ||
@@ -128,15 +114,9 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.PAUSE, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(PauseIXLayout.span); | ||
PauseIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.PAUSE, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -163,15 +143,9 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(UnpauseIXLayout.span); | ||
UnpauseIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.UNPAUSE, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -201,15 +175,9 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(SetFeeAccountIXLayout.span); | ||
SetFeeAccountIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.SET_FEE_ACCOUNT, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -235,17 +203,10 @@ config, | ||
{ pubkey: adminAccount, isSigner: true, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(ApplyNewAdminIXLayout.span); | ||
ApplyNewAdminIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.APPLY_NEW_ADMIN, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -274,3 +235,2 @@ config, | ||
{ pubkey: newAdminAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -280,12 +240,9 @@ const dataLayout = BufferLayout.struct<{ | ||
}>([BufferLayout.u8("instruction")]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.COMMIT_NEW_ADMIN, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -314,17 +271,10 @@ config, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
fees: RawFees; | ||
}>([BufferLayout.u8("instruction"), FeesLayout]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: AdminInstruction.SET_NEW_FEES, // InitializeSwap instruction | ||
fees: encodeFees(fees), | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(SetNewFeesIXLayout.span); | ||
SetNewFeesIXLayout.encode( | ||
{ | ||
instruction: AdminInstruction.SET_NEW_FEES, // InitializeSwap instruction | ||
fees: encodeFees(fees), | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -331,0 +281,0 @@ config, |
export * from "./admin"; | ||
export { StableSwapConfig } from "./common"; | ||
export * from "./layouts"; | ||
export * from "./swap"; |
import type { u64 } from "@saberhq/token-utils"; | ||
import { Uint64Layout } from "@saberhq/token-utils"; | ||
import * as BufferLayout from "@solana/buffer-layout"; | ||
import type { PublicKey, TransactionInstruction } from "@solana/web3.js"; | ||
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js"; | ||
import type { Fees, RawFees } from "../state"; | ||
import { encodeFees, FeesLayout, ZERO_FEES } from "../state"; | ||
import { encodeFees, ZERO_FEES } from "../state"; | ||
import type { StableSwapConfig } from "./common"; | ||
import { buildInstruction } from "./common"; | ||
import { | ||
DepositIXLayout, | ||
InitializeSwapIXLayout, | ||
SwapIXLayout, | ||
WithdrawIXLayout, | ||
WithdrawOneIXLayout, | ||
} from "./layouts"; | ||
/** | ||
* Instruction enum. | ||
*/ | ||
export enum StableSwapInstruction { | ||
@@ -176,3 +183,3 @@ INITIALIZE = 0, | ||
export const initializeSwapInstruction = ({ | ||
export const initializeSwapInstructionRaw = ({ | ||
config, | ||
@@ -194,4 +201,6 @@ adminAccount, | ||
ampFactor, | ||
fees = ZERO_FEES, | ||
}: InitializeSwapInstruction): TransactionInstruction => { | ||
fees, | ||
}: Omit<InitializeSwapInstruction, "fees"> & { | ||
fees: RawFees; | ||
}): TransactionInstruction => { | ||
const keys = [ | ||
@@ -210,28 +219,13 @@ { pubkey: config.swapAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
nonce: number; | ||
ampFactor: Uint8Array; | ||
fees: RawFees; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
BufferLayout.u8("nonce"), | ||
Uint64Layout("ampFactor"), | ||
FeesLayout, | ||
]); | ||
let data = Buffer.alloc(dataLayout.span); | ||
{ | ||
const encodeLength = dataLayout.encode( | ||
{ | ||
instruction: StableSwapInstruction.INITIALIZE, // InitializeSwap instruction | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees: encodeFees(fees), | ||
}, | ||
data | ||
); | ||
data = data.slice(0, encodeLength); | ||
} | ||
const data = Buffer.alloc(InitializeSwapIXLayout.span); | ||
InitializeSwapIXLayout.encode( | ||
{ | ||
instruction: StableSwapInstruction.INITIALIZE, // InitializeSwap instruction | ||
nonce, | ||
ampFactor: ampFactor.toBuffer(), | ||
fees, | ||
}, | ||
data | ||
); | ||
return buildInstruction({ | ||
@@ -244,2 +238,9 @@ config, | ||
export const initializeSwapInstruction = ({ | ||
fees = ZERO_FEES, | ||
...args | ||
}: InitializeSwapInstruction): TransactionInstruction => { | ||
return initializeSwapInstructionRaw({ ...args, fees: encodeFees(fees) }); | ||
}; | ||
export const swapInstruction = ({ | ||
@@ -256,14 +257,4 @@ config, | ||
}: SwapInstruction): TransactionInstruction => { | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
amountIn: Uint8Array; | ||
minimumAmountOut: Uint8Array; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("amountIn"), | ||
Uint64Layout("minimumAmountOut"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode( | ||
const data = Buffer.alloc(SwapIXLayout.span); | ||
SwapIXLayout.encode( | ||
{ | ||
@@ -276,3 +267,2 @@ instruction: StableSwapInstruction.SWAP, // Swap instruction | ||
); | ||
const keys = [ | ||
@@ -288,3 +278,2 @@ { pubkey: config.swapAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -311,15 +300,4 @@ return buildInstruction({ | ||
}: DepositInstruction): TransactionInstruction => { | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
tokenAmountA: Uint8Array; | ||
tokenAmountB: Uint8Array; | ||
minimumPoolTokenAmount: Uint8Array; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("tokenAmountA"), | ||
Uint64Layout("tokenAmountB"), | ||
Uint64Layout("minimumPoolTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode( | ||
const data = Buffer.alloc(DepositIXLayout.span); | ||
DepositIXLayout.encode( | ||
{ | ||
@@ -333,3 +311,2 @@ instruction: StableSwapInstruction.DEPOSIT, // Deposit instruction | ||
); | ||
const keys = [ | ||
@@ -346,3 +323,2 @@ { pubkey: config.swapAccount, isSigner: false, isWritable: false }, | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -371,16 +347,4 @@ return buildInstruction({ | ||
}: WithdrawInstruction): TransactionInstruction => { | ||
const dataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
poolTokenAmount: Uint8Array; | ||
minimumTokenA: Uint8Array; | ||
minimumTokenB: Uint8Array; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("poolTokenAmount"), | ||
Uint64Layout("minimumTokenA"), | ||
Uint64Layout("minimumTokenB"), | ||
]); | ||
const data = Buffer.alloc(dataLayout.span); | ||
dataLayout.encode( | ||
const data = Buffer.alloc(WithdrawIXLayout.span); | ||
WithdrawIXLayout.encode( | ||
{ | ||
@@ -408,3 +372,2 @@ instruction: StableSwapInstruction.WITHDRAW, // Withdraw instruction | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -430,14 +393,4 @@ return buildInstruction({ | ||
}: WithdrawOneInstruction): TransactionInstruction => { | ||
const withdrawOneDataLayout = BufferLayout.struct<{ | ||
instruction: number; | ||
poolTokenAmount: Uint8Array; | ||
minimumTokenAmount: Uint8Array; | ||
}>([ | ||
BufferLayout.u8("instruction"), | ||
Uint64Layout("poolTokenAmount"), | ||
Uint64Layout("minimumTokenAmount"), | ||
]); | ||
const data = Buffer.alloc(withdrawOneDataLayout.span); | ||
withdrawOneDataLayout.encode( | ||
const data = Buffer.alloc(WithdrawOneIXLayout.span); | ||
WithdrawOneIXLayout.encode( | ||
{ | ||
@@ -462,3 +415,2 @@ instruction: StableSwapInstruction.WITHDRAW_ONE, // Withdraw instruction | ||
{ pubkey: config.tokenProgramID, isSigner: false, isWritable: false }, | ||
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, | ||
]; | ||
@@ -465,0 +417,0 @@ return buildInstruction({ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
592929
203
7755