@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/src/syPosition.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
-
|
|
3
|
-
makeFlavorJitoRestakingSync,
|
|
4
|
-
makeFlavorKaminoSync,
|
|
5
|
-
makeFlavorMarginfiSync,
|
|
6
|
-
makeFlavorPerenaSync,
|
|
7
|
-
} from "./flavors"
|
|
2
|
+
|
|
8
3
|
import { ExponentFetcher, SyPosition } from "@exponent-labs/exponent-fetcher"
|
|
9
|
-
import { MarginfiSyPda } from "@exponent-labs/marginfi-sy-pda"
|
|
10
|
-
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
11
|
-
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
12
|
-
import { JitoRestakingSyPda } from "@exponent-labs/jito-restaking-sy-pda"
|
|
13
|
-
import { PROGRAM_ID as PERENA_STANDARD_PROGRAM_ID } from "@exponent-labs/perena-sy-idl"
|
|
14
|
-
import { PROGRAM_ID as GENERIC_STANDARD_PROGRAM_ID } from "@exponent-labs/generic-sy-idl"
|
|
15
4
|
import {
|
|
16
|
-
|
|
17
|
-
FlavorKamino,
|
|
18
|
-
SyPositionJson,
|
|
19
|
-
IFlavorState,
|
|
5
|
+
FlavorGeneric,
|
|
20
6
|
FlavorJitoRestaking,
|
|
7
|
+
FlavorKamino,
|
|
8
|
+
FlavorMarginfi,
|
|
21
9
|
FlavorPerena,
|
|
22
|
-
|
|
10
|
+
IFlavorState,
|
|
11
|
+
SyPositionJson,
|
|
23
12
|
} from "@exponent-labs/exponent-types"
|
|
13
|
+
import { PROGRAM_ID as GENERIC_STANDARD_PROGRAM_ID } from "@exponent-labs/generic-sy-idl"
|
|
14
|
+
import { GenericSyPda } from "@exponent-labs/generic-sy-pda"
|
|
24
15
|
import { PROGRAM_ID as JITO_RESTAKING_SY_PROGRAM_ID } from "@exponent-labs/jito-restaking-sy-idl"
|
|
16
|
+
import { JitoRestakingSyPda } from "@exponent-labs/jito-restaking-sy-pda"
|
|
17
|
+
import { PROGRAM_ID as KAMINO_STANDARD_PROGRAM_ID } from "@exponent-labs/kamino-sy-idl"
|
|
18
|
+
import { KaminoSyPda } from "@exponent-labs/kamino-sy-pda"
|
|
19
|
+
import { MarginfiSyPda } from "@exponent-labs/marginfi-sy-pda"
|
|
20
|
+
import { PROGRAM_ID as PERENA_STANDARD_PROGRAM_ID } from "@exponent-labs/perena-sy-idl"
|
|
25
21
|
import { PerenaSyPda } from "@exponent-labs/perena-sy-pda"
|
|
26
|
-
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
makeFlavorJitoRestakingSync,
|
|
25
|
+
makeFlavorKaminoSync,
|
|
26
|
+
makeFlavorMarginfiSync,
|
|
27
|
+
makeFlavorPerenaSync,
|
|
28
|
+
} from "./flavors"
|
|
27
29
|
|
|
28
30
|
export function deserializeSyPosition(syPosition: SyPositionJson): SyPosition {
|
|
29
31
|
return {
|
|
@@ -37,11 +39,11 @@ export function deserializeSyPosition(syPosition: SyPositionJson): SyPosition {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
export function
|
|
42
|
+
export function serializeSyPosition(syPosition: SyPosition): SyPositionJson {
|
|
41
43
|
return {
|
|
42
|
-
balanceSy:
|
|
43
|
-
owner:
|
|
44
|
-
emissions:
|
|
44
|
+
balanceSy: syPosition.balanceSy.toString(),
|
|
45
|
+
owner: syPosition.owner.toString(),
|
|
46
|
+
emissions: syPosition.emissions.map((emission) => ({
|
|
45
47
|
...emission,
|
|
46
48
|
mint: emission.mint.toString(),
|
|
47
49
|
staged: emission.staged.toString(),
|
|
@@ -58,16 +60,24 @@ export async function makeSyPosition(
|
|
|
58
60
|
if (flavor.flavor === "marginfi") {
|
|
59
61
|
const marginfiFlavor = makeFlavorMarginfiSync(flavor)
|
|
60
62
|
return makeSyPositionMarginfi(fetcher, syProgramId, marginfiFlavor, owner)
|
|
61
|
-
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (flavor.flavor === "kamino") {
|
|
62
66
|
const kaminoFlavor = makeFlavorKaminoSync(flavor)
|
|
63
67
|
return makeSyPositionKamino(fetcher, kaminoFlavor, owner)
|
|
64
|
-
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (flavor.flavor === "jitoRestaking") {
|
|
65
71
|
const jitoRestakingFlavor = makeFlavorJitoRestakingSync(flavor)
|
|
66
72
|
return makeSyPositionJitoRestaking(fetcher, jitoRestakingFlavor, owner)
|
|
67
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (flavor.flavor === "perena") {
|
|
68
76
|
const perenaFlavor = makeFlavorPerenaSync(flavor)
|
|
69
77
|
return makeSyPositionPerena(fetcher, perenaFlavor, owner)
|
|
70
|
-
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (flavor.flavor === "generic") {
|
|
71
81
|
return makeSyPositionGeneric(fetcher, flavor as FlavorGeneric, owner)
|
|
72
82
|
}
|
|
73
83
|
|
|
@@ -142,6 +152,8 @@ async function makeSyPositionGeneric(
|
|
|
142
152
|
interfaceIndex = 3 // InterfaceType.Fragmetric
|
|
143
153
|
} else if ("meteora" in interfaceType) {
|
|
144
154
|
interfaceIndex = 4 // InterfaceType.Meteora
|
|
155
|
+
} else if ("fragmetricSupportedAsset" in interfaceType) {
|
|
156
|
+
interfaceIndex = 5 // InterfaceType.FragmetricSupportedAsset
|
|
145
157
|
} else {
|
|
146
158
|
throw new Error("Unsupported interface type")
|
|
147
159
|
}
|
package/src/tokenUtil.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
-
import { CpiAccountsRaw, CpiAccountsRawJson } from "@exponent-labs/exponent-types"
|
|
3
2
|
import { MintLayout } from "@solana/spl-token"
|
|
4
3
|
|
|
5
|
-
export async function getMintSupply(
|
|
6
|
-
const mintInfo = await
|
|
4
|
+
export async function getMintSupply(connection: web3.Connection, address: web3.PublicKey): Promise<bigint> {
|
|
5
|
+
const mintInfo = await connection.getAccountInfo(address)
|
|
7
6
|
if (mintInfo === null) {
|
|
8
7
|
throw new Error("Failed to find mint account")
|
|
9
8
|
}
|
|
10
9
|
return MintLayout.decode(mintInfo.data).supply
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export async function getMultipleMintSupply(
|
|
14
|
-
|
|
12
|
+
export async function getMultipleMintSupply(
|
|
13
|
+
connection: web3.Connection,
|
|
14
|
+
addresses: web3.PublicKey[],
|
|
15
|
+
): Promise<bigint[]> {
|
|
16
|
+
const mintInfos = await connection.getMultipleAccountsInfo(addresses)
|
|
15
17
|
return mintInfos.map((mintInfo) => {
|
|
16
18
|
if (mintInfo === null) {
|
|
17
19
|
throw new Error("Failed to find mint account")
|
package/src/utils/altUtil.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as web3 from "@solana/web3.js"
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { AccountInfo, CpiAccountIndex, CpiAccountIndexes, CpiAccountsRaw } from "@exponent-labs/exponent-types"
|
|
3
4
|
|
|
4
5
|
export function extendAddressLookupTable(
|
|
5
6
|
oldAlt: web3.PublicKey[],
|
|
6
|
-
|
|
7
|
+
cpiAccountsRaw: CpiAccountsRaw,
|
|
7
8
|
): {
|
|
8
9
|
cpiAccountIndexes: CpiAccountIndexes
|
|
9
10
|
addressLookupTableExtension: web3.PublicKey[]
|
|
10
11
|
} {
|
|
11
|
-
const allPubkeys = getAllPubkeysFromCpiAccountsRaw(
|
|
12
|
+
const allPubkeys = getAllPubkeysFromCpiAccountsRaw(cpiAccountsRaw)
|
|
12
13
|
|
|
13
14
|
const newPubkeys = allPubkeys.filter((p) => !oldAlt.some((o) => o.equals(p)))
|
|
14
15
|
const addressLookupTableExtension = Array.from(new Set(newPubkeys))
|
|
@@ -26,11 +27,11 @@ export function extendAddressLookupTable(
|
|
|
26
27
|
})
|
|
27
28
|
|
|
28
29
|
const cpiAccountIndexes: CpiAccountIndexes = {
|
|
29
|
-
getSyState:
|
|
30
|
-
withdrawSy:
|
|
31
|
-
depositSy:
|
|
32
|
-
claimEmission:
|
|
33
|
-
getPositionState:
|
|
30
|
+
getSyState: cpiAccountsRaw.getSyState.map(toCpiAccountIndex),
|
|
31
|
+
withdrawSy: cpiAccountsRaw.withdrawSy.map(toCpiAccountIndex),
|
|
32
|
+
depositSy: cpiAccountsRaw.depositSy.map(toCpiAccountIndex),
|
|
33
|
+
claimEmission: cpiAccountsRaw.claimEmission.map((a) => a.map(toCpiAccountIndex)),
|
|
34
|
+
getPositionState: cpiAccountsRaw.getPositionState.map(toCpiAccountIndex),
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
return {
|
|
@@ -40,8 +41,12 @@ export function extendAddressLookupTable(
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/** Get all pubkeys from CpiAccountsRaw */
|
|
43
|
-
export function getAllPubkeysFromCpiAccountsRaw(
|
|
44
|
-
return [
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
export function getAllPubkeysFromCpiAccountsRaw(cpiAccountsRaw: CpiAccountsRaw): web3.PublicKey[] {
|
|
45
|
+
return [
|
|
46
|
+
...cpiAccountsRaw.getSyState,
|
|
47
|
+
...cpiAccountsRaw.withdrawSy,
|
|
48
|
+
...cpiAccountsRaw.depositSy,
|
|
49
|
+
...cpiAccountsRaw.claimEmission.flat(),
|
|
50
|
+
...cpiAccountsRaw.getPositionState,
|
|
51
|
+
].map((a) => a.pubkey)
|
|
47
52
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
|
|
2
3
|
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
4
|
+
|
|
3
5
|
export { InstructionAccounts } from "./ix"
|
|
4
6
|
|
|
5
7
|
export function uniqueRemainingAccounts(xs: web3.AccountMeta[]): web3.AccountMeta[] {
|
package/src/vault.ts
CHANGED
|
@@ -1,52 +1,65 @@
|
|
|
1
|
-
import { BN, Program, web3
|
|
2
|
-
import {
|
|
1
|
+
import { AnchorProvider, BN, Program, web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import {
|
|
3
|
+
TOKEN_PROGRAM_ID,
|
|
4
|
+
createAssociatedTokenAccountIdempotentInstruction,
|
|
5
|
+
getAssociatedTokenAddressSync,
|
|
6
|
+
} from "@solana/spl-token"
|
|
7
|
+
|
|
8
|
+
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
9
|
+
import { ExponentFetcher, deserializeEmission, serializeEmission } from "@exponent-labs/exponent-fetcher"
|
|
10
|
+
import { ExponentCore, IDL } from "@exponent-labs/exponent-idl"
|
|
11
|
+
import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
12
|
+
import {
|
|
13
|
+
AnchorizedPNum,
|
|
14
|
+
CpiAccountsRaw,
|
|
15
|
+
VaultEmission,
|
|
16
|
+
VaultJson,
|
|
17
|
+
VaultState,
|
|
18
|
+
deserializeCpiAccountsRaw,
|
|
19
|
+
serializeCpiAccountsRaw,
|
|
20
|
+
} from "@exponent-labs/exponent-types"
|
|
21
|
+
import { ClaimAmount } from "@exponent-labs/marginfi-sy-sdk"
|
|
22
|
+
|
|
3
23
|
import { fetchAddressLookupTable, makeCpiAccountMetaLists } from "./addressLookupTableUtil"
|
|
24
|
+
import { Environment } from "./environment"
|
|
4
25
|
import {
|
|
5
26
|
deserializeFlavorGeneric,
|
|
27
|
+
deserializeFlavorJitoRestaking,
|
|
6
28
|
deserializeFlavorKamino,
|
|
7
29
|
deserializeFlavorMarginfi,
|
|
8
|
-
|
|
9
|
-
deserializeFlavorJitoRestaking,
|
|
30
|
+
deserializeFlavorPerena,
|
|
10
31
|
makeFlavor,
|
|
11
32
|
makeFlavorGenericSync,
|
|
33
|
+
makeFlavorJitoRestakingSync,
|
|
12
34
|
makeFlavorKaminoSync,
|
|
13
35
|
makeFlavorMarginfiSync,
|
|
14
36
|
makeFlavorPerenaSync,
|
|
15
|
-
makeFlavorJitoRestakingSync,
|
|
16
37
|
serializeFlavorGeneric,
|
|
17
38
|
serializeFlavorJitoRestaking,
|
|
18
39
|
serializeFlavorKamino,
|
|
19
40
|
serializeFlavorMarginfi,
|
|
20
|
-
|
|
41
|
+
serializeFlavorPerena,
|
|
21
42
|
} from "./flavors"
|
|
22
|
-
import { Environment } from "./environment"
|
|
23
|
-
import {
|
|
24
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
25
|
-
getAssociatedTokenAddressSync,
|
|
26
|
-
TOKEN_PROGRAM_ID,
|
|
27
|
-
} from "@solana/spl-token"
|
|
28
|
-
import { deserializeSyPosition, makeSyPosition, serializeSyPostion } from "./syPosition"
|
|
29
|
-
import { ExponentCore, IDL } from "@exponent-labs/exponent-idl"
|
|
30
|
-
import { emitEventAuthority, InstructionAccounts, uniqueRemainingAccounts } from "./utils"
|
|
31
|
-
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
32
|
-
import { ExponentPDA } from "@exponent-labs/exponent-pda"
|
|
33
43
|
import { MyWallet } from "./market"
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
44
|
+
import { deserializeSyPosition, makeSyPosition, serializeSyPosition } from "./syPosition"
|
|
45
|
+
import { InstructionAccounts, emitEventAuthority, uniqueRemainingAccounts } from "./utils"
|
|
36
46
|
import { extendAddressLookupTable } from "./utils/altUtil"
|
|
37
|
-
import { ClaimAmount } from "@exponent-labs/marginfi-sy-sdk"
|
|
38
47
|
|
|
39
48
|
export type CollectTreasuryEmissionKind =
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
40
50
|
| { yieldPosition: {} }
|
|
41
51
|
| {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
42
53
|
treasuryEmission: {}
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
export type CollectTreasuryInterestKind =
|
|
46
57
|
| {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
47
59
|
yieldPosition: {}
|
|
48
60
|
}
|
|
49
61
|
| {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
50
63
|
treasuryInterest: {}
|
|
51
64
|
}
|
|
52
65
|
|
|
@@ -92,8 +105,8 @@ export class Vault {
|
|
|
92
105
|
)
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
static loadFromJson(
|
|
96
|
-
const state = toVaultState(
|
|
108
|
+
static loadFromJson(vaultJson: VaultJson, address: web3.PublicKey, env: Environment, connection: web3.Connection) {
|
|
109
|
+
const state = toVaultState(vaultJson)
|
|
97
110
|
return new Vault(state, address, env, connection)
|
|
98
111
|
}
|
|
99
112
|
|
|
@@ -104,52 +117,53 @@ export class Vault {
|
|
|
104
117
|
options: VaultLoadOptions = {},
|
|
105
118
|
) {
|
|
106
119
|
const fetcher = new ExponentFetcher({ connection })
|
|
107
|
-
const
|
|
120
|
+
const vault = await fetcher.fetchVault(address)
|
|
121
|
+
|
|
108
122
|
|
|
109
|
-
const alt = await fetchAddressLookupTable(connection,
|
|
110
|
-
const cpiAccounts = makeCpiAccountMetaLists(alt,
|
|
111
|
-
const flavor = await makeFlavor(fetcher, env,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const syPosition = await makeSyPosition(fetcher, flavor, v.syProgram, v.authority)
|
|
123
|
+
const alt = await fetchAddressLookupTable(connection, vault.addressLookupTable)
|
|
124
|
+
const cpiAccounts = makeCpiAccountMetaLists(alt, vault.cpiAccounts)
|
|
125
|
+
const flavor = await makeFlavor(fetcher, env, vault.syProgram, cpiAccounts, options.syConfig)
|
|
126
|
+
|
|
127
|
+
const syPosition = await makeSyPosition(fetcher, flavor, vault.syProgram, vault.authority)
|
|
115
128
|
|
|
116
129
|
const state: VaultState = {
|
|
117
|
-
ptSupply:
|
|
118
|
-
syForPt:
|
|
119
|
-
startTs:
|
|
120
|
-
durationSeconds:
|
|
121
|
-
authority:
|
|
122
|
-
addressLookupTable:
|
|
123
|
-
lastSeenSyExchangeRate:
|
|
124
|
-
allTimeHighSyExchangeRate:
|
|
125
|
-
syProgram:
|
|
126
|
-
mintPt:
|
|
127
|
-
mintSy:
|
|
128
|
-
mintYt:
|
|
129
|
-
escrowSy:
|
|
130
|
-
escrowYt:
|
|
131
|
-
|
|
130
|
+
ptSupply: vault.ptSupply,
|
|
131
|
+
syForPt: vault.syForPt,
|
|
132
|
+
startTs: vault.startTs,
|
|
133
|
+
durationSeconds: vault.duration,
|
|
134
|
+
authority: vault.authority,
|
|
135
|
+
addressLookupTable: vault.addressLookupTable,
|
|
136
|
+
lastSeenSyExchangeRate: vault.lastSeenSyExchangeRate,
|
|
137
|
+
allTimeHighSyExchangeRate: vault.allTimeHighSyExchangeRate,
|
|
138
|
+
syProgram: vault.syProgram,
|
|
139
|
+
mintPt: vault.mintPt,
|
|
140
|
+
mintSy: vault.mintSy,
|
|
141
|
+
mintYt: vault.mintYt,
|
|
142
|
+
escrowSy: vault.escrowSy,
|
|
143
|
+
escrowYt: vault.escrowYt,
|
|
144
|
+
// Misspelled word
|
|
145
|
+
yieldPositonAddress: vault.yieldPosition,
|
|
132
146
|
cpiAccounts,
|
|
133
147
|
flavor,
|
|
134
148
|
syPosition,
|
|
135
|
-
totalSyInEscrow:
|
|
136
|
-
treasurySyTokenAccount:
|
|
137
|
-
interestBpsFee:
|
|
138
|
-
emissions:
|
|
139
|
-
minOperationSizeStrip:
|
|
140
|
-
minOperationSizeMerge:
|
|
141
|
-
status:
|
|
142
|
-
finalSyExchangeRate:
|
|
143
|
-
maxPySupply:
|
|
149
|
+
totalSyInEscrow: vault.totalSyInEscrow,
|
|
150
|
+
treasurySyTokenAccount: vault.treasurySyTokenAccount,
|
|
151
|
+
interestBpsFee: vault.interestBpsFee,
|
|
152
|
+
emissions: vault.emissions,
|
|
153
|
+
minOperationSizeStrip: vault.minOpSizeStrip,
|
|
154
|
+
minOperationSizeMerge: vault.minOpSizeMerge,
|
|
155
|
+
status: vault.status,
|
|
156
|
+
finalSyExchangeRate: vault.finalSyExchangeRate,
|
|
157
|
+
maxPySupply: vault.maxPySupply,
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
return new Vault(state, address, env, connection)
|
|
147
161
|
}
|
|
148
162
|
|
|
149
|
-
async reload(
|
|
150
|
-
const
|
|
151
|
-
this.state =
|
|
152
|
-
return
|
|
163
|
+
async reload(connection: web3.Connection = this.connection) {
|
|
164
|
+
const vault = await Vault.load(this.env, connection, this.selfAddress)
|
|
165
|
+
this.state = vault.state
|
|
166
|
+
return vault
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
toJson(): VaultJson {
|
|
@@ -177,9 +191,11 @@ export class Vault {
|
|
|
177
191
|
totalSyInEscrow: this.state.totalSyInEscrow.toString(),
|
|
178
192
|
cpiAccounts: serializeCpiAccountsRaw(this.state.cpiAccounts),
|
|
179
193
|
status: this.state.status,
|
|
180
|
-
|
|
194
|
+
// Misspelled word
|
|
195
|
+
syPosition: serializeSyPosition(this.state.syPosition),
|
|
181
196
|
minOperationSizeStrip: this.state.minOperationSizeStrip.toString(),
|
|
182
197
|
minOperationSizeMerge: this.state.minOperationSizeMerge.toString(),
|
|
198
|
+
// Misspelled word
|
|
183
199
|
yieldPositonAddress: this.state.yieldPositonAddress.toString(),
|
|
184
200
|
interestFeeBps: this.state.interestBpsFee,
|
|
185
201
|
flavor: (() => {
|
|
@@ -191,7 +207,7 @@ export class Vault {
|
|
|
191
207
|
case "jitoRestaking":
|
|
192
208
|
return serializeFlavorJitoRestaking(this.state.flavor)
|
|
193
209
|
case "perena":
|
|
194
|
-
return
|
|
210
|
+
return serializeFlavorPerena(this.state.flavor)
|
|
195
211
|
case "generic":
|
|
196
212
|
return serializeFlavorGeneric(this.state.flavor)
|
|
197
213
|
default:
|
|
@@ -380,10 +396,10 @@ export class Vault {
|
|
|
380
396
|
async ixStripFromBase({
|
|
381
397
|
owner,
|
|
382
398
|
amountBase,
|
|
383
|
-
baseSrc,
|
|
384
|
-
sySrc,
|
|
385
|
-
ptDst,
|
|
386
|
-
ytDst,
|
|
399
|
+
baseSrc: baseSrcParam,
|
|
400
|
+
sySrc: sySrcParam,
|
|
401
|
+
ptDst: ptDstParam,
|
|
402
|
+
ytDst: ytDstParam,
|
|
387
403
|
}: {
|
|
388
404
|
owner: web3.PublicKey
|
|
389
405
|
amountBase: bigint
|
|
@@ -392,10 +408,10 @@ export class Vault {
|
|
|
392
408
|
ptDst?: web3.PublicKey
|
|
393
409
|
ytDst?: web3.PublicKey
|
|
394
410
|
}): Promise<web3.TransactionInstruction> {
|
|
395
|
-
baseSrc =
|
|
396
|
-
sySrc =
|
|
397
|
-
ptDst =
|
|
398
|
-
ytDst =
|
|
411
|
+
const baseSrc = baseSrcParam || getAssociatedTokenAddressSync(this.mintPt, owner, true, TOKEN_PROGRAM_ID)
|
|
412
|
+
const sySrc = sySrcParam || getAssociatedTokenAddressSync(this.mintSy, owner, true, TOKEN_PROGRAM_ID)
|
|
413
|
+
const ptDst = ptDstParam || getAssociatedTokenAddressSync(this.mintPt, owner, true, TOKEN_PROGRAM_ID)
|
|
414
|
+
const ytDst = ytDstParam || getAssociatedTokenAddressSync(this.mintYt, owner, true, TOKEN_PROGRAM_ID)
|
|
399
415
|
|
|
400
416
|
const mintSyIx = await this.state.flavor.ixMintSy({
|
|
401
417
|
amountBase: "0",
|
|
@@ -439,9 +455,9 @@ export class Vault {
|
|
|
439
455
|
async ixMergeToBase({
|
|
440
456
|
owner,
|
|
441
457
|
amountPy,
|
|
442
|
-
ptSrc,
|
|
443
|
-
ytSrc,
|
|
444
|
-
syDst,
|
|
458
|
+
ptSrc: ptSrcParam,
|
|
459
|
+
ytSrc: ytSrcParam,
|
|
460
|
+
syDst: syDstParam,
|
|
445
461
|
baseDst,
|
|
446
462
|
}: {
|
|
447
463
|
owner: web3.PublicKey
|
|
@@ -451,9 +467,9 @@ export class Vault {
|
|
|
451
467
|
syDst?: web3.PublicKey
|
|
452
468
|
baseDst?: web3.PublicKey
|
|
453
469
|
}): Promise<{ ixs: web3.TransactionInstruction[]; setupIxs: web3.TransactionInstruction[] }> {
|
|
454
|
-
syDst =
|
|
455
|
-
ptSrc =
|
|
456
|
-
ytSrc =
|
|
470
|
+
const syDst = syDstParam || getAssociatedTokenAddressSync(this.mintSy, owner, true, TOKEN_PROGRAM_ID)
|
|
471
|
+
const ptSrc = ptSrcParam || getAssociatedTokenAddressSync(this.mintPt, owner, true, TOKEN_PROGRAM_ID)
|
|
472
|
+
const ytSrc = ytSrcParam || getAssociatedTokenAddressSync(this.mintYt, owner, true, TOKEN_PROGRAM_ID)
|
|
457
473
|
|
|
458
474
|
const tokenSyTraderAtaIx = createAssociatedTokenAccountIdempotentInstruction(owner, syDst, owner, this.mintSy)
|
|
459
475
|
const tokenPtTraderAtaIx = createAssociatedTokenAccountIdempotentInstruction(owner, ptSrc, owner, this.mintPt)
|
|
@@ -560,7 +576,7 @@ export class Vault {
|
|
|
560
576
|
collectEmissionAccounts({
|
|
561
577
|
emissionIndex,
|
|
562
578
|
owner,
|
|
563
|
-
emissionDst,
|
|
579
|
+
emissionDst: emissionDstParam,
|
|
564
580
|
}: {
|
|
565
581
|
emissionIndex: number
|
|
566
582
|
owner: web3.PublicKey
|
|
@@ -581,7 +597,8 @@ export class Vault {
|
|
|
581
597
|
const emissionEscrow = vaultE.tokenAccount
|
|
582
598
|
const treasuryEmissionTokenAccount = vaultE.treasuryTokenAccount
|
|
583
599
|
const position = this.pda.yieldPosition({ owner, vault: this.selfAddress })
|
|
584
|
-
emissionDst =
|
|
600
|
+
const emissionDst =
|
|
601
|
+
emissionDstParam || getAssociatedTokenAddressSync(syE.mint, owner, true, syE.tokenProgramAddress)
|
|
585
602
|
const remainingAccounts = uniqueRemainingAccounts([...this.cpiAccounts.claimEmission[emissionIndex]])
|
|
586
603
|
|
|
587
604
|
return {
|
|
@@ -605,20 +622,20 @@ export class Vault {
|
|
|
605
622
|
|
|
606
623
|
stripAccounts({
|
|
607
624
|
depositor,
|
|
608
|
-
ptDst,
|
|
609
|
-
ytDst,
|
|
610
|
-
sySrc,
|
|
625
|
+
ptDst: ptDstParam,
|
|
626
|
+
ytDst: ytDstParam,
|
|
627
|
+
sySrc: sySrcParam,
|
|
611
628
|
}: {
|
|
612
629
|
depositor: web3.PublicKey
|
|
613
630
|
ptDst?: web3.PublicKey
|
|
614
631
|
ytDst?: web3.PublicKey
|
|
615
632
|
sySrc?: web3.PublicKey
|
|
616
633
|
}): InstructionAccounts<StripAccounts> {
|
|
617
|
-
ptDst =
|
|
618
|
-
ytDst =
|
|
619
|
-
sySrc =
|
|
634
|
+
const ptDst = ptDstParam || getAssociatedTokenAddressSync(this.mintPt, depositor, true, TOKEN_PROGRAM_ID)
|
|
635
|
+
const ytDst = ytDstParam || getAssociatedTokenAddressSync(this.mintYt, depositor, true, TOKEN_PROGRAM_ID)
|
|
636
|
+
const sySrc = sySrcParam || getAssociatedTokenAddressSync(this.mintSy, depositor, true, TOKEN_PROGRAM_ID)
|
|
620
637
|
|
|
621
|
-
console.log("sysrc account: ", sySrc.toBase58())
|
|
638
|
+
// console.log("sysrc account: ", sySrc.toBase58())
|
|
622
639
|
|
|
623
640
|
const remainingAccounts = uniqueRemainingAccounts([...this.cpiAccounts.depositSy])
|
|
624
641
|
|
|
@@ -757,12 +774,12 @@ export class Vault {
|
|
|
757
774
|
|
|
758
775
|
collectInterestAccounts({
|
|
759
776
|
owner,
|
|
760
|
-
syDst,
|
|
777
|
+
syDst: syDstParam,
|
|
761
778
|
}: {
|
|
762
779
|
owner: web3.PublicKey
|
|
763
780
|
syDst?: web3.PublicKey
|
|
764
781
|
}): InstructionAccounts<CollectInterestAccounts> {
|
|
765
|
-
syDst =
|
|
782
|
+
const syDst = syDstParam || getAssociatedTokenAddressSync(this.mintSy, owner, true, TOKEN_PROGRAM_ID)
|
|
766
783
|
const yieldPosition = this.pda.yieldPosition({ owner, vault: this.selfAddress })
|
|
767
784
|
const remainingAccounts = [...this.cpiAccounts.withdrawSy]
|
|
768
785
|
|
|
@@ -788,18 +805,18 @@ export class Vault {
|
|
|
788
805
|
/** Construct accounts for Merge instruction */
|
|
789
806
|
mergeAccounts({
|
|
790
807
|
owner,
|
|
791
|
-
ptSrc,
|
|
792
|
-
ytSrc,
|
|
793
|
-
syDst,
|
|
808
|
+
ptSrc: ptSrcParam,
|
|
809
|
+
ytSrc: ytSrcParam,
|
|
810
|
+
syDst: syDstParam,
|
|
794
811
|
}: {
|
|
795
812
|
owner: web3.PublicKey
|
|
796
813
|
ptSrc?: web3.PublicKey
|
|
797
814
|
ytSrc?: web3.PublicKey
|
|
798
815
|
syDst?: web3.PublicKey
|
|
799
816
|
}): InstructionAccounts<MergeAccounts> {
|
|
800
|
-
ptSrc =
|
|
801
|
-
ytSrc =
|
|
802
|
-
syDst =
|
|
817
|
+
const ptSrc = ptSrcParam || getAssociatedTokenAddressSync(this.mintPt, owner, true, TOKEN_PROGRAM_ID)
|
|
818
|
+
const ytSrc = ytSrcParam || getAssociatedTokenAddressSync(this.mintYt, owner, true, TOKEN_PROGRAM_ID)
|
|
819
|
+
const syDst = syDstParam || getAssociatedTokenAddressSync(this.mintSy, owner, true, TOKEN_PROGRAM_ID)
|
|
803
820
|
const remainingAccounts = [...this.cpiAccounts.getSyState, ...this.cpiAccounts.withdrawSy]
|
|
804
821
|
return {
|
|
805
822
|
mainAccounts: {
|
|
@@ -891,7 +908,7 @@ function toVaultState(vault: VaultJson): VaultState {
|
|
|
891
908
|
case "jitoRestaking":
|
|
892
909
|
return makeFlavorJitoRestakingSync(deserializeFlavorJitoRestaking(vault.flavor))
|
|
893
910
|
case "perena":
|
|
894
|
-
return makeFlavorPerenaSync(
|
|
911
|
+
return makeFlavorPerenaSync(deserializeFlavorPerena(vault.flavor))
|
|
895
912
|
case "generic":
|
|
896
913
|
return makeFlavorGenericSync(deserializeFlavorGeneric(vault.flavor))
|
|
897
914
|
default:
|