@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/ytPosition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ytPosition.js","sourceRoot":"","sources":["../src/ytPosition.ts"],"names":[],"mappings":";;;AAAA,8CAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"ytPosition.js","sourceRoot":"","sources":["../src/ytPosition.ts"],"names":[],"mappings":";;;AAAA,8CAAqE;AACrE,iDAAmF;AAEnF,sEAAmH;AACnH,8DAA+D;AAC/D,8DAAyD;AAGzD,kEAA6D;AAG7D,qCAAmC;AAEnC,mCAA+B;AAE/B,MAAa,UAAU;IAGZ;IACA;IACA;IACA;IACA;IANF,WAAW,CAAuB;IACzC,YACS,GAAgB,EAChB,UAA2B,EAC3B,WAA2B,EAC3B,KAAsB,EACtB,KAAY;QAJZ,QAAG,GAAH,GAAG,CAAa;QAChB,eAAU,GAAV,UAAU,CAAiB;QAC3B,gBAAW,GAAX,WAAW,CAAgB;QAC3B,UAAK,GAAL,KAAK,CAAiB;QACtB,UAAK,GAAL,KAAK,CAAO;QAEnB,MAAM,UAAU,GAAG,IAAI,iBAAQ,CAAC,aAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAO,CAAC,kBAAmB,EAAE,IAAI,uBAAc,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAA;IACjG,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAgB,EAAE,UAA2B,EAAE,OAAuB,EAAE,KAAa;QACrG,MAAM,OAAO,GAAG,IAAI,kCAAe,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;QACnD,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAC9D,MAAM,WAAW,GAAG,KAAK,IAAI,CAAC,MAAM,aAAK,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,eAAe,C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AC;QAC1F,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE;KACjC,CAAA;AACH,CAAC;AAED,SAAS,uBAAuB,CAAC,iBAAoC;IACnE,OAAO;QACL,aAAa,EAAE,iBAAiB,CAAC,aAAa;QAC9C,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,QAAQ,EAAE;KAC5C,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exponent-labs/exponent-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "build/index.d.ts",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -10,28 +10,28 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@coral-xyz/anchor": "0.30.1",
|
|
13
|
-
"@exponent-labs/exponent-fetcher": "0.0
|
|
14
|
-
"@exponent-labs/exponent-idl": "0.0
|
|
15
|
-
"@exponent-labs/exponent-pda": "0.0
|
|
16
|
-
"@exponent-labs/generic-sy-idl": "0.0
|
|
17
|
-
"@exponent-labs/generic-sy-pda": "0.0
|
|
18
|
-
"@exponent-labs/generic-sy-sdk": "0.0
|
|
19
|
-
"@exponent-labs/jito-restaking-sy-idl": "0.0
|
|
20
|
-
"@exponent-labs/jito-restaking-sy-sdk": "0.0
|
|
21
|
-
"@exponent-labs/kamino-sy-sdk": "0.0
|
|
22
|
-
"@exponent-labs/marginfi-sy-pda": "0.0
|
|
23
|
-
"@exponent-labs/marginfi-sy-sdk": "0.0
|
|
24
|
-
"@exponent-labs/market-math": "0.0
|
|
25
|
-
"@exponent-labs/perena-sy-idl": "0.0
|
|
26
|
-
"@exponent-labs/perena-sy-pda": "0.0
|
|
27
|
-
"@exponent-labs/perena-sy-sdk": "0.0
|
|
13
|
+
"@exponent-labs/exponent-fetcher": "0.1.0",
|
|
14
|
+
"@exponent-labs/exponent-idl": "0.1.0",
|
|
15
|
+
"@exponent-labs/exponent-pda": "0.1.0",
|
|
16
|
+
"@exponent-labs/generic-sy-idl": "0.1.0",
|
|
17
|
+
"@exponent-labs/generic-sy-pda": "0.1.0",
|
|
18
|
+
"@exponent-labs/generic-sy-sdk": "0.1.0",
|
|
19
|
+
"@exponent-labs/jito-restaking-sy-idl": "0.1.0",
|
|
20
|
+
"@exponent-labs/jito-restaking-sy-sdk": "0.1.0",
|
|
21
|
+
"@exponent-labs/kamino-sy-sdk": "0.1.0",
|
|
22
|
+
"@exponent-labs/marginfi-sy-pda": "0.1.0",
|
|
23
|
+
"@exponent-labs/marginfi-sy-sdk": "0.1.0",
|
|
24
|
+
"@exponent-labs/market-math": "0.1.0",
|
|
25
|
+
"@exponent-labs/perena-sy-idl": "0.1.0",
|
|
26
|
+
"@exponent-labs/perena-sy-pda": "0.1.0",
|
|
27
|
+
"@exponent-labs/perena-sy-sdk": "0.1.0",
|
|
28
28
|
"@solana/spl-token": "0.4.8",
|
|
29
|
-
"@exponent-labs/precise-number": "0.0
|
|
30
|
-
"@exponent-labs/exponent-admin-pda": "0.0
|
|
31
|
-
"@exponent-labs/jito-restaking-sy-pda": "0.0
|
|
32
|
-
"@exponent-labs/kamino-sy-idl": "0.0
|
|
33
|
-
"@exponent-labs/exponent-types": "0.0
|
|
34
|
-
"@exponent-labs/kamino-sy-pda": "0.0
|
|
29
|
+
"@exponent-labs/precise-number": "0.1.0",
|
|
30
|
+
"@exponent-labs/exponent-admin-pda": "0.1.0",
|
|
31
|
+
"@exponent-labs/jito-restaking-sy-pda": "0.1.0",
|
|
32
|
+
"@exponent-labs/kamino-sy-idl": "0.1.0",
|
|
33
|
+
"@exponent-labs/exponent-types": "0.1.0",
|
|
34
|
+
"@exponent-labs/kamino-sy-pda": "0.1.0",
|
|
35
35
|
"bs58": "5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { CpiAccountIndex, CpiAccountIndexes } from "@exponent-labs/exponent-types"
|
|
3
4
|
|
|
4
5
|
/** Fetch and deserialize the ALT */
|
|
5
6
|
export async function fetchAddressLookupTable(
|
package/src/events.ts
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { BorshCoder, web3
|
|
1
|
+
import { BN, BorshCoder, web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import bs58 from "bs58"
|
|
3
|
+
|
|
2
4
|
import { ExponentCore, IDL } from "@exponent-labs/exponent-idl"
|
|
3
5
|
import { AnchorizedPNum } from "@exponent-labs/exponent-types"
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
const EVENT_IX_TAG = new BN("1d9acb512ea545e4", 16)
|
|
5
8
|
|
|
6
9
|
export class EventDecoder {
|
|
7
10
|
private coder: BorshCoder
|
|
8
11
|
programId: web3.PublicKey
|
|
9
|
-
private static eventIxTag =
|
|
10
|
-
private discriminators: Map<string, string>
|
|
12
|
+
private static eventIxTag = EVENT_IX_TAG
|
|
11
13
|
|
|
12
14
|
constructor(idl: ExponentCore = IDL as ExponentCore) {
|
|
13
15
|
this.programId = new web3.PublicKey(idl.address)
|
|
14
16
|
this.coder = new BorshCoder(idl)
|
|
15
|
-
this.discriminators = new Map<string, string>(
|
|
16
|
-
(idl.events ?? []).map((ev): [string, string] => [Buffer.from(ev.discriminator).toString("hex"), ev.name]),
|
|
17
|
-
)
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
parseAsTransactionCpiData(log: string): string | null {
|
|
21
|
-
let encodedLog: Buffer
|
|
22
20
|
try {
|
|
23
|
-
encodedLog = Buffer.from(bs58.decode(log))
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
const encodedLog = Buffer.from(bs58.decode(log))
|
|
22
|
+
const discriminator = encodedLog.subarray(0, 8)
|
|
23
|
+
|
|
24
|
+
const eventIxTagBuffer = Uint8Array.from(EventDecoder.eventIxTag.toBuffer("le", 8))
|
|
25
|
+
|
|
26
|
+
if (discriminator.equals(eventIxTagBuffer)) {
|
|
27
|
+
return Buffer.from(Uint8Array.from(encodedLog.subarray(8))).toString("base64")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error("Discriminator not found")
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Unable tp parse transaction CPI data:", error)
|
|
31
33
|
return null
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -42,34 +44,46 @@ export class EventDecoder {
|
|
|
42
44
|
const event = this.coder.events.decode(cpiData)
|
|
43
45
|
return {
|
|
44
46
|
name: event.name,
|
|
45
|
-
data: event,
|
|
47
|
+
data: event.data,
|
|
46
48
|
}
|
|
47
|
-
} catch (
|
|
48
|
-
console.error(`Failed to decode event:`,
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`Failed to decode event:`, error)
|
|
49
51
|
return null
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
parseCpiEvents(
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
async parseCpiEvents(
|
|
56
|
+
transactionResponse: web3.VersionedTransactionResponse | web3.TransactionResponse,
|
|
57
|
+
connection: web3.Connection,
|
|
58
|
+
): Promise<CategorizedEvents> {
|
|
59
|
+
const innerInstructions: web3.CompiledInnerInstruction[] = transactionResponse?.meta?.innerInstructions ?? []
|
|
60
|
+
|
|
61
|
+
const addressTableLookups = transactionResponse?.transaction.message.addressTableLookups
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
63
|
+
const lookupTables = await Promise.all(
|
|
64
|
+
addressTableLookups.map(async (lookup) => {
|
|
65
|
+
const lookupTable = await connection.getAddressLookupTable(lookup.accountKey)
|
|
66
|
+
return lookupTable
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
const instructions: web3.CompiledInstruction[] = innerInstructions.map(({ instructions }) => instructions).flat()
|
|
62
71
|
|
|
72
|
+
const events: GenericEvent[] = instructions
|
|
73
|
+
.map((ix) => {
|
|
74
|
+
const accountKeys = transactionResponse?.transaction.message.getAccountKeys({
|
|
75
|
+
addressLookupTableAccounts: lookupTables.map((lookup) => lookup.value),
|
|
76
|
+
})
|
|
77
|
+
const programPubkey = accountKeys.get(ix.programIdIndex)
|
|
63
78
|
if (programPubkey === undefined || !programPubkey.equals(this.programId)) {
|
|
64
|
-
|
|
79
|
+
return null
|
|
65
80
|
}
|
|
66
81
|
|
|
67
82
|
const event = this.decode(ix.data)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
83
|
+
|
|
84
|
+
return event || null
|
|
85
|
+
})
|
|
86
|
+
.filter((ev) => !!ev)
|
|
73
87
|
|
|
74
88
|
return categorizeEvents(events)
|
|
75
89
|
}
|
|
@@ -77,26 +91,26 @@ export class EventDecoder {
|
|
|
77
91
|
parseHeliusWebsocketCpiEvents(
|
|
78
92
|
transactionResponse: web3.VersionedTransactionResponse | web3.TransactionResponse,
|
|
79
93
|
): CategorizedEvents {
|
|
80
|
-
const events: GenericEvent[] = []
|
|
81
|
-
const
|
|
94
|
+
// const events: GenericEvent[] = []
|
|
95
|
+
const innerInstructions: web3.CompiledInnerInstruction[] = transactionResponse?.meta?.innerInstructions ?? []
|
|
82
96
|
|
|
83
|
-
|
|
84
|
-
for (let j = 0; j < inner[i].instructions.length; j++) {
|
|
85
|
-
const ix = inner[i].instructions[j]
|
|
97
|
+
const instructions: web3.CompiledInstruction[] = innerInstructions.map(({ instructions }) => instructions).flat()
|
|
86
98
|
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
const events: GenericEvent[] = instructions
|
|
100
|
+
.map((ix) => {
|
|
101
|
+
//! Is it safe? If helius adds a programId field, we need to use a modified CompiledInstruction interface
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
const programPubkey = new web3.PublicKey((ix as any).programId)
|
|
89
104
|
|
|
90
105
|
if (programPubkey === undefined || !programPubkey.equals(this.programId)) {
|
|
91
|
-
|
|
106
|
+
return null
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
const event = this.decode(ix.data)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
110
|
+
|
|
111
|
+
return event || null
|
|
112
|
+
})
|
|
113
|
+
.filter((ev) => !!ev)
|
|
100
114
|
|
|
101
115
|
return categorizeEvents(events)
|
|
102
116
|
}
|
|
@@ -104,6 +118,7 @@ export class EventDecoder {
|
|
|
104
118
|
|
|
105
119
|
interface GenericEvent {
|
|
106
120
|
name: string
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
122
|
data: any
|
|
108
123
|
}
|
|
109
124
|
|
package/src/flavors.ts
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { BN, web3 } from "@coral-xyz/anchor"
|
|
2
|
+
|
|
2
3
|
import { ExponentFetcher, fetchKaminoReserve } from "@exponent-labs/exponent-fetcher"
|
|
3
|
-
import { Environment } from "./environment"
|
|
4
|
-
import { MfiSySdk } from "@exponent-labs/marginfi-sy-sdk"
|
|
5
|
-
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
6
|
-
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
7
|
-
import { KlendSySdk } from "@exponent-labs/kamino-sy-sdk"
|
|
8
4
|
import {
|
|
9
|
-
FlavorKaminoStateJson,
|
|
10
|
-
FlavorKaminoState,
|
|
11
|
-
FlavorMarginfiState,
|
|
12
|
-
FlavorMarginfiStateJson,
|
|
13
|
-
FlavorKamino,
|
|
14
|
-
FlavorMarginfi,
|
|
15
|
-
FlavorDiscriminator,
|
|
16
|
-
MintSyArgs,
|
|
17
|
-
RedeemSyArgs,
|
|
18
|
-
Flavor,
|
|
19
5
|
CpiAccountsRaw,
|
|
6
|
+
Flavor,
|
|
7
|
+
FlavorDiscriminator,
|
|
8
|
+
FlavorGeneric,
|
|
9
|
+
FlavorGenericState,
|
|
10
|
+
FlavorGenericStateJson,
|
|
20
11
|
FlavorJitoRestaking,
|
|
21
12
|
FlavorJitoRestakingState,
|
|
22
13
|
FlavorJitoRestakingStateJson,
|
|
14
|
+
FlavorKamino,
|
|
15
|
+
FlavorKaminoState,
|
|
16
|
+
FlavorKaminoStateJson,
|
|
17
|
+
FlavorMarginfi,
|
|
18
|
+
FlavorMarginfiState,
|
|
19
|
+
FlavorMarginfiStateJson,
|
|
23
20
|
FlavorPerena,
|
|
24
21
|
FlavorPerenaState,
|
|
25
22
|
FlavorPerenaStateJson,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
InterfaceInstructionArgs,
|
|
29
|
-
FlavorGenericStateJson,
|
|
30
|
-
toInterfaceTypeGenericJson,
|
|
23
|
+
MintSyArgs,
|
|
24
|
+
RedeemSyArgs,
|
|
31
25
|
fromInterfaceTypeGenericJson,
|
|
26
|
+
toInterfaceTypeGenericJson,
|
|
32
27
|
} from "@exponent-labs/exponent-types"
|
|
28
|
+
import { GenericSySdk } from "@exponent-labs/generic-sy-sdk"
|
|
33
29
|
import { JitoRestakingSySdk } from "@exponent-labs/jito-restaking-sy-sdk"
|
|
34
|
-
import {
|
|
30
|
+
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
31
|
+
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
32
|
+
import { KlendSySdk } from "@exponent-labs/kamino-sy-sdk"
|
|
33
|
+
import { MfiSySdk } from "@exponent-labs/marginfi-sy-sdk"
|
|
35
34
|
import { PerenaSySdk } from "@exponent-labs/perena-sy-sdk"
|
|
36
|
-
import {
|
|
35
|
+
import { PreciseNumber } from "@exponent-labs/precise-number"
|
|
36
|
+
|
|
37
|
+
import { Environment } from "./environment"
|
|
37
38
|
|
|
38
39
|
export function serializeFlavorMarginfi(flavor: FlavorMarginfiState): FlavorMarginfiStateJson {
|
|
39
40
|
return {
|
|
@@ -303,7 +304,7 @@ export function deserializeFlavorJitoRestaking(flavor: FlavorJitoRestakingStateJ
|
|
|
303
304
|
}
|
|
304
305
|
}
|
|
305
306
|
|
|
306
|
-
export function
|
|
307
|
+
export function serializeFlavorPerena(flavor: FlavorPerenaState): FlavorPerenaStateJson {
|
|
307
308
|
return {
|
|
308
309
|
flavor: "perena",
|
|
309
310
|
currentSyExchangeRate: flavor.currentSyExchangeRate,
|
|
@@ -388,7 +389,7 @@ export function serializeFlavorGeneric(flavor: FlavorGenericState): FlavorGeneri
|
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
391
|
|
|
391
|
-
export function
|
|
392
|
+
export function deserializeFlavorPerena(flavor: FlavorPerenaStateJson): FlavorPerenaState {
|
|
392
393
|
return {
|
|
393
394
|
flavor: "perena",
|
|
394
395
|
currentSyExchangeRate: flavor.currentSyExchangeRate,
|
|
@@ -482,8 +483,8 @@ export function makeFlavorMarginfiSync(data: FlavorMarginfiState): FlavorMarginf
|
|
|
482
483
|
flavor: "marginfi",
|
|
483
484
|
ixMintSy: (args) => mfiSySdk.ixMintSy(args),
|
|
484
485
|
ixRedeemSy: (args) => mfiSySdk.ixRedeemSy(args),
|
|
485
|
-
preIxs: async (
|
|
486
|
-
postIxs: async (
|
|
486
|
+
preIxs: async () => [],
|
|
487
|
+
postIxs: async () => [],
|
|
487
488
|
}
|
|
488
489
|
}
|
|
489
490
|
|
|
@@ -508,8 +509,8 @@ export function makeFlavorJitoRestakingSync(data: FlavorJitoRestakingState): Fla
|
|
|
508
509
|
flavor: "jitoRestaking",
|
|
509
510
|
ixMintSy: (args) => jitoSdk.ixMintSy(args),
|
|
510
511
|
ixRedeemSy: (args) => jitoSdk.ixRedeemSy(args),
|
|
511
|
-
preIxs: async (
|
|
512
|
-
postIxs: async (
|
|
512
|
+
preIxs: async () => [],
|
|
513
|
+
postIxs: async () => [],
|
|
513
514
|
}
|
|
514
515
|
}
|
|
515
516
|
|
|
@@ -622,8 +623,8 @@ async function makeMarginfiFlavor(
|
|
|
622
623
|
mfiSyState: mfiSySdk.state,
|
|
623
624
|
emissionMint: mapOptAccount(emissionMint),
|
|
624
625
|
emissionTokenProgram: mapOptAccount(emissionTokenProgram),
|
|
625
|
-
preIxs: async (
|
|
626
|
-
postIxs: async (
|
|
626
|
+
preIxs: async () => [],
|
|
627
|
+
postIxs: async () => [],
|
|
627
628
|
}
|
|
628
629
|
}
|
|
629
630
|
|
|
@@ -632,9 +633,6 @@ async function makeKaminoFlavor(
|
|
|
632
633
|
kaminoSyProgramId: web3.PublicKey,
|
|
633
634
|
cpiAccounts: CpiAccountsRaw,
|
|
634
635
|
): Promise<FlavorKamino> {
|
|
635
|
-
const isNone = (x: web3.PublicKey) => x.equals(kaminoSyProgramId)
|
|
636
|
-
const mapOptAccount = (x: web3.PublicKey) => (isNone(x) ? undefined : x)
|
|
637
|
-
|
|
638
636
|
// TODO - I do not like hard-coding these magic numbers
|
|
639
637
|
const reserve = cpiAccounts.getSyState[0].pubkey
|
|
640
638
|
const reserveAcct = await fetchKaminoReserve(reserve, fetcher.connection)
|
|
@@ -685,7 +683,6 @@ async function makeJitoRestakingFlavor(
|
|
|
685
683
|
): Promise<FlavorJitoRestaking> {
|
|
686
684
|
// TODO - I do not like hard-coding these magic numbers
|
|
687
685
|
const jitoVault = cpiAccounts.getSyState[1].pubkey
|
|
688
|
-
// const recentBlockhash = await fetcher.connection.getLatestBlockhash().then((b) => b.blockhash)
|
|
689
686
|
|
|
690
687
|
const jitoSdk = await JitoRestakingSySdk.load({
|
|
691
688
|
cnx: fetcher.connection,
|
|
@@ -757,9 +754,6 @@ async function makeGenericFlavor(
|
|
|
757
754
|
config: syConfig,
|
|
758
755
|
})
|
|
759
756
|
|
|
760
|
-
let preIxs = []
|
|
761
|
-
let postIxs = []
|
|
762
|
-
|
|
763
757
|
return {
|
|
764
758
|
flavor: "generic",
|
|
765
759
|
currentSyExchangeRate: sySdk.state.syRate,
|
|
@@ -767,8 +761,8 @@ async function makeGenericFlavor(
|
|
|
767
761
|
baseTokenProgram: sySdk.tokenProgramBase,
|
|
768
762
|
ixMintSy: (args) => sySdk.ixMintSy(args),
|
|
769
763
|
ixRedeemSy: (args) => sySdk.ixRedeemSy(args),
|
|
770
|
-
preIxs: async () =>
|
|
771
|
-
postIxs: async () =>
|
|
764
|
+
preIxs: async () => [],
|
|
765
|
+
postIxs: async () => [],
|
|
772
766
|
genericSyState: sySdk.state,
|
|
773
767
|
emissions: sySdk.emissions.map((e) => ({
|
|
774
768
|
exchangeRate: e.index,
|
package/src/lpPosition.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AnchorProvider, Program, web3 } from "@coral-xyz/anchor"
|
|
2
|
-
|
|
3
|
-
import { Environment } from "./environment"
|
|
4
|
-
import { ExponentCore, IDL } from "@exponent-labs/exponent-idl"
|
|
2
|
+
|
|
5
3
|
import { ExponentFetcher } from "@exponent-labs/exponent-fetcher"
|
|
4
|
+
import { ExponentCore, IDL } from "@exponent-labs/exponent-idl"
|
|
5
|
+
import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
6
6
|
import { PreciseNumber } from "@exponent-labs/precise-number"
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import { Environment } from "./environment"
|
|
9
|
+
import { Market, MyWallet } from "./market"
|
|
8
10
|
|
|
9
11
|
export interface EmissionTracker {
|
|
10
12
|
lastSeenIndex: number
|
|
@@ -32,25 +34,51 @@ export class LpPosition {
|
|
|
32
34
|
this.coreProgram = new Program(IDL as ExponentCore, new AnchorProvider(connection, mockWallet))
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
static async load(env: Environment, connection: web3.Connection, address: web3.PublicKey) {
|
|
37
|
+
static async load(env: Environment, connection: web3.Connection, address: web3.PublicKey, market?: Market) {
|
|
36
38
|
const fetcher = new ExponentFetcher({ connection })
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
owner:
|
|
41
|
-
balanceLp:
|
|
42
|
-
market,
|
|
43
|
-
emissionTrackers:
|
|
44
|
-
farms:
|
|
39
|
+
const fetchedLpPosition = await fetcher.fetchLpPosition(address)
|
|
40
|
+
const loadedMarket = market ?? (await Market.load(env, connection, fetchedLpPosition.market))
|
|
41
|
+
const lpPositionState: LpPositionState = {
|
|
42
|
+
owner: fetchedLpPosition.owner,
|
|
43
|
+
balanceLp: fetchedLpPosition.lpBalance,
|
|
44
|
+
market: loadedMarket,
|
|
45
|
+
emissionTrackers: fetchedLpPosition.emissions,
|
|
46
|
+
farms: fetchedLpPosition.farms,
|
|
45
47
|
fetcher: fetcher,
|
|
46
48
|
}
|
|
47
|
-
return new LpPosition(env, connection, address,
|
|
49
|
+
return new LpPosition(env, connection, address, lpPositionState)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static async loadAllByOwner(
|
|
53
|
+
env: Environment,
|
|
54
|
+
connection: web3.Connection,
|
|
55
|
+
owner: web3.PublicKey,
|
|
56
|
+
markets: (Market | web3.PublicKey)[],
|
|
57
|
+
) {
|
|
58
|
+
const pda = new ExponentPDA(env.coreProgramId)
|
|
59
|
+
const addresses = markets.map((m) =>
|
|
60
|
+
pda.marketLpPosition({
|
|
61
|
+
market: m instanceof web3.PublicKey ? m : m.selfAddress,
|
|
62
|
+
owner,
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const positionPromises = addresses.map((addr) => {
|
|
67
|
+
try {
|
|
68
|
+
return LpPosition.load(env, connection, addr)
|
|
69
|
+
} catch {
|
|
70
|
+
return Promise.resolve(null)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const positions = await Promise.all(positionPromises)
|
|
75
|
+
return positions.filter((p): p is LpPosition => p !== null)
|
|
48
76
|
}
|
|
49
77
|
|
|
50
|
-
async reload(
|
|
51
|
-
const
|
|
52
|
-
this.state =
|
|
53
|
-
return
|
|
78
|
+
async reload(connection = this.connection) {
|
|
79
|
+
const lpPosition = await LpPosition.load(this.env, connection, this.selfAddress)
|
|
80
|
+
this.state = lpPosition.state
|
|
81
|
+
return lpPosition
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
get lpBalance() {
|
|
@@ -92,9 +120,9 @@ export class LpPosition {
|
|
|
92
120
|
const marketFarm = this.state.market.state.lpFarm.farmEmissions[marketFarmIndex]
|
|
93
121
|
const positionFarm = this.state.farms[marketFarmIndex]
|
|
94
122
|
|
|
95
|
-
const
|
|
123
|
+
const timeNow = new Date().getTime() / 1000
|
|
96
124
|
|
|
97
|
-
const deltaTimeFarm =
|
|
125
|
+
const deltaTimeFarm = timeNow - this.marketSdk.state.lpFarm.lastSeenTimestamp
|
|
98
126
|
const lpStakedTotal = this.marketSdk.state.lpEscrowAmount
|
|
99
127
|
const tokensEmitted = Number(marketFarm.tokenRate) * deltaTimeFarm
|
|
100
128
|
const increaseAmount = Number(tokensEmitted) / Number(lpStakedTotal)
|
|
@@ -110,7 +138,7 @@ export class LpPosition {
|
|
|
110
138
|
async getClaimableMarketEmissions() {
|
|
111
139
|
const syPosition = this.marketSdk.state.syPosition
|
|
112
140
|
|
|
113
|
-
return this.state.market.emissions.map((
|
|
141
|
+
return this.state.market.emissions.map((_, index) => {
|
|
114
142
|
const marketEmission = this.state.market.marketEmissions.trackers[index]
|
|
115
143
|
const positionEmission = this.state.emissionTrackers[index]
|
|
116
144
|
if (!positionEmission) return 0
|