@exponent-labs/exponent-sdk 0.0.10 → 0.1.1
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.map +1 -1
- package/build/events.d.ts +2 -2
- package/build/events.js +43 -49
- package/build/events.js.map +1 -1
- package/build/flavors.d.ts +3 -3
- package/build/flavors.js +19 -24
- package/build/flavors.js.map +1 -1
- package/build/lpPosition.d.ts +4 -4
- package/build/lpPosition.js +19 -19
- package/build/lpPosition.js.map +1 -1
- package/build/market.d.ts +31 -35
- package/build/market.js +202 -205
- package/build/market.js.map +1 -1
- package/build/syPosition.d.ts +2 -2
- package/build/syPosition.js +19 -16
- package/build/syPosition.js.map +1 -1
- package/build/tokenUtil.d.ts +2 -2
- package/build/tokenUtil.js +4 -4
- package/build/tokenUtil.js.map +1 -1
- package/build/utils/altUtil.d.ts +3 -3
- package/build/utils/altUtil.js +15 -9
- package/build/utils/altUtil.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.map +1 -1
- package/build/vault.d.ts +11 -11
- package/build/vault.js +69 -68
- package/build/vault.js.map +1 -1
- package/build/ytPosition.d.ts +7 -7
- package/build/ytPosition.js +33 -33
- package/build/ytPosition.js.map +1 -1
- package/package.json +22 -22
- package/src/addressLookupTableUtil.ts +2 -1
- package/src/events.ts +44 -44
- package/src/flavors.ts +33 -39
- package/src/lpPosition.ts +22 -21
- package/src/market.ts +296 -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 +40 -36
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,19 +249,19 @@ 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
262
|
}
|
|
263
|
-
static annualizeApy(
|
|
264
|
-
return (1 +
|
|
263
|
+
static annualizeApy(rate, secondsRemaining) {
|
|
264
|
+
return (1 + rate) ** (SECONDS_PER_YEAR / secondsRemaining) - 1;
|
|
265
265
|
}
|
|
266
266
|
/** Annualized PT fixed rate */
|
|
267
267
|
get ptApr() {
|
|
@@ -285,7 +285,7 @@ class Market {
|
|
|
285
285
|
get feeTreasuryRate() {
|
|
286
286
|
return this.feeTreasuryBps / 10_000;
|
|
287
287
|
}
|
|
288
|
-
/** Calculate
|
|
288
|
+
/** Calculate amount of LP tokens to expect for tokens in */
|
|
289
289
|
lpOutForTokensIn(syInIntent, ptInIntent) {
|
|
290
290
|
return (0, market_math_1.lpOutForTokensIn)({
|
|
291
291
|
syIntent: Number(syInIntent),
|
|
@@ -296,7 +296,8 @@ class Market {
|
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
298
|
marketCalculator() {
|
|
299
|
-
const
|
|
299
|
+
const timeNow = Date.now() / 1000;
|
|
300
|
+
const secondsRemaining = Math.max(0, Math.round(this.state.expirationTs - timeNow));
|
|
300
301
|
return new market_math_1.MarketCalculator({
|
|
301
302
|
liquiditySy: parseInt(this.syBalance.toString()),
|
|
302
303
|
liquidityPt: parseInt(this.ptBalance.toString()),
|
|
@@ -311,6 +312,7 @@ class Market {
|
|
|
311
312
|
windowStartTimestamp: this.state.liquidityNetBalanceLimits.windowStartTimestamp,
|
|
312
313
|
windowStartNetBalance: this.state.liquidityNetBalanceLimits.windowStartNetBalance.toNumber(),
|
|
313
314
|
windowDurationSeconds: this.state.liquidityNetBalanceLimits.windowDurationSeconds,
|
|
315
|
+
feeTreasurySyBps: this.state.feeTreasurySyBps,
|
|
314
316
|
});
|
|
315
317
|
}
|
|
316
318
|
/** Deposit a pair of tokens as liquidity to the market
|
|
@@ -321,14 +323,14 @@ class Market {
|
|
|
321
323
|
*
|
|
322
324
|
* The token accounts themselves are optional, and will be derived from the depositor's wallet if not provided
|
|
323
325
|
*/
|
|
324
|
-
async ixDepositLiquidity({ ptInIntent, syInIntent, minLpOut, depositor, ptSrc, sySrc, lpDst, }) {
|
|
326
|
+
async ixDepositLiquidity({ ptInIntent, syInIntent, minLpOut, depositor, ptSrc: ptSrcParam, sySrc: sySrcParam, lpDst: lpDstParam, }) {
|
|
325
327
|
const tokenProgram = spl_token_1.TOKEN_PROGRAM_ID;
|
|
326
|
-
sySrc =
|
|
327
|
-
ptSrc =
|
|
328
|
-
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);
|
|
329
331
|
const syRemAccounts = this.cpiAccounts.depositSy;
|
|
330
332
|
return this.coreProgram.methods
|
|
331
|
-
.marketTwoDepositLiquidity(new
|
|
333
|
+
.marketTwoDepositLiquidity(new anchor_1.BN(ptInIntent.toString()), new anchor_1.BN(syInIntent.toString()), new anchor_1.BN(minLpOut.toString()))
|
|
332
334
|
.accountsStrict({
|
|
333
335
|
depositor,
|
|
334
336
|
market: this.selfAddress,
|
|
@@ -358,11 +360,11 @@ class Market {
|
|
|
358
360
|
})
|
|
359
361
|
.instruction();
|
|
360
362
|
}
|
|
361
|
-
async ixModifyFarm({ newRate, untilTimestamp, signer, farmMint, farmTokenProgram, farmTokenSrc, }) {
|
|
362
|
-
farmTokenSrc =
|
|
363
|
+
async ixModifyFarm({ newRate, untilTimestamp, signer, farmMint, farmTokenProgram, farmTokenSrc: farmTokenSrcParam, }) {
|
|
364
|
+
const farmTokenSrc = farmTokenSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, signer, true, farmTokenProgram);
|
|
363
365
|
const tokenFarm = (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, this.selfAddress, true, farmTokenProgram);
|
|
364
366
|
return this.coreProgram.methods
|
|
365
|
-
.modifyFarm(untilTimestamp, new
|
|
367
|
+
.modifyFarm(untilTimestamp, new anchor_1.BN(newRate.toString()))
|
|
366
368
|
.accountsStrict({
|
|
367
369
|
adminState: (0, utils_1.getExponentAdminStatePda)(),
|
|
368
370
|
market: this.selfAddress,
|
|
@@ -383,16 +385,16 @@ class Market {
|
|
|
383
385
|
*
|
|
384
386
|
* The token accounts themselves are optional, and will be derived from the withdrawer's wallet if not provided
|
|
385
387
|
*/
|
|
386
|
-
async ixWithdrawLiquidity({ lpIn, withdrawer, minPtOut, minSyOut, ptDst, syDst, lpSrc, }) {
|
|
387
|
-
ptDst =
|
|
388
|
-
syDst =
|
|
389
|
-
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);
|
|
390
392
|
const ptDstAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, ptDst, withdrawer, this.mintPt);
|
|
391
393
|
const syDstAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, syDst, withdrawer, this.mintSy);
|
|
392
394
|
const lpSrcAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(withdrawer, lpSrc, withdrawer, this.mintLp);
|
|
393
395
|
const syRemAccounts = this.cpiAccounts.withdrawSy;
|
|
394
396
|
const ixs = await this.coreProgram.methods
|
|
395
|
-
.marketTwoWithdrawLiquidity(new
|
|
397
|
+
.marketTwoWithdrawLiquidity(new anchor_1.BN(lpIn.toString()), new anchor_1.BN(minPtOut.toString()), new anchor_1.BN(minSyOut.toString()))
|
|
396
398
|
.accountsStrict({
|
|
397
399
|
withdrawer,
|
|
398
400
|
market: this.selfAddress,
|
|
@@ -448,9 +450,9 @@ class Market {
|
|
|
448
450
|
tokenSy,
|
|
449
451
|
});
|
|
450
452
|
}
|
|
451
|
-
async ixTradePt({ trader, traderPt, syConstraint, isBuy, tokenPt, tokenSy, }) {
|
|
452
|
-
tokenPt =
|
|
453
|
-
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);
|
|
454
456
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, tokenSy, trader, this.mintSy);
|
|
455
457
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, tokenPt, trader, this.mintPt);
|
|
456
458
|
const remainingAccounts = [
|
|
@@ -458,8 +460,8 @@ class Market {
|
|
|
458
460
|
...this.cpiAccounts.depositSy,
|
|
459
461
|
...this.cpiAccounts.withdrawSy,
|
|
460
462
|
];
|
|
461
|
-
const netTradePtBN = new
|
|
462
|
-
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));
|
|
463
465
|
const ix = await this.coreProgram.methods
|
|
464
466
|
.tradePt(netTradePtBN, syConstraintBN)
|
|
465
467
|
.accountsStrict({
|
|
@@ -490,10 +492,10 @@ class Market {
|
|
|
490
492
|
*
|
|
491
493
|
* The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
|
|
492
494
|
*/
|
|
493
|
-
async ixSellYt({ trader, ytIn, minSyOut, ytSrc, ptSrc, syDst, }) {
|
|
494
|
-
syDst =
|
|
495
|
-
ptSrc =
|
|
496
|
-
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);
|
|
497
499
|
const syDstAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, syDst, trader, this.mintSy);
|
|
498
500
|
const ptSrcAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ptSrc, trader, this.mintPt);
|
|
499
501
|
const ytSrcAtaIxs = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ytSrc, trader, this.mintYt);
|
|
@@ -505,7 +507,7 @@ class Market {
|
|
|
505
507
|
]);
|
|
506
508
|
remainingAccounts.push({ pubkey: this.coreProgram.programId, isWritable: false, isSigner: false });
|
|
507
509
|
const ix = await this.coreProgram.methods
|
|
508
|
-
.sellYt(new
|
|
510
|
+
.sellYt(new anchor_1.BN(ytIn.toString()), new anchor_1.BN(minSyOut.toString()))
|
|
509
511
|
.accountsStrict({
|
|
510
512
|
trader,
|
|
511
513
|
market: this.selfAddress,
|
|
@@ -542,10 +544,10 @@ class Market {
|
|
|
542
544
|
*
|
|
543
545
|
* The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
|
|
544
546
|
*/
|
|
545
|
-
async ixBuyYt({ trader, ytOut, maxSyIn, ytTrader, ptTrader, syTrader, }) {
|
|
546
|
-
syTrader =
|
|
547
|
-
ptTrader =
|
|
548
|
-
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);
|
|
549
551
|
const syTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, syTrader, trader, this.mintSy);
|
|
550
552
|
const ptTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ptTrader, trader, this.mintPt);
|
|
551
553
|
const ytTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(trader, ytTrader, trader, this.mintYt);
|
|
@@ -563,7 +565,7 @@ class Market {
|
|
|
563
565
|
]);
|
|
564
566
|
remainingAccounts.push({ pubkey: this.coreProgram.programId, isWritable: false, isSigner: false });
|
|
565
567
|
const ix = await this.coreProgram.methods
|
|
566
|
-
.buyYt(new
|
|
568
|
+
.buyYt(new anchor_1.BN(maxSyIn.toString()), new anchor_1.BN(ytOut.toString()))
|
|
567
569
|
.accountsStrict({
|
|
568
570
|
trader,
|
|
569
571
|
market: this.selfAddress,
|
|
@@ -606,11 +608,11 @@ class Market {
|
|
|
606
608
|
.instruction();
|
|
607
609
|
}
|
|
608
610
|
/** Deposit LP tokens into the farming module to earn rewards */
|
|
609
|
-
async ixDepositLp({ owner, amount, lpSrc }) {
|
|
610
|
-
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);
|
|
611
613
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
612
614
|
return this.coreProgram.methods
|
|
613
|
-
.marketDepositLp(new
|
|
615
|
+
.marketDepositLp(new anchor_1.BN(amount.toString()))
|
|
614
616
|
.accountsStrict({
|
|
615
617
|
owner,
|
|
616
618
|
lpPosition,
|
|
@@ -629,11 +631,11 @@ class Market {
|
|
|
629
631
|
.instruction();
|
|
630
632
|
}
|
|
631
633
|
/** Withdraw LP tokens from the farming module */
|
|
632
|
-
async ixWithdrawLp({ owner, amount, lpDst }) {
|
|
633
|
-
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);
|
|
634
636
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
635
637
|
return this.coreProgram.methods
|
|
636
|
-
.marketWithdrawLp(new
|
|
638
|
+
.marketWithdrawLp(new anchor_1.BN(amount.toString()))
|
|
637
639
|
.accountsStrict({
|
|
638
640
|
owner,
|
|
639
641
|
lpPosition,
|
|
@@ -651,9 +653,9 @@ class Market {
|
|
|
651
653
|
.remainingAccounts(this.cpiAccounts.getPositionState)
|
|
652
654
|
.instruction();
|
|
653
655
|
}
|
|
654
|
-
async ixWrapperCollectInterest({ claimer, tokenSyDst }) {
|
|
656
|
+
async ixWrapperCollectInterest({ claimer, tokenSyDst: tokenSyDstParam, }) {
|
|
655
657
|
const yieldPosition = this.xponPda.yieldPosition({ owner: claimer, vault: this.vault.selfAddress });
|
|
656
|
-
tokenSyDst =
|
|
658
|
+
const tokenSyDst = tokenSyDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, claimer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
657
659
|
const tokenBaseClaimer = (0, spl_token_1.getAssociatedTokenAddressSync)(this.flavor.mintBase, claimer, true, this.flavor.baseTokenProgram);
|
|
658
660
|
const tokenBaseClaimerAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(claimer, tokenBaseClaimer, claimer, this.flavor.mintBase);
|
|
659
661
|
const tokenSyClaimer = (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, claimer, true);
|
|
@@ -695,11 +697,11 @@ class Market {
|
|
|
695
697
|
setupIxs: [tokenBaseClaimerAtaIx, tokenSyClaimerAtaIx],
|
|
696
698
|
};
|
|
697
699
|
}
|
|
698
|
-
async ixWrapperBuyPt({ owner, ptOut, maxBaseIn, tokenSyTrader, tokenPtTrader, tokenBaseTrader, }) {
|
|
699
|
-
tokenSyTrader =
|
|
700
|
-
tokenPtTrader =
|
|
701
|
-
tokenBaseTrader =
|
|
702
|
-
|
|
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);
|
|
703
705
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
704
706
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
705
707
|
const tokenBaseTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenBaseTrader, owner, this.flavor.mintBase);
|
|
@@ -710,7 +712,7 @@ class Market {
|
|
|
710
712
|
depositorSyTokenAccount: tokenSyTrader,
|
|
711
713
|
});
|
|
712
714
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
713
|
-
console.log("mintSyRemAccounts", mintSyRemAccounts)
|
|
715
|
+
// console.log("mintSyRemAccounts", mintSyRemAccounts)
|
|
714
716
|
mintSyRemAccounts.push({
|
|
715
717
|
pubkey: this.coreProgram.programId,
|
|
716
718
|
isWritable: false,
|
|
@@ -722,7 +724,7 @@ class Market {
|
|
|
722
724
|
// ...this.cpiAccounts.withdrawSy,
|
|
723
725
|
]);
|
|
724
726
|
const ix = await this.coreProgram.methods
|
|
725
|
-
.wrapperBuyPt(new
|
|
727
|
+
.wrapperBuyPt(new anchor_1.BN(ptOut.toString()), new anchor_1.BN(maxBaseIn.toString()), mintSyRemAccounts.length - 1)
|
|
726
728
|
.accountsStrict({
|
|
727
729
|
addressLookupTable: this.addressLookupTable,
|
|
728
730
|
buyer: owner,
|
|
@@ -744,11 +746,11 @@ class Market {
|
|
|
744
746
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenBaseTraderAtaIx],
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
|
-
async ixWrapperSellPt({ owner, amount, minBaseOut, tokenSyTrader, tokenPtTrader, tokenBaseTrader, }) {
|
|
748
|
-
tokenSyTrader =
|
|
749
|
-
tokenPtTrader =
|
|
750
|
-
tokenBaseTrader =
|
|
751
|
-
|
|
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);
|
|
752
754
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
753
755
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
754
756
|
const tokenBaseTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenBaseTrader, owner, this.flavor.mintBase);
|
|
@@ -761,7 +763,7 @@ class Market {
|
|
|
761
763
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
762
764
|
const remainingAccounts = (0, utils_1.uniqueRemainingAccounts)([...this.cpiAccounts.getSyState, ...this.cpiAccounts.withdrawSy]);
|
|
763
765
|
const ix = await this.coreProgram.methods
|
|
764
|
-
.wrapperSellPt(new
|
|
766
|
+
.wrapperSellPt(new anchor_1.BN(amount.toString()), new anchor_1.BN(minBaseOut.toString()), redeemSyRemAccounts.length)
|
|
765
767
|
.accountsStrict({
|
|
766
768
|
seller: owner,
|
|
767
769
|
market: this.selfAddress,
|
|
@@ -783,12 +785,12 @@ class Market {
|
|
|
783
785
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenBaseTraderAtaIx],
|
|
784
786
|
};
|
|
785
787
|
}
|
|
786
|
-
async ixWrapperBuyYt({ owner, ytOut, maxBaseIn, tokenSyTrader, tokenPtTrader, tokenYtTrader, tokenBaseTrader, }) {
|
|
787
|
-
tokenSyTrader =
|
|
788
|
-
tokenPtTrader =
|
|
789
|
-
tokenYtTrader =
|
|
790
|
-
tokenBaseTrader =
|
|
791
|
-
|
|
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);
|
|
792
794
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
793
795
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
794
796
|
const tokenYtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtTrader, owner, this.mintYt);
|
|
@@ -808,7 +810,7 @@ class Market {
|
|
|
808
810
|
]);
|
|
809
811
|
const allRemainingAccounts = mintSyRemAccounts.concat(remainingAccounts);
|
|
810
812
|
const ix1 = await this.coreProgram.methods
|
|
811
|
-
.wrapperBuyYt(new
|
|
813
|
+
.wrapperBuyYt(new anchor_1.BN(ytOut.toString()), new anchor_1.BN(maxBaseIn.toString()), mintSyRemAccounts.length)
|
|
812
814
|
.accountsStrict({
|
|
813
815
|
buyer: owner,
|
|
814
816
|
market: this.selfAddress,
|
|
@@ -837,7 +839,7 @@ class Market {
|
|
|
837
839
|
.remainingAccounts(allRemainingAccounts)
|
|
838
840
|
.instruction();
|
|
839
841
|
const ix2 = await this.coreProgram.methods
|
|
840
|
-
.depositYt(new
|
|
842
|
+
.depositYt(new anchor_1.BN(ytOut.toString()))
|
|
841
843
|
.accountsStrict({
|
|
842
844
|
depositor: owner,
|
|
843
845
|
vault: this.vault.selfAddress,
|
|
@@ -864,12 +866,12 @@ class Market {
|
|
|
864
866
|
setupIxs: [tokenSyTraderAtaIx, tokenPtTraderAtaIx, tokenYtTraderAtaIx],
|
|
865
867
|
};
|
|
866
868
|
}
|
|
867
|
-
async ixWrapperSellYt({ owner, amount, minBaseOut, tokenBaseTrader, tokenSyTrader, tokenYtTrader, tokenPtTrader, }) {
|
|
868
|
-
tokenBaseTrader =
|
|
869
|
-
|
|
870
|
-
tokenSyTrader =
|
|
871
|
-
tokenYtTrader =
|
|
872
|
-
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);
|
|
873
875
|
const tokenSyTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyTrader, owner, this.mintSy);
|
|
874
876
|
const tokenPtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtTrader, owner, this.mintPt);
|
|
875
877
|
const tokenYtTraderAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtTrader, owner, this.mintYt);
|
|
@@ -886,14 +888,14 @@ class Market {
|
|
|
886
888
|
...this.cpiAccounts.withdrawSy,
|
|
887
889
|
...this.vault.cpiAccounts.depositSy,
|
|
888
890
|
]);
|
|
889
|
-
console.log(" remaining accounts length", remainingAccounts.length)
|
|
891
|
+
// console.log(" remaining accounts length", remainingAccounts.length)
|
|
890
892
|
// remainingAccounts.push({
|
|
891
893
|
// pubkey: this.coreProgram.programId,
|
|
892
894
|
// isWritable: false,
|
|
893
895
|
// isSigner: false,
|
|
894
896
|
// })
|
|
895
897
|
const ix1 = await this.coreProgram.methods
|
|
896
|
-
.withdrawYt(new
|
|
898
|
+
.withdrawYt(new anchor_1.BN(amount.toString()))
|
|
897
899
|
.accountsStrict({
|
|
898
900
|
ytDst: tokenYtTrader,
|
|
899
901
|
escrowYt: this.vault.escrowYt,
|
|
@@ -912,7 +914,7 @@ class Market {
|
|
|
912
914
|
.remainingAccounts(remainingAccounts)
|
|
913
915
|
.instruction();
|
|
914
916
|
const ix2 = await this.coreProgram.methods
|
|
915
|
-
.wrapperSellYt(new
|
|
917
|
+
.wrapperSellYt(new anchor_1.BN(amount.toString()), new anchor_1.BN(minBaseOut.toString()), redeemSyRemAccounts.length)
|
|
916
918
|
.accountsStrict({
|
|
917
919
|
seller: owner,
|
|
918
920
|
market: this.selfAddress,
|
|
@@ -973,20 +975,19 @@ class Market {
|
|
|
973
975
|
};
|
|
974
976
|
}
|
|
975
977
|
/** Provide liquidity from a base asset - and receive YT and LP tokens in return */
|
|
976
|
-
async ixProvideLiquidityNoPriceImpact({ depositor, amountBase, minLpOut, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
977
|
-
tokenSyDepositor =
|
|
978
|
-
tokenYtDepositor =
|
|
979
|
-
tokenPtDepositor =
|
|
980
|
-
tokenBaseDepositor =
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
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);
|
|
984
985
|
const tokenSyDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
985
986
|
const tokenYtDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
986
987
|
const tokenPtDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
987
988
|
const tokenLpDepositorAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenLpDepositor, depositor, this.mintLp);
|
|
988
|
-
const amountBaseBn = new
|
|
989
|
-
const minLpOutBn = new
|
|
989
|
+
const amountBaseBn = new anchor_1.BN(amountBase.toString());
|
|
990
|
+
const minLpOutBn = new anchor_1.BN(minLpOut.toString());
|
|
990
991
|
// TODO - fix this
|
|
991
992
|
const mintSyIx = await this.flavor.ixMintSy({
|
|
992
993
|
// argument does not matter - since we are just getting the keys
|
|
@@ -996,22 +997,22 @@ class Market {
|
|
|
996
997
|
depositorSyTokenAccount: tokenSyDepositor,
|
|
997
998
|
});
|
|
998
999
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
999
|
-
// Log vault accounts before filtering
|
|
1000
1000
|
const beforeVaultAccounts = [...this.vault.cpiAccounts.getSyState, ...this.vault.cpiAccounts.depositSy];
|
|
1001
|
-
|
|
1001
|
+
// Log vault accounts before filtering
|
|
1002
|
+
// console.log("Before filtering vault accounts:", beforeVaultAccounts.length, "accounts")
|
|
1002
1003
|
// Filter out TOKEN_PROGRAM_ID and SystemProgram.programId from vault remaining accounts
|
|
1003
1004
|
const vaultCpiRemainingAccounts = beforeVaultAccounts.filter((account) => account.pubkey.toBase58() !== spl_token_1.TOKEN_PROGRAM_ID.toBase58());
|
|
1004
1005
|
// Log vault accounts after filtering
|
|
1005
|
-
console.log("After filtering vault accounts:", vaultCpiRemainingAccounts.length, "accounts")
|
|
1006
|
+
// console.log("After filtering vault accounts:", vaultCpiRemainingAccounts.length, "accounts")
|
|
1006
1007
|
// Log market accounts before filtering
|
|
1007
1008
|
const beforeMarketAccounts = [...this.cpiAccounts.depositSy];
|
|
1008
|
-
console.log("Before filtering market accounts:", beforeMarketAccounts.length, "accounts")
|
|
1009
|
+
// console.log("Before filtering market accounts:", beforeMarketAccounts.length, "accounts")
|
|
1009
1010
|
// Filter out TOKEN_PROGRAM_ID and SystemProgram.programId from market remaining accounts
|
|
1010
1011
|
const marketCpiRemainingAccounts = beforeMarketAccounts.filter((account) => account.pubkey.toBase58() !== spl_token_1.TOKEN_PROGRAM_ID.toBase58() &&
|
|
1011
1012
|
account.pubkey.toBase58() !== anchor_1.web3.SystemProgram.programId.toBase58() &&
|
|
1012
1013
|
account.pubkey.toBase58() !== this.selfAddress.toBase58());
|
|
1013
1014
|
// Log market accounts after filtering
|
|
1014
|
-
console.log("After filtering market accounts:", marketCpiRemainingAccounts.length, "accounts")
|
|
1015
|
+
// console.log("After filtering market accounts:", marketCpiRemainingAccounts.length, "accounts")
|
|
1015
1016
|
// These remaining accounts can be in any order, and they can be unique-ified
|
|
1016
1017
|
const unorderedRemainingAccounts = (0, utils_1.uniqueRemainingAccounts)([
|
|
1017
1018
|
...vaultCpiRemainingAccounts,
|
|
@@ -1051,7 +1052,7 @@ class Market {
|
|
|
1051
1052
|
})
|
|
1052
1053
|
.remainingAccounts(allRemainingAccounts)
|
|
1053
1054
|
.instruction();
|
|
1054
|
-
console.log("ix accounts length", ix.keys.length)
|
|
1055
|
+
// console.log("ix accounts length", ix.keys.length)
|
|
1055
1056
|
return {
|
|
1056
1057
|
ixs: [
|
|
1057
1058
|
...(await this.flavor.preIxs({ signer: depositor })),
|
|
@@ -1061,14 +1062,13 @@ class Market {
|
|
|
1061
1062
|
setupIxs: [tokenSyDepositorAtaIx, tokenYtDepositorAtaIx, tokenPtDepositorAtaIx, tokenLpDepositorAtaIx],
|
|
1062
1063
|
};
|
|
1063
1064
|
}
|
|
1064
|
-
async ixProvideLiquidityBase({ depositor, amountBase, minLpOut, externalPtToBuy, externalSyConstraint, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
1065
|
-
tokenSyDepositor =
|
|
1066
|
-
tokenYtDepositor =
|
|
1067
|
-
tokenPtDepositor =
|
|
1068
|
-
tokenBaseDepositor =
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
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);
|
|
1072
1072
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
1073
1073
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
1074
1074
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
@@ -1087,7 +1087,7 @@ class Market {
|
|
|
1087
1087
|
});
|
|
1088
1088
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
1089
1089
|
const ix = await this.coreProgram.methods
|
|
1090
|
-
.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()))
|
|
1091
1091
|
.accountsStrict({
|
|
1092
1092
|
depositor,
|
|
1093
1093
|
lpPosition,
|
|
@@ -1118,14 +1118,13 @@ class Market {
|
|
|
1118
1118
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1119
1119
|
};
|
|
1120
1120
|
}
|
|
1121
|
-
async ixProvideLiquidityClassic({ depositor, amountBase, amountPt, minLpOut, tokenSyDepositor, tokenYtDepositor, tokenPtDepositor, tokenBaseDepositor, tokenLpDepositor, }) {
|
|
1122
|
-
tokenSyDepositor =
|
|
1123
|
-
tokenYtDepositor =
|
|
1124
|
-
tokenPtDepositor =
|
|
1125
|
-
tokenBaseDepositor =
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
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);
|
|
1129
1128
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenSyDepositor, depositor, this.mintSy);
|
|
1130
1129
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenYtDepositor, depositor, this.mintYt);
|
|
1131
1130
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(depositor, tokenPtDepositor, depositor, this.mintPt);
|
|
@@ -1143,7 +1142,7 @@ class Market {
|
|
|
1143
1142
|
});
|
|
1144
1143
|
const mintSyRemAccounts = mintSyIx.keys;
|
|
1145
1144
|
const ix = await this.coreProgram.methods
|
|
1146
|
-
.wrapperProvideLiquidityClassic(new
|
|
1145
|
+
.wrapperProvideLiquidityClassic(new anchor_1.BN(amountBase.toString()), new anchor_1.BN(amountPt.toString()), new anchor_1.BN(minLpOut.toString()), mintSyRemAccounts.length)
|
|
1147
1146
|
.accountsStrict({
|
|
1148
1147
|
depositor,
|
|
1149
1148
|
lpPosition,
|
|
@@ -1173,14 +1172,13 @@ class Market {
|
|
|
1173
1172
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenLpAtaIx],
|
|
1174
1173
|
};
|
|
1175
1174
|
}
|
|
1176
|
-
async ixWithdrawLiquidityToBase({ owner, amountLp, minBaseOut, tokenSyWithdrawer, tokenYtWithdrawer, tokenPtWithdrawer, tokenBaseWithdrawer, tokenLpWithdrawer, }) {
|
|
1177
|
-
tokenSyWithdrawer =
|
|
1178
|
-
tokenYtWithdrawer =
|
|
1179
|
-
tokenPtWithdrawer =
|
|
1180
|
-
tokenBaseWithdrawer =
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
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);
|
|
1184
1182
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyWithdrawer, owner, this.mintSy);
|
|
1185
1183
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtWithdrawer, owner, this.mintYt);
|
|
1186
1184
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtWithdrawer, owner, this.mintPt);
|
|
@@ -1200,7 +1198,7 @@ class Market {
|
|
|
1200
1198
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
1201
1199
|
const minSyOut = Number(minBaseOut) / this.currentSyExchangeRate;
|
|
1202
1200
|
const ix = await this.coreProgram.methods
|
|
1203
|
-
.wrapperWithdrawLiquidity(new
|
|
1201
|
+
.wrapperWithdrawLiquidity(new anchor_1.BN(amountLp.toString()), new anchor_1.BN(minSyOut.toFixed(0).toString()), redeemSyRemAccounts.length)
|
|
1204
1202
|
.accountsStrict({
|
|
1205
1203
|
market: this.selfAddress,
|
|
1206
1204
|
tokenPtEscrow: this.tokenPtEscrow,
|
|
@@ -1227,14 +1225,13 @@ class Market {
|
|
|
1227
1225
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1228
1226
|
};
|
|
1229
1227
|
}
|
|
1230
|
-
async ixWithdrawLiquidityClassic({ owner, amountLp,
|
|
1231
|
-
tokenSyWithdrawer =
|
|
1232
|
-
tokenYtWithdrawer =
|
|
1233
|
-
tokenPtWithdrawer =
|
|
1234
|
-
tokenBaseWithdrawer =
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
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);
|
|
1238
1235
|
const tokenSyAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenSyWithdrawer, owner, this.mintSy);
|
|
1239
1236
|
const tokenYtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenYtWithdrawer, owner, this.mintYt);
|
|
1240
1237
|
const tokenPtAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenPtWithdrawer, owner, this.mintPt);
|
|
@@ -1253,7 +1250,7 @@ class Market {
|
|
|
1253
1250
|
});
|
|
1254
1251
|
const redeemSyRemAccounts = redeemSyIx.keys;
|
|
1255
1252
|
const ixn = await this.coreProgram.methods
|
|
1256
|
-
.wrapperWithdrawLiquidityClassic(new
|
|
1253
|
+
.wrapperWithdrawLiquidityClassic(new anchor_1.BN(amountLp.toString()), redeemSyRemAccounts.length)
|
|
1257
1254
|
.accountsStrict({
|
|
1258
1255
|
market: this.selfAddress,
|
|
1259
1256
|
tokenPtEscrow: this.tokenPtEscrow,
|
|
@@ -1279,8 +1276,8 @@ class Market {
|
|
|
1279
1276
|
setupIxs: [tokenSyAtaIx, tokenYtAtaIx, tokenPtAtaIx, tokenBaseAtaIx, tokenLpAtaIx],
|
|
1280
1277
|
};
|
|
1281
1278
|
}
|
|
1282
|
-
async claimFarmEmissions({ owner, mint, tokenProgram, tokenDst, }) {
|
|
1283
|
-
tokenDst =
|
|
1279
|
+
async claimFarmEmissions({ owner, mint, tokenProgram, tokenDst: tokenDstParam, }) {
|
|
1280
|
+
const tokenDst = tokenDstParam || (0, spl_token_1.getAssociatedTokenAddressSync)(mint, owner, true, tokenProgram);
|
|
1284
1281
|
const lpPosition = this.xponPda.marketLpPosition({ market: this.selfAddress, owner });
|
|
1285
1282
|
const tokenFarm = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, this.selfAddress, true, tokenProgram);
|
|
1286
1283
|
const tokenAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, tokenDst, owner, mint);
|
|
@@ -1324,12 +1321,12 @@ class Market {
|
|
|
1324
1321
|
addMarketEmissionIx: ix,
|
|
1325
1322
|
};
|
|
1326
1323
|
}
|
|
1327
|
-
async addFarm({ signer, farmMint, farmRewardTokenProgram, emissionsRate, untilTimestamp, farmRewardSrc, feePayer, }) {
|
|
1328
|
-
feePayer =
|
|
1324
|
+
async addFarm({ signer, farmMint, farmRewardTokenProgram, emissionsRate, untilTimestamp, farmRewardSrc: farmRewardSrcParam, feePayer: feePayerParam, }) {
|
|
1325
|
+
const feePayer = feePayerParam || signer;
|
|
1329
1326
|
const farmRewardEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, this.selfAddress, true, farmRewardTokenProgram);
|
|
1330
|
-
farmRewardSrc =
|
|
1327
|
+
const farmRewardSrc = farmRewardSrcParam || (0, spl_token_1.getAssociatedTokenAddressSync)(farmMint, signer, true, farmRewardTokenProgram);
|
|
1331
1328
|
const ix = await this.coreProgram.methods
|
|
1332
|
-
.addFarm(new
|
|
1329
|
+
.addFarm(new anchor_1.BN(emissionsRate), untilTimestamp)
|
|
1333
1330
|
.accountsStrict({
|
|
1334
1331
|
adminState: (0, utils_1.getExponentAdminStatePda)(),
|
|
1335
1332
|
market: this.selfAddress,
|
|
@@ -1347,20 +1344,20 @@ class Market {
|
|
|
1347
1344
|
};
|
|
1348
1345
|
}
|
|
1349
1346
|
/** Calculate available liquidity for PT trades
|
|
1350
|
-
* @param
|
|
1351
|
-
* @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)
|
|
1352
1349
|
* @returns amount of PT that can be traded given current liquidity
|
|
1353
1350
|
*/
|
|
1354
|
-
liquidityAvailable(
|
|
1351
|
+
liquidityAvailable(isBuy, sizePt) {
|
|
1355
1352
|
const calc = this.marketCalculator();
|
|
1356
|
-
if (
|
|
1353
|
+
if (isBuy) {
|
|
1357
1354
|
// When buying PT, we're limited by SY liquidity
|
|
1358
1355
|
// Convert PT amount to SY using current price
|
|
1359
|
-
const syNeeded = Number(
|
|
1356
|
+
const syNeeded = Number(sizePt) * calc.exchangeRate;
|
|
1360
1357
|
// Available SY in the market
|
|
1361
1358
|
const syAvailable = Number(this.syBalance);
|
|
1362
1359
|
if (syNeeded <= syAvailable) {
|
|
1363
|
-
return
|
|
1360
|
+
return sizePt;
|
|
1364
1361
|
}
|
|
1365
1362
|
else {
|
|
1366
1363
|
// Calculate max PT that can be bought with available SY
|
|
@@ -1370,8 +1367,8 @@ class Market {
|
|
|
1370
1367
|
else {
|
|
1371
1368
|
// When selling PT, we're limited by PT liquidity in the market
|
|
1372
1369
|
const ptAvailable = this.ptBalance;
|
|
1373
|
-
if (
|
|
1374
|
-
return
|
|
1370
|
+
if (sizePt <= ptAvailable) {
|
|
1371
|
+
return sizePt;
|
|
1375
1372
|
}
|
|
1376
1373
|
else {
|
|
1377
1374
|
return ptAvailable;
|
|
@@ -1380,59 +1377,59 @@ class Market {
|
|
|
1380
1377
|
}
|
|
1381
1378
|
}
|
|
1382
1379
|
exports.Market = Market;
|
|
1383
|
-
function toJson(
|
|
1384
|
-
const
|
|
1380
|
+
function toJson(market) {
|
|
1381
|
+
const marketCalculator = market.marketCalculator();
|
|
1385
1382
|
return {
|
|
1386
|
-
treasurySyTokenAccount:
|
|
1387
|
-
address:
|
|
1388
|
-
addressLookupTable:
|
|
1389
|
-
tokenSyEscrow:
|
|
1390
|
-
tokenPtEscrow:
|
|
1391
|
-
tokenLpEscrow:
|
|
1392
|
-
lpSupply:
|
|
1393
|
-
syProgram:
|
|
1394
|
-
mintPt:
|
|
1395
|
-
mintSy:
|
|
1396
|
-
mintLp:
|
|
1397
|
-
feeTreasurySyBps:
|
|
1398
|
-
ptBalance:
|
|
1399
|
-
syBalance:
|
|
1400
|
-
currentSyRate:
|
|
1401
|
-
expirationTs:
|
|
1402
|
-
expirationDate: new Date(
|
|
1403
|
-
lnFeeRateRoot:
|
|
1404
|
-
rateScalarRoot:
|
|
1405
|
-
lastLnImpliedRate:
|
|
1406
|
-
currentPtPriceInSy:
|
|
1407
|
-
currentPtPriceInAsset:
|
|
1408
|
-
secondsRemaining:
|
|
1409
|
-
proportionPtInAsset:
|
|
1410
|
-
proportionPtInSy:
|
|
1411
|
-
currentFeeRate:
|
|
1412
|
-
currentRateScalar:
|
|
1413
|
-
currentRateAnchor:
|
|
1414
|
-
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),
|
|
1415
1412
|
emissions: {
|
|
1416
|
-
trackers:
|
|
1413
|
+
trackers: market.marketEmissions.trackers.map((e) => ({
|
|
1417
1414
|
tokenEscrow: e.tokenEscrow.toBase58(),
|
|
1418
1415
|
lpShareIndex: e.lpShareIndex,
|
|
1419
1416
|
lastSeenStaged: e.lastSeenStaged,
|
|
1420
1417
|
})),
|
|
1421
1418
|
},
|
|
1422
|
-
ptApr:
|
|
1423
|
-
ptApy:
|
|
1424
|
-
lpEscrowAmount:
|
|
1425
|
-
maxLpSupply:
|
|
1419
|
+
ptApr: market.ptApr,
|
|
1420
|
+
ptApy: market.ptApy,
|
|
1421
|
+
lpEscrowAmount: market.state.lpEscrowAmount.toString(),
|
|
1422
|
+
maxLpSupply: market.state.maxLpSupply.toString(),
|
|
1426
1423
|
liquidityNetBalanceLimits: {
|
|
1427
|
-
windowStartTimestamp:
|
|
1428
|
-
windowStartNetBalance:
|
|
1429
|
-
maxNetBalanceChangeNegativePercentage:
|
|
1430
|
-
maxNetBalanceChangePositivePercentage:
|
|
1431
|
-
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,
|
|
1432
1429
|
},
|
|
1433
1430
|
lpFarm: {
|
|
1434
|
-
lastSeenTimestamp:
|
|
1435
|
-
farmEmissions:
|
|
1431
|
+
lastSeenTimestamp: market.state.lpFarm.lastSeenTimestamp,
|
|
1432
|
+
farmEmissions: market.state.lpFarm.farmEmissions.map((e) => ({
|
|
1436
1433
|
mint: e.mint.toBase58(),
|
|
1437
1434
|
tokenRate: e.tokenRate.toString(),
|
|
1438
1435
|
expiryTimestamp: e.expiryTimestamp,
|