@exponent-labs/exponent-sdk 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/addressLookupTableUtil.js +3 -2
- package/build/addressLookupTableUtil.js.map +1 -1
- package/build/events.d.ts +3 -3
- package/build/events.js +49 -47
- package/build/events.js.map +1 -1
- package/build/flavors.d.ts +3 -3
- package/build/flavors.js +34 -38
- package/build/flavors.js.map +1 -1
- package/build/index.js +7 -17
- package/build/index.js.map +1 -1
- package/build/lpPosition.d.ts +6 -5
- package/build/lpPosition.js +37 -19
- package/build/lpPosition.js.map +1 -1
- package/build/market.d.ts +34 -34
- package/build/market.js +207 -203
- package/build/market.js.map +1 -1
- package/build/syPosition.d.ts +2 -2
- package/build/syPosition.js +21 -17
- package/build/syPosition.js.map +1 -1
- package/build/tokenUtil.d.ts +2 -2
- package/build/tokenUtil.js +7 -6
- package/build/tokenUtil.js.map +1 -1
- package/build/utils/altUtil.d.ts +3 -3
- package/build/utils/altUtil.js +18 -11
- package/build/utils/altUtil.js.map +1 -1
- package/build/utils/binSolver.js +2 -1
- package/build/utils/binSolver.js.map +1 -1
- package/build/utils/binSolver.test.js +6 -5
- package/build/utils/binSolver.test.js.map +1 -1
- package/build/utils/index.js +4 -3
- package/build/utils/index.js.map +1 -1
- package/build/vault.d.ts +12 -11
- package/build/vault.js +69 -68
- package/build/vault.js.map +1 -1
- package/build/ytPosition.d.ts +9 -8
- package/build/ytPosition.js +42 -34
- package/build/ytPosition.js.map +1 -1
- package/package.json +22 -22
- package/src/addressLookupTableUtil.ts +2 -1
- package/src/events.ts +60 -45
- package/src/flavors.ts +33 -39
- package/src/lpPosition.ts +49 -21
- package/src/market.ts +307 -229
- package/src/syPosition.ts +38 -26
- package/src/tokenUtil.ts +7 -5
- package/src/utils/altUtil.ts +17 -12
- package/src/utils/binSolver.test.ts +2 -0
- package/src/utils/index.ts +2 -0
- package/src/vault.ts +108 -91
- package/src/ytPosition.ts +57 -37
package/build/market.js
CHANGED
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Market = exports.MyWallet = void 0;
|
|
4
4
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
-
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
6
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
-
const
|
|
8
|
-
const tokenUtil_1 = require("./tokenUtil");
|
|
9
|
-
const flavors_1 = require("./flavors");
|
|
6
|
+
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
10
7
|
const exponent_idl_1 = require("@exponent-labs/exponent-idl");
|
|
11
|
-
const anchor_2 = require("@coral-xyz/anchor");
|
|
12
8
|
const exponent_pda_1 = require("@exponent-labs/exponent-pda");
|
|
13
|
-
const vault_1 = require("./vault");
|
|
14
|
-
const market_math_1 = require("@exponent-labs/market-math");
|
|
15
|
-
const utils_1 = require("./utils");
|
|
16
9
|
const exponent_types_1 = require("@exponent-labs/exponent-types");
|
|
10
|
+
const market_math_1 = require("@exponent-labs/market-math");
|
|
17
11
|
const precise_number_1 = require("@exponent-labs/precise-number");
|
|
18
|
-
const
|
|
12
|
+
const addressLookupTableUtil_1 = require("./addressLookupTableUtil");
|
|
13
|
+
const flavors_1 = require("./flavors");
|
|
19
14
|
const syPosition_1 = require("./syPosition");
|
|
15
|
+
const tokenUtil_1 = require("./tokenUtil");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
17
|
+
const altUtil_1 = require("./utils/altUtil");
|
|
18
|
+
const vault_1 = require("./vault");
|
|
20
19
|
const SECONDS_PER_YEAR = 365 * 24 * 60 * 60;
|
|
20
|
+
//TODO Put it in the shared package because this code is repeated in many packages
|
|
21
21
|
class MyWallet {
|
|
22
22
|
payer;
|
|
23
23
|
constructor(payer) {
|
|
@@ -67,13 +67,13 @@ class Market {
|
|
|
67
67
|
}
|
|
68
68
|
static async load(env, connection, address, vault, options = {}) {
|
|
69
69
|
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection });
|
|
70
|
-
const
|
|
70
|
+
const fetchedMarket = await fetcher.fetchMarket(address);
|
|
71
71
|
const [[lpSupply, sySupply], alt, loadedVault] = await Promise.all([
|
|
72
|
-
(0, tokenUtil_1.getMultipleMintSupply)(connection, [
|
|
73
|
-
(0, addressLookupTableUtil_1.fetchAddressLookupTable)(connection,
|
|
74
|
-
vault || vault_1.Vault.load(env, connection,
|
|
72
|
+
(0, tokenUtil_1.getMultipleMintSupply)(connection, [fetchedMarket.mintLp, fetchedMarket.mintSy]),
|
|
73
|
+
(0, addressLookupTableUtil_1.fetchAddressLookupTable)(connection, fetchedMarket.addressLookupTable),
|
|
74
|
+
vault || vault_1.Vault.load(env, connection, fetchedMarket.vault, options),
|
|
75
75
|
]);
|
|
76
|
-
const cpiAccounts = (0, addressLookupTableUtil_1.makeCpiAccountMetaLists)(alt,
|
|
76
|
+
const cpiAccounts = (0, addressLookupTableUtil_1.makeCpiAccountMetaLists)(alt, fetchedMarket.cpiAccounts);
|
|
77
77
|
const flavor = (() => {
|
|
78
78
|
switch (loadedVault.flavor.flavor) {
|
|
79
79
|
case "marginfi":
|
|
@@ -90,9 +90,9 @@ class Market {
|
|
|
90
90
|
throw new Error(`Unknown flavor: ${loadedVault.flavor}`);
|
|
91
91
|
}
|
|
92
92
|
})();
|
|
93
|
-
const syPosition = await (0, syPosition_1.makeSyPosition)(fetcher, flavor,
|
|
93
|
+
const syPosition = await (0, syPosition_1.makeSyPosition)(fetcher, flavor, fetchedMarket.syProgram, address);
|
|
94
94
|
const state = {
|
|
95
|
-
...
|
|
95
|
+
...fetchedMarket,
|
|
96
96
|
vault: loadedVault,
|
|
97
97
|
cpiAccounts,
|
|
98
98
|
lpSupply,
|
|
@@ -102,10 +102,10 @@ class Market {
|
|
|
102
102
|
};
|
|
103
103
|
return new Market(state, address, env, connection);
|
|
104
104
|
}
|
|
105
|
-
async reload(
|
|
106
|
-
const
|
|
107
|
-
this.state =
|
|
108
|
-
return
|
|
105
|
+
async reload(connection = this.connection) {
|
|
106
|
+
const market = await Market.load(this.env, connection, this.selfAddress);
|
|
107
|
+
this.state = market.state;
|
|
108
|
+
return market;
|
|
109
109
|
}
|
|
110
110
|
/** Convert to a JSON representation */
|
|
111
111
|
toJson() {
|
|
@@ -236,8 +236,8 @@ class Market {
|
|
|
236
236
|
return this.currentPtPriceInAsset / this.currentSyExchangeRate;
|
|
237
237
|
}
|
|
238
238
|
get currentPtPriceInAsset() {
|
|
239
|
-
const
|
|
240
|
-
return
|
|
239
|
+
const marketCalculator = this.marketCalculator();
|
|
240
|
+
return marketCalculator.exchangeRate;
|
|
241
241
|
}
|
|
242
242
|
get ptDiscount() {
|
|
243
243
|
return 1 / this.currentPtPriceInAsset;
|
|
@@ -249,21 +249,27 @@ class Market {
|
|
|
249
249
|
return Number(this.lpSupply) === 0 ? 0 : liquidityPoolTvl / Number(this.lpSupply);
|
|
250
250
|
}
|
|
251
251
|
get secondsRemaining() {
|
|
252
|
-
const
|
|
253
|
-
return Math.max(0, Math.round(this.state.expirationTs -
|
|
252
|
+
const timeNow = Date.now() / 1000;
|
|
253
|
+
return Math.max(0, Math.round(this.state.expirationTs - timeNow));
|
|
254
254
|
}
|
|
255
255
|
get absolutePtYield() {
|
|
256
256
|
const ptAssetExchangeRate = this.ptDiscount;
|
|
257
257
|
return (1 - ptAssetExchangeRate) / ptAssetExchangeRate;
|
|
258
258
|
}
|
|
259
259
|
/** Annualize a rate given the number of seconds remaining until maturity */
|
|
260
|
-
static annualize(
|
|
261
|
-
return (
|
|
260
|
+
static annualize(rate, secondsRemaining) {
|
|
261
|
+
return (rate * SECONDS_PER_YEAR) / secondsRemaining;
|
|
262
|
+
}
|
|
263
|
+
static annualizeApy(rate, secondsRemaining) {
|
|
264
|
+
return (1 + rate) ** (SECONDS_PER_YEAR / secondsRemaining) - 1;
|
|
262
265
|
}
|
|
263
266
|
/** Annualized PT fixed rate */
|
|
264
267
|
get ptApr() {
|
|
265
268
|
return Market.annualize(this.absolutePtYield, this.secondsRemaining);
|
|
266
269
|
}
|
|
270
|
+
get ptApy() {
|
|
271
|
+
return Market.annualizeApy(this.absolutePtYield, this.secondsRemaining);
|
|
272
|
+
}
|
|
267
273
|
/** The fee rate taken off of trade fees (typically around 20%) expressed as a BPS number */
|
|
268
274
|
get feeTreasuryBps() {
|
|
269
275
|
return this.state.feeTreasurySyBps;
|
|
@@ -279,7 +285,7 @@ class Market {
|
|
|
279
285
|
get feeTreasuryRate() {
|
|
280
286
|
return this.feeTreasuryBps / 10_000;
|
|
281
287
|
}
|
|
282
|
-
/** Calculate
|
|
288
|
+
/** Calculate amount of LP tokens to expect for tokens in */
|
|
283
289
|
lpOutForTokensIn(syInIntent, ptInIntent) {
|
|
284
290
|
return (0, market_math_1.lpOutForTokensIn)({
|
|
285
291
|
syIntent: Number(syInIntent),
|
|
@@ -290,7 +296,8 @@ class Market {
|
|
|
290
296
|
});
|
|
291
297
|
}
|
|
292
298
|
marketCalculator() {
|
|
293
|
-
const
|
|
299
|
+
const timeNow = Date.now() / 1000;
|
|
300
|
+
const secondsRemaining = Math.max(0, Math.round(this.state.expirationTs - timeNow));
|
|
294
301
|
return new market_math_1.MarketCalculator({
|
|
295
302
|
liquiditySy: parseInt(this.syBalance.toString()),
|
|
296
303
|
liquidityPt: parseInt(this.ptBalance.toString()),
|
|
@@ -305,6 +312,7 @@ class Market {
|
|
|
305
312
|
windowStartTimestamp: this.state.liquidityNetBalanceLimits.windowStartTimestamp,
|
|
306
313
|
windowStartNetBalance: this.state.liquidityNetBalanceLimits.windowStartNetBalance.toNumber(),
|
|
307
314
|
windowDurationSeconds: this.state.liquidityNetBalanceLimits.windowDurationSeconds,
|
|
315
|
+
feeTreasurySyBps: this.state.feeTreasurySyBps,
|
|
308
316
|
});
|
|
309
317
|
}
|
|
310
318
|
/** Deposit a pair of tokens as liquidity to the market
|
|
@@ -315,14 +323,14 @@ class Market {
|
|
|
315
323
|
*
|
|
316
324
|
* The token accounts themselves are optional, and will be derived from the depositor's wallet if not provided
|
|
317
325
|
*/
|
|
318
|
-
async ixDepositLiquidity({ ptInIntent, syInIntent, minLpOut, depositor, ptSrc, sySrc, lpDst, }) {
|
|
326
|
+
async ixDepositLiquidity({ ptInIntent, syInIntent, minLpOut, depositor, ptSrc: ptSrcParam, sySrc: sySrcParam, lpDst: lpDstParam, }) {
|
|
319
327
|
const tokenProgram = spl_token_1.TOKEN_PROGRAM_ID;
|
|
320
|
-
sySrc =
|
|
321
|
-
ptSrc =
|
|
322
|
-
lpDst =
|
|
328
|
+
const sySrc = sySrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
329
|
+
const ptSrc = ptSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
330
|
+
const lpDst = lpDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
323
331
|
const syRemAccounts = this.cpiAccounts.depositSy;
|
|
324
332
|
return this.coreProgram.methods
|
|
325
|
-
.marketTwoDepositLiquidity(new
|
|
333
|
+
.marketTwoDepositLiquidity(new anchor_1.BN(ptInIntent.toString()), new anchor_1.BN(syInIntent.toString()), new anchor_1.BN(minLpOut.toString()))
|
|
326
334
|
.accountsStrict({
|
|
327
335
|
depositor,
|
|
328
336
|
market: this.selfAddress,
|
|
@@ -352,11 +360,11 @@ class Market {
|
|
|
352
360
|
})
|
|
353
361
|
.instruction();
|
|
354
362
|
}
|
|
355
|
-
async ixModifyFarm({ newRate, untilTimestamp, signer, farmMint, farmTokenProgram, farmTokenSrc, }) {
|
|
356
|
-
farmTokenSrc =
|
|
363
|
+
async ixModifyFarm({ newRate, untilTimestamp, signer, farmMint, farmTokenProgram, farmTokenSrc: farmTokenSrcParam, }) {
|
|
364
|
+
const farmTokenSrc = farmTokenSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, signer, true, farmTokenProgram);
|
|
357
365
|
const tokenFarm = (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, this.selfAddress, true, farmTokenProgram);
|
|
358
366
|
return this.coreProgram.methods
|
|
359
|
-
.modifyFarm(untilTimestamp, new
|
|
367
|
+
.modifyFarm(untilTimestamp, new anchor_1.BN(newRate.toString()))
|
|
360
368
|
.accountsStrict({
|
|
361
369
|
adminState: (0, utils_1.getExponentAdminStatePda)(),
|
|
362
370
|
market: this.selfAddress,
|
|
@@ -377,16 +385,16 @@ class Market {
|
|
|
377
385
|
*
|
|
378
386
|
* The token accounts themselves are optional, and will be derived from the withdrawer's wallet if not provided
|
|
379
387
|
*/
|
|
380
|
-
async ixWithdrawLiquidity({ lpIn, withdrawer, minPtOut, minSyOut, ptDst, syDst, lpSrc, }) {
|
|
381
|
-
ptDst =
|
|
382
|
-
syDst =
|
|
383
|
-
lpSrc =
|
|
388
|
+
async ixWithdrawLiquidity({ lpIn, withdrawer, minPtOut, minSyOut, ptDst: ptDstParam, syDst: syDstParam, lpSrc: lpSrcParam, }) {
|
|
389
|
+
const ptDst = ptDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, withdrawer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
390
|
+
const syDst = syDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, withdrawer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
391
|
+
const lpSrc = lpSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, withdrawer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
384
392
|
const ptDstAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, ptDst, withdrawer, this.mintPt);
|
|
385
393
|
const syDstAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, syDst, withdrawer, this.mintSy);
|
|
386
394
|
const lpSrcAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, lpSrc, withdrawer, this.mintLp);
|
|
387
395
|
const syRemAccounts = this.cpiAccounts.withdrawSy;
|
|
388
396
|
const ixs = await this.coreProgram.methods
|
|
389
|
-
.marketTwoWithdrawLiquidity(new
|
|
397
|
+
.marketTwoWithdrawLiquidity(new anchor_1.BN(lpIn.toString()), new anchor_1.BN(minPtOut.toString()), new anchor_1.BN(minSyOut.toString()))
|
|
390
398
|
.accountsStrict({
|
|
391
399
|
withdrawer,
|
|
392
400
|
market: this.selfAddress,
|
|
@@ -442,9 +450,9 @@ class Market {
|
|
|
442
450
|
tokenSy,
|
|
443
451
|
});
|
|
444
452
|
}
|
|
445
|
-
async ixTradePt({ trader, traderPt, syConstraint, isBuy, tokenPt, tokenSy, }) {
|
|
446
|
-
tokenPt =
|
|
447
|
-
tokenSy =
|
|
453
|
+
async ixTradePt({ trader, traderPt, syConstraint, isBuy, tokenPt: tokenPtParam, tokenSy: tokenSyParam, }) {
|
|
454
|
+
const tokenPt = tokenPtParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
455
|
+
const tokenSy = tokenSyParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
448
456
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, tokenSy, trader, this.mintSy);
|
|
449
457
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, tokenPt, trader, this.mintPt);
|
|
450
458
|
const remainingAccounts = [
|
|
@@ -452,8 +460,8 @@ class Market {
|
|
|
452
460
|
...this.cpiAccounts.depositSy,
|
|
453
461
|
...this.cpiAccounts.withdrawSy,
|
|
454
462
|
];
|
|
455
|
-
const netTradePtBN = new
|
|
456
|
-
const syConstraintBN = new
|
|
463
|
+
const netTradePtBN = new anchor_1.BN(traderPt.toString()).mul(isBuy ? new anchor_1.BN(1) : new anchor_1.BN(-1));
|
|
464
|
+
const syConstraintBN = new anchor_1.BN(syConstraint.toString()).mul(isBuy ? new anchor_1.BN(-1) : new anchor_1.BN(1));
|
|
457
465
|
const ix = await this.coreProgram.methods
|
|
458
466
|
.tradePt(netTradePtBN, syConstraintBN)
|
|
459
467
|
.accountsStrict({
|
|
@@ -484,10 +492,10 @@ class Market {
|
|
|
484
492
|
*
|
|
485
493
|
* The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
|
|
486
494
|
*/
|
|
487
|
-
async ixSellYt({ trader, ytIn, minSyOut, ytSrc, ptSrc, syDst, }) {
|
|
488
|
-
syDst =
|
|
489
|
-
ptSrc =
|
|
490
|
-
ytSrc =
|
|
495
|
+
async ixSellYt({ trader, ytIn, minSyOut, ytSrc: ytSrcParam, ptSrc: ptSrcParam, syDst: syDstParam, }) {
|
|
496
|
+
const syDst = syDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
497
|
+
const ptSrc = ptSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
498
|
+
const ytSrc = ytSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
491
499
|
const syDstAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, syDst, trader, this.mintSy);
|
|
492
500
|
const ptSrcAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ptSrc, trader, this.mintPt);
|
|
493
501
|
const ytSrcAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ytSrc, trader, this.mintYt);
|
|
@@ -499,7 +507,7 @@ class Market {
|
|
|
499
507
|
]);
|
|
500
508
|
remainingAccounts.push({ pubkey: this.coreProgram.programId, isWritable: false, isSigner: false });
|
|
501
509
|
const ix = await this.coreProgram.methods
|
|
502
|
-
.sellYt(new
|
|
510
|
+
.sellYt(new anchor_1.BN(ytIn.toString()), new anchor_1.BN(minSyOut.toString()))
|
|
503
511
|
.accountsStrict({
|
|
504
512
|
trader,
|
|
505
513
|
market: this.selfAddress,
|
|
@@ -536,10 +544,10 @@ class Market {
|
|
|
536
544
|
*
|
|
537
545
|
* The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
|
|
538
546
|
*/
|
|
539
|
-
async ixBuyYt({ trader, ytOut, maxSyIn, ytTrader, ptTrader, syTrader, }) {
|
|
540
|
-
syTrader =
|
|
541
|
-
ptTrader =
|
|
542
|
-
ytTrader =
|
|
547
|
+
async ixBuyYt({ trader, ytOut, maxSyIn, ytTrader: ytTraderParam, ptTrader: ptTraderParam, syTrader: syTraderParam, }) {
|
|
548
|
+
const syTrader = syTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
549
|
+
const ptTrader = ptTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
550
|
+
const ytTrader = ytTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, trader, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
543
551
|
const syTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, syTrader, trader, this.mintSy);
|
|
544
552
|
const ptTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ptTrader, trader, this.mintPt);
|
|
545
553
|
const ytTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ytTrader, trader, this.mintYt);
|
|
@@ -557,7 +565,7 @@ class Market {
|
|
|
557
565
|
]);
|
|
558
566
|
remainingAccounts.push({ pubkey: this.coreProgram.programId, isWritable: false, isSigner: false });
|
|
559
567
|
const ix = await this.coreProgram.methods
|
|
560
|
-
.buyYt(new
|
|
568
|
+
.buyYt(new anchor_1.BN(maxSyIn.toString()), new anchor_1.BN(ytOut.toString()))
|
|
561
569
|
.accountsStrict({
|
|
562
570
|
trader,
|
|
563
571
|
market: this.selfAddress,
|
|
@@ -600,11 +608,11 @@ class Market {
|
|
|
600
608
|
.instruction();
|
|
601
609
|
}
|
|
602
610
|
/** Deposit LP tokens into the farming module to earn rewards */
|
|
603
|
-
async ixDepositLp({ owner, amount, lpSrc }) {
|
|
604
|
-
lpSrc =
|
|
611
|
+
async ixDepositLp({ owner, amount, lpSrc: lpSrcParam, }) {
|
|
612
|
+
const lpSrc = lpSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
605
613
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
606
614
|
return this.coreProgram.methods
|
|
607
|
-
.marketDepositLp(new
|
|
615
|
+
.marketDepositLp(new anchor_1.BN(amount.toString()))
|
|
608
616
|
.accountsStrict({
|
|
609
617
|
owner,
|
|
610
618
|
lpPosition,
|
|
@@ -623,11 +631,11 @@ class Market {
|
|
|
623
631
|
.instruction();
|
|
624
632
|
}
|
|
625
633
|
/** Withdraw LP tokens from the farming module */
|
|
626
|
-
async ixWithdrawLp({ owner, amount, lpDst }) {
|
|
627
|
-
lpDst =
|
|
634
|
+
async ixWithdrawLp({ owner, amount, lpDst: lpDstParam, }) {
|
|
635
|
+
const lpDst = lpDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
628
636
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
629
637
|
return this.coreProgram.methods
|
|
630
|
-
.marketWithdrawLp(new
|
|
638
|
+
.marketWithdrawLp(new anchor_1.BN(amount.toString()))
|
|
631
639
|
.accountsStrict({
|
|
632
640
|
owner,
|
|
633
641
|
lpPosition,
|
|
@@ -645,9 +653,9 @@ class Market {
|
|
|
645
653
|
.remainingAccounts(this.cpiAccounts.getPositionState)
|
|
646
654
|
.instruction();
|
|
647
655
|
}
|
|
648
|
-
async ixWrapperCollectInterest({ claimer, tokenSyDst }) {
|
|
656
|
+
async ixWrapperCollectInterest({ claimer, tokenSyDst: tokenSyDstParam, }) {
|
|
649
657
|
const yieldPosition = this.xponPda.yieldPosition({ owner: claimer, vault: this.vault.selfAddress });
|
|
650
|
-
tokenSyDst =
|
|
658
|
+
const tokenSyDst = tokenSyDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, claimer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
651
659
|
const tokenBaseClaimer = (0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, claimer, true, this.flavor.baseTokenProgram);
|
|
652
660
|
const tokenBaseClaimerAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(claimer, tokenBaseClaimer, claimer, this.flavor.mintBase);
|
|
653
661
|
const tokenSyClaimer = (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, claimer, true);
|
|
@@ -689,11 +697,11 @@ class Market {
|
|
|
689
697
|
setupIxs: [tokenBaseClaimerAtaIx, tokenSyClaimerAtaIx],
|
|
690
698
|
};
|
|
691
699
|
}
|
|
692
|
-
async ixWrapperBuyPt({ owner, ptOut, maxBaseIn, tokenSyTrader, tokenPtTrader, tokenBaseTrader, }) {
|
|
693
|
-
tokenSyTrader =
|
|
694
|
-
tokenPtTrader =
|
|
695
|
-
tokenBaseTrader =
|
|
696
|
-
|
|
700
|
+
async ixWrapperBuyPt({ owner, ptOut, maxBaseIn, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenBaseTrader: tokenBaseTraderParam, }) {
|
|
701
|
+
const tokenSyTrader = tokenSyTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
702
|
+
const tokenPtTrader = tokenPtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
703
|
+
const tokenBaseTrader = tokenBaseTraderParam ||
|
|
704
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
697
705
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
698
706
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
699
707
|
const tokenBaseTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenBaseTrader, owner, this.flavor.mintBase);
|
|
@@ -704,7 +712,7 @@ class Market {
|
|
|
704
712
|
depositorSyTokenAccount: tokenSyTrader,
|
|
705
713
|
});
|
|
706
714
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
707
|
-
console.log("mintSyRemAccounts", mintSyRemAccounts)
|
|
715
|
+
// console.log("mintSyRemAccounts", mintSyRemAccounts)
|
|
708
716
|
mintSyRemAccounts.push({
|
|
709
717
|
pubkey: this.coreProgram.programId,
|
|
710
718
|
isWritable: false,
|
|
@@ -716,7 +724,7 @@ class Market {
|
|
|
716
724
|
// ...this.cpiAccounts.withdrawSy,
|
|
717
725
|
]);
|
|
718
726
|
const ix = await this.coreProgram.methods
|
|
719
|
-
.wrapperBuyPt(new
|
|
727
|
+
.wrapperBuyPt(new anchor_1.BN(ptOut.toString()), new anchor_1.BN(maxBaseIn.toString()), mintSyRemAccounts.length - 1)
|
|
720
728
|
.accountsStrict({
|
|
721
729
|
addressLookupTable: this.addressLookupTable,
|
|
722
730
|
buyer: owner,
|
|
@@ -738,11 +746,11 @@ class Market {
|
|
|
738
746
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenBaseTraderAtaIx],
|
|
739
747
|
};
|
|
740
748
|
}
|
|
741
|
-
async ixWrapperSellPt({ owner, amount, minBaseOut, tokenSyTrader, tokenPtTrader, tokenBaseTrader, }) {
|
|
742
|
-
tokenSyTrader =
|
|
743
|
-
tokenPtTrader =
|
|
744
|
-
tokenBaseTrader =
|
|
745
|
-
|
|
749
|
+
async ixWrapperSellPt({ owner, amount, minBaseOut, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenBaseTrader: tokenBaseTraderParam, }) {
|
|
750
|
+
const tokenSyTrader = tokenSyTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
751
|
+
const tokenPtTrader = tokenPtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
752
|
+
const tokenBaseTrader = tokenBaseTraderParam ||
|
|
753
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
746
754
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
747
755
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
748
756
|
const tokenBaseTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenBaseTrader, owner, this.flavor.mintBase);
|
|
@@ -755,7 +763,7 @@ class Market {
|
|
|
755
763
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
756
764
|
const remainingAccounts = (0, utils_1.uniqueRemainingAccounts)([...this.cpiAccounts.getSyState, ...this.cpiAccounts.withdrawSy]);
|
|
757
765
|
const ix = await this.coreProgram.methods
|
|
758
|
-
.wrapperSellPt(new
|
|
766
|
+
.wrapperSellPt(new anchor_1.BN(amount.toString()), new anchor_1.BN(minBaseOut.toString()), redeemSyRemAccounts.length)
|
|
759
767
|
.accountsStrict({
|
|
760
768
|
seller: owner,
|
|
761
769
|
market: this.selfAddress,
|
|
@@ -777,12 +785,12 @@ class Market {
|
|
|
777
785
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenBaseTraderAtaIx],
|
|
778
786
|
};
|
|
779
787
|
}
|
|
780
|
-
async ixWrapperBuyYt({ owner, ytOut, maxBaseIn, tokenSyTrader, tokenPtTrader, tokenYtTrader, tokenBaseTrader, }) {
|
|
781
|
-
tokenSyTrader =
|
|
782
|
-
tokenPtTrader =
|
|
783
|
-
tokenYtTrader =
|
|
784
|
-
tokenBaseTrader =
|
|
785
|
-
|
|
788
|
+
async ixWrapperBuyYt({ owner, ytOut, maxBaseIn, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenYtTrader: tokenYtTraderParam, tokenBaseTrader: tokenBaseTraderParam, }) {
|
|
789
|
+
const tokenSyTrader = tokenSyTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
790
|
+
const tokenPtTrader = tokenPtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
791
|
+
const tokenYtTrader = tokenYtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
792
|
+
const tokenBaseTrader = tokenBaseTraderParam ||
|
|
793
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
786
794
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
787
795
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
788
796
|
const tokenYtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtTrader, owner, this.mintYt);
|
|
@@ -802,7 +810,7 @@ class Market {
|
|
|
802
810
|
]);
|
|
803
811
|
const allRemainingAccounts = mintSyRemAccounts.concat(remainingAccounts);
|
|
804
812
|
const ix1 = await this.coreProgram.methods
|
|
805
|
-
.wrapperBuyYt(new
|
|
813
|
+
.wrapperBuyYt(new anchor_1.BN(ytOut.toString()), new anchor_1.BN(maxBaseIn.toString()), mintSyRemAccounts.length)
|
|
806
814
|
.accountsStrict({
|
|
807
815
|
buyer: owner,
|
|
808
816
|
market: this.selfAddress,
|
|
@@ -831,7 +839,7 @@ class Market {
|
|
|
831
839
|
.remainingAccounts(allRemainingAccounts)
|
|
832
840
|
.instruction();
|
|
833
841
|
const ix2 = await this.coreProgram.methods
|
|
834
|
-
.depositYt(new
|
|
842
|
+
.depositYt(new anchor_1.BN(ytOut.toString()))
|
|
835
843
|
.accountsStrict({
|
|
836
844
|
depositor: owner,
|
|
837
845
|
vault: this.vault.selfAddress,
|
|
@@ -858,12 +866,12 @@ class Market {
|
|
|
858
866
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenYtTraderAtaIx],
|
|
859
867
|
};
|
|
860
868
|
}
|
|
861
|
-
async ixWrapperSellYt({ owner, amount, minBaseOut, tokenBaseTrader, tokenSyTrader, tokenYtTrader, tokenPtTrader, }) {
|
|
862
|
-
tokenBaseTrader =
|
|
863
|
-
|
|
864
|
-
tokenSyTrader =
|
|
865
|
-
tokenYtTrader =
|
|
866
|
-
tokenPtTrader =
|
|
869
|
+
async ixWrapperSellYt({ owner, amount, minBaseOut, tokenBaseTrader: tokenBaseTraderParam, tokenSyTrader: tokenSyTraderParam, tokenYtTrader: tokenYtTraderParam, tokenPtTrader: tokenPtTraderParam, }) {
|
|
870
|
+
const tokenBaseTrader = tokenBaseTraderParam ||
|
|
871
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
872
|
+
const tokenSyTrader = tokenSyTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
873
|
+
const tokenYtTrader = tokenYtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
874
|
+
const tokenPtTrader = tokenPtTraderParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
867
875
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
868
876
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
869
877
|
const tokenYtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtTrader, owner, this.mintYt);
|
|
@@ -880,14 +888,14 @@ class Market {
|
|
|
880
888
|
...this.cpiAccounts.withdrawSy,
|
|
881
889
|
...this.vault.cpiAccounts.depositSy,
|
|
882
890
|
]);
|
|
883
|
-
console.log(" remaining accounts length", remainingAccounts.length)
|
|
891
|
+
// console.log(" remaining accounts length", remainingAccounts.length)
|
|
884
892
|
// remainingAccounts.push({
|
|
885
893
|
// pubkey: this.coreProgram.programId,
|
|
886
894
|
// isWritable: false,
|
|
887
895
|
// isSigner: false,
|
|
888
896
|
// })
|
|
889
897
|
const ix1 = await this.coreProgram.methods
|
|
890
|
-
.withdrawYt(new
|
|
898
|
+
.withdrawYt(new anchor_1.BN(amount.toString()))
|
|
891
899
|
.accountsStrict({
|
|
892
900
|
ytDst: tokenYtTrader,
|
|
893
901
|
escrowYt: this.vault.escrowYt,
|
|
@@ -906,7 +914,7 @@ class Market {
|
|
|
906
914
|
.remainingAccounts(remainingAccounts)
|
|
907
915
|
.instruction();
|
|
908
916
|
const ix2 = await this.coreProgram.methods
|
|
909
|
-
.wrapperSellYt(new
|
|
917
|
+
.wrapperSellYt(new anchor_1.BN(amount.toString()), new anchor_1.BN(minBaseOut.toString()), redeemSyRemAccounts.length)
|
|
910
918
|
.accountsStrict({
|
|
911
919
|
seller: owner,
|
|
912
920
|
market: this.selfAddress,
|
|
@@ -967,20 +975,19 @@ class Market {
|
|
|
967
975
|
};
|
|
968
976
|
}
|
|
969
977
|
/** Provide liquidity from a base asset - and receive YT and LP tokens in return */
|
|
970
|
-
async ixProvideLiquidityNoPriceImpact({ depositor, amountBase, minLpOut, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
971
|
-
tokenSyDepositor =
|
|
972
|
-
tokenYtDepositor =
|
|
973
|
-
tokenPtDepositor =
|
|
974
|
-
tokenBaseDepositor =
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
tokenLpDepositor = tokenLpDepositor || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
978
|
+
async ixProvideLiquidityNoPriceImpact({ depositor, amountBase, minLpOut, tokenSyDepositor: tokenSyDepositorParam, tokenYtDepositor: tokenYtDepositorParam, tokenPtDepositor: tokenPtDepositorParam, tokenBaseDepositor: tokenBaseDepositorParam, tokenLpDepositor: tokenLpDepositorParam, }) {
|
|
979
|
+
const tokenSyDepositor = tokenSyDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
980
|
+
const tokenYtDepositor = tokenYtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
981
|
+
const tokenPtDepositor = tokenPtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
982
|
+
const tokenBaseDepositor = tokenBaseDepositorParam ||
|
|
983
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, depositor, true, this.flavor.baseTokenProgram);
|
|
984
|
+
const tokenLpDepositor = tokenLpDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
978
985
|
const tokenSyDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
979
986
|
const tokenYtDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
980
987
|
const tokenPtDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
981
988
|
const tokenLpDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenLpDepositor, depositor, this.mintLp);
|
|
982
|
-
const amountBaseBn = new
|
|
983
|
-
const minLpOutBn = new
|
|
989
|
+
const amountBaseBn = new anchor_1.BN(amountBase.toString());
|
|
990
|
+
const minLpOutBn = new anchor_1.BN(minLpOut.toString());
|
|
984
991
|
// TODO - fix this
|
|
985
992
|
const mintSyIx = await this.flavor.ixMintSy({
|
|
986
993
|
// argument does not matter - since we are just getting the keys
|
|
@@ -990,22 +997,22 @@ class Market {
|
|
|
990
997
|
depositorSyTokenAccount: tokenSyDepositor,
|
|
991
998
|
});
|
|
992
999
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
993
|
-
// Log vault accounts before filtering
|
|
994
1000
|
const beforeVaultAccounts = [...this.vault.cpiAccounts.getSyState, ...this.vault.cpiAccounts.depositSy];
|
|
995
|
-
|
|
1001
|
+
// Log vault accounts before filtering
|
|
1002
|
+
// console.log("Before filtering vault accounts:", beforeVaultAccounts.length, "accounts")
|
|
996
1003
|
// Filter out TOKEN_PROGRAM_ID and SystemProgram.programId from vault remaining accounts
|
|
997
1004
|
const vaultCpiRemainingAccounts = beforeVaultAccounts.filter((account) => account.pubkey.toBase58() !== spl_token_1.TOKEN_PROGRAM_ID.toBase58());
|
|
998
1005
|
// Log vault accounts after filtering
|
|
999
|
-
console.log("After filtering vault accounts:", vaultCpiRemainingAccounts.length, "accounts")
|
|
1006
|
+
// console.log("After filtering vault accounts:", vaultCpiRemainingAccounts.length, "accounts")
|
|
1000
1007
|
// Log market accounts before filtering
|
|
1001
1008
|
const beforeMarketAccounts = [...this.cpiAccounts.depositSy];
|
|
1002
|
-
console.log("Before filtering market accounts:", beforeMarketAccounts.length, "accounts")
|
|
1009
|
+
// console.log("Before filtering market accounts:", beforeMarketAccounts.length, "accounts")
|
|
1003
1010
|
// Filter out TOKEN_PROGRAM_ID and SystemProgram.programId from market remaining accounts
|
|
1004
1011
|
const marketCpiRemainingAccounts = beforeMarketAccounts.filter((account) => account.pubkey.toBase58() !== spl_token_1.TOKEN_PROGRAM_ID.toBase58() &&
|
|
1005
1012
|
account.pubkey.toBase58() !== anchor_1.web3.SystemProgram.programId.toBase58() &&
|
|
1006
1013
|
account.pubkey.toBase58() !== this.selfAddress.toBase58());
|
|
1007
1014
|
// Log market accounts after filtering
|
|
1008
|
-
console.log("After filtering market accounts:", marketCpiRemainingAccounts.length, "accounts")
|
|
1015
|
+
// console.log("After filtering market accounts:", marketCpiRemainingAccounts.length, "accounts")
|
|
1009
1016
|
// These remaining accounts can be in any order, and they can be unique-ified
|
|
1010
1017
|
const unorderedRemainingAccounts = (0, utils_1.uniqueRemainingAccounts)([
|
|
1011
1018
|
...vaultCpiRemainingAccounts,
|
|
@@ -1014,7 +1021,7 @@ class Market {
|
|
|
1014
1021
|
const allRemainingAccounts = [...mintSyRemAccounts, ...unorderedRemainingAccounts];
|
|
1015
1022
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner: depositor });
|
|
1016
1023
|
const ix = await this.coreProgram.methods
|
|
1017
|
-
.wrapperProvideLiquidity(amountBaseBn, minLpOutBn, mintSyRemAccounts.length
|
|
1024
|
+
.wrapperProvideLiquidity(amountBaseBn, minLpOutBn, mintSyRemAccounts.length)
|
|
1018
1025
|
.accountsStrict({
|
|
1019
1026
|
depositor,
|
|
1020
1027
|
authority: this.vault.authority,
|
|
@@ -1045,7 +1052,7 @@ class Market {
|
|
|
1045
1052
|
})
|
|
1046
1053
|
.remainingAccounts(allRemainingAccounts)
|
|
1047
1054
|
.instruction();
|
|
1048
|
-
console.log("ix accounts length", ix.keys.length)
|
|
1055
|
+
// console.log("ix accounts length", ix.keys.length)
|
|
1049
1056
|
return {
|
|
1050
1057
|
ixs: [
|
|
1051
1058
|
...(await this.flavor.preIxs({ signer: depositor })),
|
|
@@ -1055,14 +1062,13 @@ class Market {
|
|
|
1055
1062
|
setupIxs: [tokenSyDepositorAtaIx, tokenYtDepositorAtaIx, tokenPtDepositorAtaIx, tokenLpDepositorAtaIx],
|
|
1056
1063
|
};
|
|
1057
1064
|
}
|
|
1058
|
-
async ixProvideLiquidityBase({ depositor, amountBase, minLpOut, externalPtToBuy, externalSyConstraint, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
1059
|
-
tokenSyDepositor =
|
|
1060
|
-
tokenYtDepositor =
|
|
1061
|
-
tokenPtDepositor =
|
|
1062
|
-
tokenBaseDepositor =
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
tokenLpDepositor = tokenLpDepositor || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1065
|
+
async ixProvideLiquidityBase({ depositor, amountBase, minLpOut, externalPtToBuy, externalSyConstraint, tokenSyDepositor: tokenSyDepositorParam, tokenYtDepositor: tokenYtDepositorParam, tokenPtDepositor: tokenPtDepositorParam, tokenBaseDepositor: tokenBaseDepositorParam, tokenLpDepositor: tokenLpDepositorParam, }) {
|
|
1066
|
+
const tokenSyDepositor = tokenSyDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1067
|
+
const tokenYtDepositor = tokenYtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1068
|
+
const tokenPtDepositor = tokenPtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1069
|
+
const tokenBaseDepositor = tokenBaseDepositorParam ||
|
|
1070
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, depositor, true, this.flavor.baseTokenProgram);
|
|
1071
|
+
const tokenLpDepositor = tokenLpDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1066
1072
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
1067
1073
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
1068
1074
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
@@ -1081,7 +1087,7 @@ class Market {
|
|
|
1081
1087
|
});
|
|
1082
1088
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
1083
1089
|
const ix = await this.coreProgram.methods
|
|
1084
|
-
.wrapperProvideLiquidityBase(new
|
|
1090
|
+
.wrapperProvideLiquidityBase(new anchor_1.BN(amountBase.toString()), new anchor_1.BN(minLpOut.toString()), mintSyRemAccounts.length, new anchor_1.BN(externalPtToBuy.toString()), new anchor_1.BN(externalSyConstraint.toString()))
|
|
1085
1091
|
.accountsStrict({
|
|
1086
1092
|
depositor,
|
|
1087
1093
|
lpPosition,
|
|
@@ -1112,14 +1118,13 @@ class Market {
|
|
|
1112
1118
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1113
1119
|
};
|
|
1114
1120
|
}
|
|
1115
|
-
async ixProvideLiquidityClassic({ depositor, amountBase, amountPt, minLpOut, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
1116
|
-
tokenSyDepositor =
|
|
1117
|
-
tokenYtDepositor =
|
|
1118
|
-
tokenPtDepositor =
|
|
1119
|
-
tokenBaseDepositor =
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
tokenLpDepositor = tokenLpDepositor || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1121
|
+
async ixProvideLiquidityClassic({ depositor, amountBase, amountPt, minLpOut, tokenSyDepositor: tokenSyDepositorParam, tokenYtDepositor: tokenYtDepositorParam, tokenPtDepositor: tokenPtDepositorParam, tokenBaseDepositor: tokenBaseDepositorParam, tokenLpDepositor: tokenLpDepositorParam, }) {
|
|
1122
|
+
const tokenSyDepositor = tokenSyDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1123
|
+
const tokenYtDepositor = tokenYtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1124
|
+
const tokenPtDepositor = tokenPtDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1125
|
+
const tokenBaseDepositor = tokenBaseDepositorParam ||
|
|
1126
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, depositor, true, this.flavor.baseTokenProgram);
|
|
1127
|
+
const tokenLpDepositor = tokenLpDepositorParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1123
1128
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
1124
1129
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
1125
1130
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
@@ -1137,7 +1142,7 @@ class Market {
|
|
|
1137
1142
|
});
|
|
1138
1143
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
1139
1144
|
const ix = await this.coreProgram.methods
|
|
1140
|
-
.wrapperProvideLiquidityClassic(new
|
|
1145
|
+
.wrapperProvideLiquidityClassic(new anchor_1.BN(amountBase.toString()), new anchor_1.BN(amountPt.toString()), new anchor_1.BN(minLpOut.toString()), mintSyRemAccounts.length)
|
|
1141
1146
|
.accountsStrict({
|
|
1142
1147
|
depositor,
|
|
1143
1148
|
lpPosition,
|
|
@@ -1167,14 +1172,13 @@ class Market {
|
|
|
1167
1172
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenLpAtaIx],
|
|
1168
1173
|
};
|
|
1169
1174
|
}
|
|
1170
|
-
async ixWithdrawLiquidityToBase({ owner, amountLp, minBaseOut, tokenSyWithdrawer, tokenYtWithdrawer, tokenPtWithdrawer, tokenBaseWithdrawer, tokenLpWithdrawer, }) {
|
|
1171
|
-
tokenSyWithdrawer =
|
|
1172
|
-
tokenYtWithdrawer =
|
|
1173
|
-
tokenPtWithdrawer =
|
|
1174
|
-
tokenBaseWithdrawer =
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
tokenLpWithdrawer = tokenLpWithdrawer || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1175
|
+
async ixWithdrawLiquidityToBase({ owner, amountLp, minBaseOut, tokenSyWithdrawer: tokenSyWithdrawerParam, tokenYtWithdrawer: tokenYtWithdrawerParam, tokenPtWithdrawer: tokenPtWithdrawerParam, tokenBaseWithdrawer: tokenBaseWithdrawerParam, tokenLpWithdrawer: tokenLpWithdrawerParam, }) {
|
|
1176
|
+
const tokenSyWithdrawer = tokenSyWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1177
|
+
const tokenYtWithdrawer = tokenYtWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1178
|
+
const tokenPtWithdrawer = tokenPtWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1179
|
+
const tokenBaseWithdrawer = tokenBaseWithdrawerParam ||
|
|
1180
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
1181
|
+
const tokenLpWithdrawer = tokenLpWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1178
1182
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyWithdrawer, owner, this.mintSy);
|
|
1179
1183
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtWithdrawer, owner, this.mintYt);
|
|
1180
1184
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtWithdrawer, owner, this.mintPt);
|
|
@@ -1194,7 +1198,7 @@ class Market {
|
|
|
1194
1198
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
1195
1199
|
const minSyOut = Number(minBaseOut) / this.currentSyExchangeRate;
|
|
1196
1200
|
const ix = await this.coreProgram.methods
|
|
1197
|
-
.wrapperWithdrawLiquidity(new
|
|
1201
|
+
.wrapperWithdrawLiquidity(new anchor_1.BN(amountLp.toString()), new anchor_1.BN(minSyOut.toFixed(0).toString()), redeemSyRemAccounts.length)
|
|
1198
1202
|
.accountsStrict({
|
|
1199
1203
|
market: this.selfAddress,
|
|
1200
1204
|
tokenPtEscrow: this.tokenPtEscrow,
|
|
@@ -1221,14 +1225,13 @@ class Market {
|
|
|
1221
1225
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1222
1226
|
};
|
|
1223
1227
|
}
|
|
1224
|
-
async ixWithdrawLiquidityClassic({ owner, amountLp,
|
|
1225
|
-
tokenSyWithdrawer =
|
|
1226
|
-
tokenYtWithdrawer =
|
|
1227
|
-
tokenPtWithdrawer =
|
|
1228
|
-
tokenBaseWithdrawer =
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
tokenLpWithdrawer = tokenLpWithdrawer || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1228
|
+
async ixWithdrawLiquidityClassic({ owner, amountLp, tokenSyWithdrawer: tokenSyWithdrawerParam, tokenYtWithdrawer: tokenYtWithdrawerParam, tokenPtWithdrawer: tokenPtWithdrawerParam, tokenBaseWithdrawer: tokenBaseWithdrawerParam, tokenLpWithdrawer: tokenLpWithdrawerParam, }) {
|
|
1229
|
+
const tokenSyWithdrawer = tokenSyWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1230
|
+
const tokenYtWithdrawer = tokenYtWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintYt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1231
|
+
const tokenPtWithdrawer = tokenPtWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintPt, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1232
|
+
const tokenBaseWithdrawer = tokenBaseWithdrawerParam ||
|
|
1233
|
+
(0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, owner, true, this.flavor.baseTokenProgram);
|
|
1234
|
+
const tokenLpWithdrawer = tokenLpWithdrawerParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintLp, owner, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
1232
1235
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyWithdrawer, owner, this.mintSy);
|
|
1233
1236
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtWithdrawer, owner, this.mintYt);
|
|
1234
1237
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtWithdrawer, owner, this.mintPt);
|
|
@@ -1247,7 +1250,7 @@ class Market {
|
|
|
1247
1250
|
});
|
|
1248
1251
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
1249
1252
|
const ixn = await this.coreProgram.methods
|
|
1250
|
-
.wrapperWithdrawLiquidityClassic(new
|
|
1253
|
+
.wrapperWithdrawLiquidityClassic(new anchor_1.BN(amountLp.toString()), redeemSyRemAccounts.length)
|
|
1251
1254
|
.accountsStrict({
|
|
1252
1255
|
market: this.selfAddress,
|
|
1253
1256
|
tokenPtEscrow: this.tokenPtEscrow,
|
|
@@ -1273,8 +1276,8 @@ class Market {
|
|
|
1273
1276
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1274
1277
|
};
|
|
1275
1278
|
}
|
|
1276
|
-
async claimFarmEmissions({ owner, mint, tokenProgram, tokenDst, }) {
|
|
1277
|
-
tokenDst =
|
|
1279
|
+
async claimFarmEmissions({ owner, mint, tokenProgram, tokenDst: tokenDstParam, }) {
|
|
1280
|
+
const tokenDst = tokenDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(mint, owner, true, tokenProgram);
|
|
1278
1281
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
1279
1282
|
const tokenFarm = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, this.selfAddress, true, tokenProgram);
|
|
1280
1283
|
const tokenAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenDst, owner, mint);
|
|
@@ -1318,12 +1321,12 @@ class Market {
|
|
|
1318
1321
|
addMarketEmissionIx: ix,
|
|
1319
1322
|
};
|
|
1320
1323
|
}
|
|
1321
|
-
async addFarm({ signer, farmMint, farmRewardTokenProgram, emissionsRate, untilTimestamp, farmRewardSrc, feePayer, }) {
|
|
1322
|
-
feePayer =
|
|
1324
|
+
async addFarm({ signer, farmMint, farmRewardTokenProgram, emissionsRate, untilTimestamp, farmRewardSrc: farmRewardSrcParam, feePayer: feePayerParam, }) {
|
|
1325
|
+
const feePayer = feePayerParam || signer;
|
|
1323
1326
|
const farmRewardEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, this.selfAddress, true, farmRewardTokenProgram);
|
|
1324
|
-
farmRewardSrc =
|
|
1327
|
+
const farmRewardSrc = farmRewardSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, signer, true, farmRewardTokenProgram);
|
|
1325
1328
|
const ix = await this.coreProgram.methods
|
|
1326
|
-
.addFarm(new
|
|
1329
|
+
.addFarm(new anchor_1.BN(emissionsRate), untilTimestamp)
|
|
1327
1330
|
.accountsStrict({
|
|
1328
1331
|
adminState: (0, utils_1.getExponentAdminStatePda)(),
|
|
1329
1332
|
market: this.selfAddress,
|
|
@@ -1341,20 +1344,20 @@ class Market {
|
|
|
1341
1344
|
};
|
|
1342
1345
|
}
|
|
1343
1346
|
/** Calculate available liquidity for PT trades
|
|
1344
|
-
* @param
|
|
1345
|
-
* @param
|
|
1347
|
+
* @param isBuy - true if buying PT with SY, false if selling PT for SY
|
|
1348
|
+
* @param sizePt - amount of PT to trade (in PT decimals)
|
|
1346
1349
|
* @returns amount of PT that can be traded given current liquidity
|
|
1347
1350
|
*/
|
|
1348
|
-
liquidityAvailable(
|
|
1351
|
+
liquidityAvailable(isBuy, sizePt) {
|
|
1349
1352
|
const calc = this.marketCalculator();
|
|
1350
|
-
if (
|
|
1353
|
+
if (isBuy) {
|
|
1351
1354
|
// When buying PT, we're limited by SY liquidity
|
|
1352
1355
|
// Convert PT amount to SY using current price
|
|
1353
|
-
const syNeeded = Number(
|
|
1356
|
+
const syNeeded = Number(sizePt) * calc.exchangeRate;
|
|
1354
1357
|
// Available SY in the market
|
|
1355
1358
|
const syAvailable = Number(this.syBalance);
|
|
1356
1359
|
if (syNeeded <= syAvailable) {
|
|
1357
|
-
return
|
|
1360
|
+
return sizePt;
|
|
1358
1361
|
}
|
|
1359
1362
|
else {
|
|
1360
1363
|
// Calculate max PT that can be bought with available SY
|
|
@@ -1364,8 +1367,8 @@ class Market {
|
|
|
1364
1367
|
else {
|
|
1365
1368
|
// When selling PT, we're limited by PT liquidity in the market
|
|
1366
1369
|
const ptAvailable = this.ptBalance;
|
|
1367
|
-
if (
|
|
1368
|
-
return
|
|
1370
|
+
if (sizePt <= ptAvailable) {
|
|
1371
|
+
return sizePt;
|
|
1369
1372
|
}
|
|
1370
1373
|
else {
|
|
1371
1374
|
return ptAvailable;
|
|
@@ -1374,58 +1377,59 @@ class Market {
|
|
|
1374
1377
|
}
|
|
1375
1378
|
}
|
|
1376
1379
|
exports.Market = Market;
|
|
1377
|
-
function toJson(
|
|
1378
|
-
const
|
|
1380
|
+
function toJson(market) {
|
|
1381
|
+
const marketCalculator = market.marketCalculator();
|
|
1379
1382
|
return {
|
|
1380
|
-
treasurySyTokenAccount:
|
|
1381
|
-
address:
|
|
1382
|
-
addressLookupTable:
|
|
1383
|
-
tokenSyEscrow:
|
|
1384
|
-
tokenPtEscrow:
|
|
1385
|
-
tokenLpEscrow:
|
|
1386
|
-
lpSupply:
|
|
1387
|
-
syProgram:
|
|
1388
|
-
mintPt:
|
|
1389
|
-
mintSy:
|
|
1390
|
-
mintLp:
|
|
1391
|
-
feeTreasurySyBps:
|
|
1392
|
-
ptBalance:
|
|
1393
|
-
syBalance:
|
|
1394
|
-
currentSyRate:
|
|
1395
|
-
expirationTs:
|
|
1396
|
-
expirationDate: new Date(
|
|
1397
|
-
lnFeeRateRoot:
|
|
1398
|
-
rateScalarRoot:
|
|
1399
|
-
lastLnImpliedRate:
|
|
1400
|
-
currentPtPriceInSy:
|
|
1401
|
-
currentPtPriceInAsset:
|
|
1402
|
-
secondsRemaining:
|
|
1403
|
-
proportionPtInAsset:
|
|
1404
|
-
proportionPtInSy:
|
|
1405
|
-
currentFeeRate:
|
|
1406
|
-
currentRateScalar:
|
|
1407
|
-
currentRateAnchor:
|
|
1408
|
-
cpiAccounts: (0, exponent_types_1.serializeCpiAccountsRaw)(
|
|
1383
|
+
treasurySyTokenAccount: market.state.tokenFeeTreasurySy.toBase58(),
|
|
1384
|
+
address: market.selfAddress.toBase58(),
|
|
1385
|
+
addressLookupTable: market.addressLookupTable.toBase58(),
|
|
1386
|
+
tokenSyEscrow: market.tokenSyEscrow.toBase58(),
|
|
1387
|
+
tokenPtEscrow: market.tokenPtEscrow.toBase58(),
|
|
1388
|
+
tokenLpEscrow: market.tokenLpEscrow.toBase58(),
|
|
1389
|
+
lpSupply: market.state.lpSupply.toString(),
|
|
1390
|
+
syProgram: market.state.syProgram.toBase58(),
|
|
1391
|
+
mintPt: market.state.mintPt.toBase58(),
|
|
1392
|
+
mintSy: market.state.mintSy.toBase58(),
|
|
1393
|
+
mintLp: market.state.mintLp.toBase58(),
|
|
1394
|
+
feeTreasurySyBps: market.state.feeTreasurySyBps,
|
|
1395
|
+
ptBalance: market.state.ptBalance.toString(),
|
|
1396
|
+
syBalance: market.state.syBalance.toString(),
|
|
1397
|
+
currentSyRate: market.flavor.currentSyExchangeRate,
|
|
1398
|
+
expirationTs: market.state.expirationTs,
|
|
1399
|
+
expirationDate: new Date(market.state.expirationTs * 1000).toISOString(),
|
|
1400
|
+
lnFeeRateRoot: market.state.lnFeeRateRoot,
|
|
1401
|
+
rateScalarRoot: market.state.rateScalarRoot,
|
|
1402
|
+
lastLnImpliedRate: market.state.lastLnImpliedRate,
|
|
1403
|
+
currentPtPriceInSy: market.currentPtPriceInSy,
|
|
1404
|
+
currentPtPriceInAsset: market.currentPtPriceInAsset,
|
|
1405
|
+
secondsRemaining: market.secondsRemaining,
|
|
1406
|
+
proportionPtInAsset: marketCalculator.proportionPtInAsset,
|
|
1407
|
+
proportionPtInSy: marketCalculator.proportionPtInSy,
|
|
1408
|
+
currentFeeRate: marketCalculator.feeRate,
|
|
1409
|
+
currentRateScalar: marketCalculator.rateScalar,
|
|
1410
|
+
currentRateAnchor: marketCalculator.findRateAnchor(),
|
|
1411
|
+
cpiAccounts: (0, exponent_types_1.serializeCpiAccountsRaw)(market.cpiAccounts),
|
|
1409
1412
|
emissions: {
|
|
1410
|
-
trackers:
|
|
1413
|
+
trackers: market.marketEmissions.trackers.map((e) => ({
|
|
1411
1414
|
tokenEscrow: e.tokenEscrow.toBase58(),
|
|
1412
1415
|
lpShareIndex: e.lpShareIndex,
|
|
1413
1416
|
lastSeenStaged: e.lastSeenStaged,
|
|
1414
1417
|
})),
|
|
1415
1418
|
},
|
|
1416
|
-
ptApr:
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
+
ptApr: market.ptApr,
|
|
1420
|
+
ptApy: market.ptApy,
|
|
1421
|
+
lpEscrowAmount: market.state.lpEscrowAmount.toString(),
|
|
1422
|
+
maxLpSupply: market.state.maxLpSupply.toString(),
|
|
1419
1423
|
liquidityNetBalanceLimits: {
|
|
1420
|
-
windowStartTimestamp:
|
|
1421
|
-
windowStartNetBalance:
|
|
1422
|
-
maxNetBalanceChangeNegativePercentage:
|
|
1423
|
-
maxNetBalanceChangePositivePercentage:
|
|
1424
|
-
windowDurationSeconds:
|
|
1424
|
+
windowStartTimestamp: market.state.liquidityNetBalanceLimits.windowStartTimestamp,
|
|
1425
|
+
windowStartNetBalance: market.state.liquidityNetBalanceLimits.windowStartNetBalance.toString(),
|
|
1426
|
+
maxNetBalanceChangeNegativePercentage: market.state.liquidityNetBalanceLimits.maxNetBalanceChangeNegativePercentage,
|
|
1427
|
+
maxNetBalanceChangePositivePercentage: market.state.liquidityNetBalanceLimits.maxNetBalanceChangePositivePercentage,
|
|
1428
|
+
windowDurationSeconds: market.state.liquidityNetBalanceLimits.windowDurationSeconds,
|
|
1425
1429
|
},
|
|
1426
1430
|
lpFarm: {
|
|
1427
|
-
lastSeenTimestamp:
|
|
1428
|
-
farmEmissions:
|
|
1431
|
+
lastSeenTimestamp: market.state.lpFarm.lastSeenTimestamp,
|
|
1432
|
+
farmEmissions: market.state.lpFarm.farmEmissions.map((e) => ({
|
|
1429
1433
|
mint: e.mint.toBase58(),
|
|
1430
1434
|
tokenRate: e.tokenRate.toString(),
|
|
1431
1435
|
expiryTimestamp: e.expiryTimestamp,
|