@exponent-labs/exponent-sdk 0.0.3 → 0.0.4
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/events.d.ts +35 -1
- package/build/events.js +21 -2
- package/build/events.js.map +1 -1
- package/build/flavors.js +7 -5
- package/build/flavors.js.map +1 -1
- package/build/market.d.ts +0 -2
- package/build/market.js +2 -5
- package/build/market.js.map +1 -1
- package/build/syPosition.js +4 -2
- package/build/syPosition.js.map +1 -1
- package/build/tokenUtil.js.map +1 -1
- package/build/vault.d.ts +1 -1
- package/build/vault.js +3 -3
- package/build/vault.js.map +1 -1
- package/build/ytPosition.js.map +1 -1
- package/package.json +24 -18
- package/src/events.ts +60 -2
- package/src/flavors.ts +8 -5
- package/src/market.ts +1 -5
- package/src/syPosition.ts +4 -2
- package/src/tokenUtil.ts +1 -0
- package/src/vault.ts +2 -2
- package/src/ytPosition.ts +1 -1
package/src/events.ts
CHANGED
|
@@ -5,7 +5,6 @@ import bs58 from "bs58"
|
|
|
5
5
|
|
|
6
6
|
export class EventDecoder {
|
|
7
7
|
private coder: BorshCoder
|
|
8
|
-
private eventDecoder: EventDecoder
|
|
9
8
|
programId: web3.PublicKey
|
|
10
9
|
private static eventIxTag = new BN("1d9acb512ea545e4", 16)
|
|
11
10
|
private discriminators: Map<string, string>
|
|
@@ -21,7 +20,7 @@ export class EventDecoder {
|
|
|
21
20
|
parseAsTransactionCpiData(log: string): string | null {
|
|
22
21
|
let encodedLog: Buffer
|
|
23
22
|
try {
|
|
24
|
-
encodedLog = bs58.decode(log)
|
|
23
|
+
encodedLog = Buffer.from(bs58.decode(log))
|
|
25
24
|
} catch (e) {
|
|
26
25
|
return null
|
|
27
26
|
}
|
|
@@ -135,6 +134,10 @@ function categorizeEvents(events: GenericEvent[]): CategorizedEvents {
|
|
|
135
134
|
const wrapperCollectInterestEvents: WrapperCollectInterestEvent[] = []
|
|
136
135
|
const wrapperWithdrawLiquidityEvents: WrapperWithdrawLiquidityEvent[] = []
|
|
137
136
|
const wrapperWithdrawLiquidityClassicEvents: WrapperWithdrawLiquidityClassicEvent[] = []
|
|
137
|
+
const wrapperProvideLiquidityBaseEvents: WrapperProvideLiquidityBaseEvent[] = []
|
|
138
|
+
const wrapperProvideLiquidityClassicEvents: WrapperProvideLiquidityClassicEvent[] = []
|
|
139
|
+
const wrapperStripEvents: WrapperStripEvent[] = []
|
|
140
|
+
const wrapperMergeEvents: WrapperMergeEvent[] = []
|
|
138
141
|
|
|
139
142
|
for (const ev of events) {
|
|
140
143
|
switch (ev.name) {
|
|
@@ -216,6 +219,18 @@ function categorizeEvents(events: GenericEvent[]): CategorizedEvents {
|
|
|
216
219
|
case "WrapperWithdrawLiquidityClassicEvent":
|
|
217
220
|
wrapperWithdrawLiquidityClassicEvents.push(ev.data as WrapperWithdrawLiquidityClassicEvent)
|
|
218
221
|
break
|
|
222
|
+
case "WrapperProvideLiquidityBaseEvent":
|
|
223
|
+
wrapperProvideLiquidityBaseEvents.push(ev.data as WrapperProvideLiquidityBaseEvent)
|
|
224
|
+
break
|
|
225
|
+
case "WrapperProvideLiquidityClassicEvent":
|
|
226
|
+
wrapperProvideLiquidityClassicEvents.push(ev.data as WrapperProvideLiquidityClassicEvent)
|
|
227
|
+
break
|
|
228
|
+
case "WrapperStripEvent":
|
|
229
|
+
wrapperStripEvents.push(ev.data as WrapperStripEvent)
|
|
230
|
+
break
|
|
231
|
+
case "WrapperMergeEvent":
|
|
232
|
+
wrapperMergeEvents.push(ev.data as WrapperMergeEvent)
|
|
233
|
+
break
|
|
219
234
|
}
|
|
220
235
|
}
|
|
221
236
|
|
|
@@ -246,6 +261,10 @@ function categorizeEvents(events: GenericEvent[]): CategorizedEvents {
|
|
|
246
261
|
wrapperCollectInterestEvents,
|
|
247
262
|
wrapperWithdrawLiquidityEvents,
|
|
248
263
|
wrapperWithdrawLiquidityClassicEvents,
|
|
264
|
+
wrapperProvideLiquidityBaseEvents,
|
|
265
|
+
wrapperProvideLiquidityClassicEvents,
|
|
266
|
+
wrapperStripEvents,
|
|
267
|
+
wrapperMergeEvents,
|
|
249
268
|
}
|
|
250
269
|
}
|
|
251
270
|
|
|
@@ -276,6 +295,10 @@ export interface CategorizedEvents {
|
|
|
276
295
|
wrapperCollectInterestEvents: WrapperCollectInterestEvent[]
|
|
277
296
|
wrapperWithdrawLiquidityEvents: WrapperWithdrawLiquidityEvent[]
|
|
278
297
|
wrapperWithdrawLiquidityClassicEvents: WrapperWithdrawLiquidityClassicEvent[]
|
|
298
|
+
wrapperProvideLiquidityBaseEvents: WrapperProvideLiquidityBaseEvent[]
|
|
299
|
+
wrapperProvideLiquidityClassicEvents: WrapperProvideLiquidityClassicEvent[]
|
|
300
|
+
wrapperStripEvents: WrapperStripEvent[]
|
|
301
|
+
wrapperMergeEvents: WrapperMergeEvent[]
|
|
279
302
|
}
|
|
280
303
|
|
|
281
304
|
export interface TradePtEvent {
|
|
@@ -593,3 +616,38 @@ export interface WrapperWithdrawLiquidityClassicEvent {
|
|
|
593
616
|
amount_pt_out: BN
|
|
594
617
|
lp_price: number
|
|
595
618
|
}
|
|
619
|
+
|
|
620
|
+
export interface WrapperProvideLiquidityBaseEvent {
|
|
621
|
+
user_address: web3.PublicKey
|
|
622
|
+
amount_base_in: BN
|
|
623
|
+
amount_lp_out: BN
|
|
624
|
+
market_address: web3.PublicKey
|
|
625
|
+
trade_amount_pt_out: BN
|
|
626
|
+
trade_amount_sy_in: BN
|
|
627
|
+
lp_price: number
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export interface WrapperProvideLiquidityClassicEvent {
|
|
631
|
+
user_address: web3.PublicKey
|
|
632
|
+
market_address: web3.PublicKey
|
|
633
|
+
amount_base_in: BN
|
|
634
|
+
amount_pt_in: BN
|
|
635
|
+
amount_lp_out: BN
|
|
636
|
+
lp_price: number
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export interface WrapperStripEvent {
|
|
640
|
+
user_address: web3.PublicKey
|
|
641
|
+
vault_address: web3.PublicKey
|
|
642
|
+
amount_base_in: BN
|
|
643
|
+
amount_sy_stripped: BN
|
|
644
|
+
amount_py_out: BN
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export interface WrapperMergeEvent {
|
|
648
|
+
user_address: web3.PublicKey
|
|
649
|
+
vault_address: web3.PublicKey
|
|
650
|
+
amount_py_in: BN
|
|
651
|
+
amount_sy_redeemed: BN
|
|
652
|
+
amount_base_out: BN
|
|
653
|
+
}
|
package/src/flavors.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { BN, web3 } from "@coral-xyz/anchor"
|
|
|
2
2
|
import { ExponentFetcher, fetchKaminoReserve } from "@exponent-labs/exponent-fetcher"
|
|
3
3
|
import { Environment } from "./environment"
|
|
4
4
|
import { MfiSySdk } from "@exponent-labs/marginfi-sy-sdk"
|
|
5
|
-
import {
|
|
5
|
+
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
6
|
+
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
6
7
|
import { KlendSySdk } from "@exponent-labs/kamino-sy-sdk"
|
|
7
8
|
import {
|
|
8
9
|
FlavorKaminoStateJson,
|
|
@@ -26,6 +27,8 @@ import {
|
|
|
26
27
|
FlavorGenericState,
|
|
27
28
|
InterfaceInstructionArgs,
|
|
28
29
|
FlavorGenericStateJson,
|
|
30
|
+
toInterfaceTypeGenericJson,
|
|
31
|
+
fromInterfaceTypeGenericJson,
|
|
29
32
|
} from "@exponent-labs/exponent-types"
|
|
30
33
|
import { JitoRestakingSySdk } from "@exponent-labs/jito-restaking-sy-sdk"
|
|
31
34
|
import { PreciseNumber } from "@exponent-labs/precise-number"
|
|
@@ -378,7 +381,7 @@ export function serializeFlavorGeneric(flavor: FlavorGenericState): FlavorGeneri
|
|
|
378
381
|
treasuryEmission: e.treasuryEmission.toString(),
|
|
379
382
|
})),
|
|
380
383
|
interfaceAccounts: flavor.genericSyState.account.interfaceAccounts.map((a) => a.toString()),
|
|
381
|
-
interfaceType: flavor.genericSyState.account.interfaceType,
|
|
384
|
+
interfaceType: toInterfaceTypeGenericJson(flavor.genericSyState.account.interfaceType),
|
|
382
385
|
index: parseFloat(PreciseNumber.fromRaw(flavor.genericSyState.account.index[0]).valueString),
|
|
383
386
|
},
|
|
384
387
|
},
|
|
@@ -444,7 +447,7 @@ export function deserializeFlavorGeneric(flavor: FlavorGenericStateJson): Flavor
|
|
|
444
447
|
yieldBearingMint: new web3.PublicKey(flavor.genericSyState.account.yieldBearingMint),
|
|
445
448
|
tokenSyEscrow: new web3.PublicKey(flavor.genericSyState.account.tokenSyEscrow),
|
|
446
449
|
interfaceAccounts: flavor.genericSyState.account.interfaceAccounts.map((a) => new web3.PublicKey(a)),
|
|
447
|
-
interfaceType: flavor.genericSyState.account.interfaceType,
|
|
450
|
+
interfaceType: fromInterfaceTypeGenericJson(flavor.genericSyState.account.interfaceType),
|
|
448
451
|
maxSySupply: new BN(flavor.genericSyState.account.maxSySupply),
|
|
449
452
|
minMintSize: new BN(flavor.genericSyState.account.minMintSize),
|
|
450
453
|
minRedeemSize: new BN(flavor.genericSyState.account.minRedeemSize),
|
|
@@ -638,7 +641,8 @@ async function makeKaminoFlavor(
|
|
|
638
641
|
// TODO - don't do this
|
|
639
642
|
const baseTokenProgram = await fetcher.connection.getAccountInfo(mintBase).then((a) => a.owner)
|
|
640
643
|
|
|
641
|
-
const
|
|
644
|
+
const pda = new KaminoSyPda(new web3.PublicKey(KAMINO_STANDARD_PROGRAM_ID))
|
|
645
|
+
const meta = pda.syMeta({ kaminoReserve: reserve })
|
|
642
646
|
|
|
643
647
|
const syMeta = await fetcher.fetchKaminoSyMeta(meta)
|
|
644
648
|
|
|
@@ -647,7 +651,6 @@ async function makeKaminoFlavor(
|
|
|
647
651
|
klendMarketId: reserveAcct.lendingMarket,
|
|
648
652
|
klendReserve: reserve,
|
|
649
653
|
klendSyProgramId: kaminoSyProgramId,
|
|
650
|
-
klendProgramId: KAMINO_LEND_PROGRAM_ID,
|
|
651
654
|
})
|
|
652
655
|
|
|
653
656
|
return {
|
package/src/market.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AnchorProvider, Program, Wallet, web3 } from "@coral-xyz/anchor"
|
|
2
2
|
import { ExponentFetcher, LiquidityNetBalanceLimits, LpFarm } from "@exponent-labs/exponent-fetcher"
|
|
3
|
-
import { ClaimAmount, ExponentIx } from "@exponent-labs/exponent-ix"
|
|
4
3
|
import {
|
|
5
4
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
6
5
|
getAssociatedTokenAddressSync,
|
|
@@ -22,12 +21,11 @@ import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
|
22
21
|
import { Vault } from "./vault"
|
|
23
22
|
import { LiquidityAdd, lpOutForTokensIn, MarketCalculator } from "@exponent-labs/market-math"
|
|
24
23
|
import { emitEventAuthority, getExponentAdminStatePda, uniqueRemainingAccounts } from "./utils"
|
|
25
|
-
import { CpiAccountsRaw, Flavor, SyPosition } from "@exponent-labs/exponent-types"
|
|
24
|
+
import { AccountInfo, CpiAccountsRaw, Flavor, serializeCpiAccountsRaw, SyPosition } from "@exponent-labs/exponent-types"
|
|
26
25
|
import { PreciseNumber } from "@exponent-labs/precise-number"
|
|
27
26
|
import { AnchorizedPNum } from "@exponent-labs/exponent-types"
|
|
28
27
|
import { extendAddressLookupTable } from "./utils/altUtil"
|
|
29
28
|
import { makeSyPosition } from "./syPosition"
|
|
30
|
-
import { serializeCpiAccountsRaw } from "@exponent-labs/exponent-ix"
|
|
31
29
|
import { CpiAccountsRawJson } from "@exponent-labs/exponent-types"
|
|
32
30
|
|
|
33
31
|
export { LiquidityAdd }
|
|
@@ -138,7 +136,6 @@ export class MyWallet implements Wallet {
|
|
|
138
136
|
|
|
139
137
|
export class Market {
|
|
140
138
|
coreProgram: Program<ExponentCore>
|
|
141
|
-
xponIx: ExponentIx
|
|
142
139
|
xponPda: ExponentPDA
|
|
143
140
|
|
|
144
141
|
constructor(
|
|
@@ -148,7 +145,6 @@ export class Market {
|
|
|
148
145
|
public connection: web3.Connection,
|
|
149
146
|
) {
|
|
150
147
|
this.xponPda = new ExponentPDA(env.coreProgramId)
|
|
151
|
-
this.xponIx = new ExponentIx(env.coreProgramId)
|
|
152
148
|
const mockWallet = new MyWallet(web3.Keypair.generate())
|
|
153
149
|
this.coreProgram = new Program(IDL as ExponentCore, new AnchorProvider(connection, mockWallet))
|
|
154
150
|
}
|
package/src/syPosition.ts
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
} from "./flavors"
|
|
8
8
|
import { ExponentFetcher, SyPosition } from "@exponent-labs/exponent-fetcher"
|
|
9
9
|
import { MarginfiSyPda } from "@exponent-labs/marginfi-sy-pda"
|
|
10
|
-
import {
|
|
10
|
+
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
11
|
+
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
11
12
|
import { JitoRestakingSyPda } from "@exponent-labs/jito-restaking-sy-pda"
|
|
12
13
|
import { PROGRAM_ID as PERENA_STANDARD_PROGRAM_ID } from "@exponent-labs/perena-sy-idl"
|
|
13
14
|
import { PROGRAM_ID as GENERIC_STANDARD_PROGRAM_ID } from "@exponent-labs/generic-sy-idl"
|
|
@@ -92,7 +93,8 @@ async function makeSyPositionKamino(
|
|
|
92
93
|
owner: web3.PublicKey,
|
|
93
94
|
): Promise<SyPosition> {
|
|
94
95
|
const reserve = flavor.kaminoSyState.account.kaminoReserve
|
|
95
|
-
const
|
|
96
|
+
const pda = new KaminoSyPda(new web3.PublicKey(KAMINO_STANDARD_PROGRAM_ID))
|
|
97
|
+
const positionAddress = pda.position({ reserve, owner })
|
|
96
98
|
const position = await fetcher.fetchKaminoSyPosition(positionAddress)
|
|
97
99
|
return position
|
|
98
100
|
}
|
package/src/tokenUtil.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import { CpiAccountsRaw, CpiAccountsRawJson } from "@exponent-labs/exponent-types"
|
|
2
3
|
import { MintLayout } from "@solana/spl-token"
|
|
3
4
|
|
|
4
5
|
export async function getMintSupply(cnx: web3.Connection, address: web3.PublicKey): Promise<bigint> {
|
package/src/vault.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN, Program, web3, AnchorProvider } from "@coral-xyz/anchor"
|
|
2
|
-
import { ClaimAmount } from "@exponent-labs/exponent-ix"
|
|
3
2
|
import { deserializeEmission, ExponentFetcher, serializeEmission } from "@exponent-labs/exponent-fetcher"
|
|
4
3
|
import { fetchAddressLookupTable, makeCpiAccountMetaLists } from "./addressLookupTableUtil"
|
|
5
4
|
import {
|
|
@@ -28,9 +27,10 @@ import { emitEventAuthority, InstructionAccounts, uniqueRemainingAccounts } from
|
|
|
28
27
|
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
29
28
|
import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
30
29
|
import { MyWallet } from "./market"
|
|
31
|
-
import { deserializeCpiAccountsRaw, serializeCpiAccountsRaw } from "@exponent-labs/exponent-
|
|
30
|
+
import { deserializeCpiAccountsRaw, serializeCpiAccountsRaw } from "@exponent-labs/exponent-types"
|
|
32
31
|
import { VaultEmission, VaultJson, VaultState, AnchorizedPNum, CpiAccountsRaw } from "@exponent-labs/exponent-types"
|
|
33
32
|
import { extendAddressLookupTable } from "./utils/altUtil"
|
|
33
|
+
import { ClaimAmount } from "@exponent-labs/marginfi-sy-sdk"
|
|
34
34
|
|
|
35
35
|
export type CollectTreasuryEmissionKind =
|
|
36
36
|
| { yieldPosition: {} }
|
package/src/ytPosition.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { Environment } from "./environment"
|
|
|
4
4
|
import { ExponentFetcher, YieldTokenTracker, YtPosition as YtPositionState } from "@exponent-labs/exponent-fetcher"
|
|
5
5
|
import { Vault } from "./vault"
|
|
6
6
|
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
7
|
-
import { ClaimAmount } from "@exponent-labs/exponent-ix"
|
|
8
7
|
import { InstructionAccounts } from "./utils"
|
|
9
8
|
import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
10
9
|
import { MyWallet } from "./market"
|
|
11
10
|
import { VaultJson } from "@exponent-labs/exponent-types"
|
|
12
11
|
import { PreciseNumber } from "@exponent-labs/precise-number"
|
|
12
|
+
import { ClaimAmount } from "@exponent-labs/marginfi-sy-sdk"
|
|
13
13
|
|
|
14
14
|
export class YtPosition {
|
|
15
15
|
public coreProgram: Program<ExponentCore>
|