diff --git a/sdk/src/client.ts b/sdk/src/client.ts index 9b3553e..430447e 100644 --- a/sdk/src/client.ts +++ b/sdk/src/client.ts @@ -53,7 +53,7 @@ export class VaultClient { private vaultState: Vault, private solend: SolendReserveAsset, private port: PortReserveAsset, - private jet: JetReserveAsset, + // private jet: JetReserveAsset, private reserveToken: Token, private lpToken: Token, private feesEnabled: boolean = false @@ -83,7 +83,7 @@ export class VaultClient { cluster, reserveMint ); - const jet = await JetReserveAsset.load(provider, cluster, reserveMint); + // const jet = await JetReserveAsset.load(provider, cluster, reserveMint); const [reserveToken, lpToken] = await this.getReserveAndLpTokens( provider.connection, @@ -96,7 +96,7 @@ export class VaultClient { vaultState, solend, port, - jet, + // jet, reserveToken, lpToken ); @@ -269,7 +269,7 @@ export class VaultClient { vaultState, solend, port, - jet, + // jet, reserveToken, lpToken ); @@ -304,62 +304,62 @@ export class VaultClient { return [reserveToken, lpToken]; } - getRefreshIx(): TransactionInstruction { - // Port does not accept an oracle as input if the reserve is denominated - // in the same token as the market quote currency (USDC). - // We account for this by passing in an argument that indicates whether - // or not to use the given oracle value. - let usePortOracle = true; - let portOracle = this.port.accounts.oracle; - if (portOracle == null) { - usePortOracle = false; - portOracle = Keypair.generate().publicKey; - } - - const feeAccounts = this.feesEnabled - ? [ - { - isSigner: false, - isWritable: true, - pubkey: this.vaultState.feeReceiver, - }, - { - isSigner: false, - isWritable: true, - pubkey: this.vaultState.referralFeeReceiver, - }, - ] - : []; - - return this.program.instruction.refresh(usePortOracle, { - accounts: { - vault: this.vaultId, - vaultAuthority: this.vaultState.vaultAuthority, - vaultReserveToken: this.vaultState.vaultReserveToken, - vaultSolendLpToken: this.vaultState.vaultSolendLpToken, - vaultPortLpToken: this.vaultState.vaultPortLpToken, - vaultJetLpToken: this.vaultState.vaultJetLpToken, - lpTokenMint: this.vaultState.lpTokenMint, - solendProgram: this.solend.accounts.program, - solendReserve: this.solend.accounts.reserve, - solendPyth: this.solend.accounts.pythPrice, - solendSwitchboard: this.solend.accounts.switchboardFeed, - portProgram: this.port.accounts.program, - portReserve: this.port.accounts.reserve, - portOracle: portOracle, - jetProgram: this.jet.accounts.program, - jetMarket: this.jet.accounts.market, - jetMarketAuthority: this.jet.accounts.marketAuthority, - jetReserve: this.jet.accounts.reserve, - jetFeeNoteVault: this.jet.accounts.feeNoteVault, - jetDepositNoteMint: this.jet.accounts.depositNoteMint, - jetPyth: this.jet.accounts.pythPrice, - tokenProgram: TOKEN_PROGRAM_ID, - clock: SYSVAR_CLOCK_PUBKEY, - }, - remainingAccounts: feeAccounts, - }); - } + // getRefreshIx(): TransactionInstruction { + // // Port does not accept an oracle as input if the reserve is denominated + // // in the same token as the market quote currency (USDC). + // // We account for this by passing in an argument that indicates whether + // // or not to use the given oracle value. + // let usePortOracle = true; + // let portOracle = this.port.accounts.oracle; + // if (portOracle == null) { + // usePortOracle = false; + // portOracle = Keypair.generate().publicKey; + // } + + // const feeAccounts = this.feesEnabled + // ? [ + // { + // isSigner: false, + // isWritable: true, + // pubkey: this.vaultState.feeReceiver, + // }, + // { + // isSigner: false, + // isWritable: true, + // pubkey: this.vaultState.referralFeeReceiver, + // }, + // ] + // : []; + + // return this.program.instruction.refresh(usePortOracle, { + // accounts: { + // vault: this.vaultId, + // vaultAuthority: this.vaultState.vaultAuthority, + // vaultReserveToken: this.vaultState.vaultReserveToken, + // vaultSolendLpToken: this.vaultState.vaultSolendLpToken, + // vaultPortLpToken: this.vaultState.vaultPortLpToken, + // vaultJetLpToken: this.vaultState.vaultJetLpToken, + // lpTokenMint: this.vaultState.lpTokenMint, + // solendProgram: this.solend.accounts.program, + // solendReserve: this.solend.accounts.reserve, + // solendPyth: this.solend.accounts.pythPrice, + // solendSwitchboard: this.solend.accounts.switchboardFeed, + // portProgram: this.port.accounts.program, + // portReserve: this.port.accounts.reserve, + // portOracle: portOracle, + // jetProgram: this.jet.accounts.program, + // jetMarket: this.jet.accounts.market, + // jetMarketAuthority: this.jet.accounts.marketAuthority, + // jetReserve: this.jet.accounts.reserve, + // jetFeeNoteVault: this.jet.accounts.feeNoteVault, + // jetDepositNoteMint: this.jet.accounts.depositNoteMint, + // jetPyth: this.jet.accounts.pythPrice, + // tokenProgram: TOKEN_PROGRAM_ID, + // clock: SYSVAR_CLOCK_PUBKEY, + // }, + // remainingAccounts: feeAccounts, + // }); + // } /** * @@ -510,7 +510,7 @@ export class VaultClient { ); } - depositTx.add(this.getRefreshIx()); + // depositTx.add(this.getRefreshIx()); depositTx.add( this.getDepositIx( new anchor.BN(amount), @@ -606,7 +606,8 @@ export class VaultClient { } } - withdrawTx.add(this.getRefreshIx()); + // NOTE - commented out so Jet doesn't blow anything up + // withdrawTx.add(this.getRefreshIx()); withdrawTx.add( this.getWithdrawIx( new anchor.BN(amount), @@ -672,14 +673,14 @@ export class VaultClient { ).lamports, this.getReconcilePortIx.bind(this), ], - [ - ( - await this.jet.getLpTokenAccountValue( - this.vaultState.vaultJetLpToken - ) - ).lamports, - this.getReconcileJetIx.bind(this), - ], + // [ + // ( + // await this.jet.getLpTokenAccountValue( + // this.vaultState.vaultJetLpToken + // ) + // ).lamports, + // this.getReconcileJetIx.bind(this), + // ], ].sort((a, b) => b[0].sub(a[0]).toNumber()); const toReconcileAmount = convertedAmount.sub(vaultReserveAmount); @@ -696,7 +697,7 @@ export class VaultClient { if (!Big(0).eq(reconcileAmount)) { const reconcileTx = new Transaction(); - reconcileTx.add(this.getRefreshIx()); + // reconcileTx.add(this.getRefreshIx()); reconcileTx.add( ix(new anchor.BN(reconcileAmount.toString())) ); @@ -712,14 +713,15 @@ export class VaultClient { getRebalanceTx(proposedWeights: ProposedWeightsBps): Transaction { const rebalanceTx = new Transaction(); - rebalanceTx.add(this.getRefreshIx()); + // rebalanceTx.add(this.getRefreshIx()); rebalanceTx.add( this.program.instruction.rebalance(proposedWeights, { accounts: { vault: this.vaultId, solendReserve: this.solend.accounts.reserve, portReserve: this.port.accounts.reserve, - jetReserve: this.jet.accounts.reserve, + // jetReserve: this.jet.accounts.reserve, + jetReserve: this.port.accounts.reserve, clock: SYSVAR_CLOCK_PUBKEY, }, }) @@ -732,84 +734,84 @@ export class VaultClient { * @param proposedWeights * @returns */ - async rebalance( - proposedWeights?: ProposedWeightsBps - ): Promise { - if ( - this.getRebalanceMode() == RebalanceModes.proofChecker && - proposedWeights == null - ) { - throw new Error( - "Proposed weights must be passed in for a vault running in proofChecker mode" - ); - } - - // Sort ixs in descending order of outflows - const newAllocations = ( - await this.program.simulate.rebalance(proposedWeights, { - accounts: { - vault: this.vaultId, - solendReserve: this.solend.accounts.reserve, - portReserve: this.port.accounts.reserve, - jetReserve: this.jet.accounts.reserve, - clock: SYSVAR_CLOCK_PUBKEY, - }, - instructions: [this.getRefreshIx()], - }) - ).events[1].data as RebalanceDataEvent; - - const newAndOldallocationsWithReconcileIxs = [ - [ - new Big(newAllocations.solend.toString()), - ( - await this.solend.getLpTokenAccountValue( - this.vaultState.vaultSolendLpToken - ) - ).lamports, - this.getReconcileSolendIx.bind(this), - ], - [ - new Big(newAllocations.port.toString()), - ( - await this.port.getLpTokenAccountValue( - this.vaultState.vaultPortLpToken - ) - ).lamports, - this.getReconcilePortIx.bind(this), - ], - [ - new Big(newAllocations.jet.toString()), - ( - await this.jet.getLpTokenAccountValue( - this.vaultState.vaultJetLpToken - ) - ).lamports, - this.getReconcileJetIx.bind(this), - ], - ]; - - const allocationDiffsWithReconcileIxs: [Big, TransactionInstruction][] = - newAndOldallocationsWithReconcileIxs.map((e) => [ - e[0].sub(e[1]), - e[2](), - ]); - - const reconcileIxs = allocationDiffsWithReconcileIxs - .sort((a, b) => a[0].sub(b[0]).toNumber()) - .map((e) => e[1]); - - const txs: SendTxRequest[] = [ - { tx: this.getRebalanceTx(proposedWeights), signers: [] }, - ]; - - for (const ix of reconcileIxs) { - const reconcileTx = new Transaction(); - reconcileTx.add(this.getRefreshIx()); - reconcileTx.add(ix); - txs.push({ tx: reconcileTx, signers: [] }); - } - return this.program.provider.sendAll(txs); - } + // async rebalance( + // proposedWeights?: ProposedWeightsBps + // ): Promise { + // if ( + // this.getRebalanceMode() == RebalanceModes.proofChecker && + // proposedWeights == null + // ) { + // throw new Error( + // "Proposed weights must be passed in for a vault running in proofChecker mode" + // ); + // } + + // // Sort ixs in descending order of outflows + // const newAllocations = ( + // await this.program.simulate.rebalance(proposedWeights, { + // accounts: { + // vault: this.vaultId, + // solendReserve: this.solend.accounts.reserve, + // portReserve: this.port.accounts.reserve, + // jetReserve: this.jet.accounts.reserve, + // clock: SYSVAR_CLOCK_PUBKEY, + // }, + // instructions: [this.getRefreshIx()], + // }) + // ).events[1].data as RebalanceDataEvent; + + // const newAndOldallocationsWithReconcileIxs = [ + // [ + // new Big(newAllocations.solend.toString()), + // ( + // await this.solend.getLpTokenAccountValue( + // this.vaultState.vaultSolendLpToken + // ) + // ).lamports, + // this.getReconcileSolendIx.bind(this), + // ], + // [ + // new Big(newAllocations.port.toString()), + // ( + // await this.port.getLpTokenAccountValue( + // this.vaultState.vaultPortLpToken + // ) + // ).lamports, + // this.getReconcilePortIx.bind(this), + // ], + // // [ + // // new Big(newAllocations.jet.toString()), + // // ( + // // await this.jet.getLpTokenAccountValue( + // // this.vaultState.vaultJetLpToken + // // ) + // // ).lamports, + // // this.getReconcileJetIx.bind(this), + // // ], + // ]; + + // const allocationDiffsWithReconcileIxs: [Big, TransactionInstruction][] = + // newAndOldallocationsWithReconcileIxs.map((e) => [ + // e[0].sub(e[1]), + // e[2](), + // ]); + + // const reconcileIxs = allocationDiffsWithReconcileIxs + // .sort((a, b) => a[0].sub(b[0]).toNumber()) + // .map((e) => e[1]); + + // const txs: SendTxRequest[] = [ + // { tx: this.getRebalanceTx(proposedWeights), signers: [] }, + // ]; + + // for (const ix of reconcileIxs) { + // const reconcileTx = new Transaction(); + // reconcileTx.add(this.getRefreshIx()); + // reconcileTx.add(ix); + // txs.push({ tx: reconcileTx, signers: [] }); + // } + // return this.program.provider.sendAll(txs); + // } private getReconcilePortIx( withdrawOption: anchor.BN = new anchor.BN(0) @@ -832,25 +834,25 @@ export class VaultClient { }); } - private getReconcileJetIx( - withdrawOption: anchor.BN = new anchor.BN(0) - ): TransactionInstruction { - return this.program.instruction.reconcileJet(withdrawOption, { - accounts: { - vault: this.vaultId, - vaultAuthority: this.vaultState.vaultAuthority, - vaultReserveToken: this.vaultState.vaultReserveToken, - vaultJetLpToken: this.vaultState.vaultJetLpToken, - jetProgram: this.jet.accounts.program, - jetMarket: this.jet.accounts.market, - jetMarketAuthority: this.jet.accounts.marketAuthority, - jetReserve: this.jet.accounts.reserve, - jetReserveToken: this.jet.accounts.liquiditySupply, - jetLpMint: this.jet.accounts.depositNoteMint, - tokenProgram: TOKEN_PROGRAM_ID, - }, - }); - } + // private getReconcileJetIx( + // withdrawOption: anchor.BN = new anchor.BN(0) + // ): TransactionInstruction { + // return this.program.instruction.reconcileJet(withdrawOption, { + // accounts: { + // vault: this.vaultId, + // vaultAuthority: this.vaultState.vaultAuthority, + // vaultReserveToken: this.vaultState.vaultReserveToken, + // vaultJetLpToken: this.vaultState.vaultJetLpToken, + // jetProgram: this.jet.accounts.program, + // jetMarket: this.jet.accounts.market, + // jetMarketAuthority: this.jet.accounts.marketAuthority, + // jetReserve: this.jet.accounts.reserve, + // jetReserveToken: this.jet.accounts.liquiditySupply, + // jetLpMint: this.jet.accounts.depositNoteMint, + // tokenProgram: TOKEN_PROGRAM_ID, + // }, + // }); + // } private getReconcileSolendIx( withdrawOption: anchor.BN = new anchor.BN(0) @@ -900,14 +902,14 @@ export class VaultClient { ) ).lamports, ], - [ - await this.jet.getApy(), - ( - await this.jet.getLpTokenAccountValue( - this.vaultState.vaultJetLpToken - ) - ).lamports, - ], + // [ + // await this.jet.getApy(), + // ( + // await this.jet.getLpTokenAccountValue( + // this.vaultState.vaultJetLpToken + // ) + // ).lamports, + // ], ]; const [valueSum, weightSum] = assetApysAndValues.reduce( ([valueSum, weightSum], [value, weight]) => [ @@ -955,7 +957,7 @@ export class VaultClient { this.vaultState.vaultSolendLpToken ), this.port.getLpTokenAccountValue(this.vaultState.vaultPortLpToken), - this.jet.getLpTokenAccountValue(this.vaultState.vaultJetLpToken), + // this.jet.getLpTokenAccountValue(this.vaultState.vaultJetLpToken), this.getVaultReserveTokenAccountValue(), ]); @@ -1000,11 +1002,11 @@ export class VaultClient { ); } - async getVaultJetLpTokenAccountValue(): Promise { - return this.jet.getLpTokenAccountValue( - this.getVaultJetLpTokenAccount() - ); - } + // async getVaultJetLpTokenAccountValue(): Promise { + // return this.jet.getLpTokenAccountValue( + // this.getVaultJetLpTokenAccount() + // ); + // } /** * Calculates the ATA given the user's address and vault mint @@ -1147,9 +1149,9 @@ export class VaultClient { return this.port; } - getJet(): JetReserveAsset { - return this.jet; - } + // getJet(): JetReserveAsset { + // return this.jet; + // } getReferralFeeSplit(): Rate { return Rate.fromPercent(this.vaultState.config.referralFeePct);