From d150870474f0275f77bbe1425d5247219ae9276a Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 14:48:31 +0200 Subject: [PATCH 1/7] export the U64_MAX const --- packages/kamino-sdk/src/utils/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kamino-sdk/src/utils/index.ts b/packages/kamino-sdk/src/utils/index.ts index 235d544f..bd0818da 100644 --- a/packages/kamino-sdk/src/utils/index.ts +++ b/packages/kamino-sdk/src/utils/index.ts @@ -6,3 +6,4 @@ export * from './math'; export * from './types'; export * from './orca'; export * from './instructions'; +export * from './consts'; From 87579b082c53ddfee48f658d8a75a16951e12db9 Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 16:02:21 +0200 Subject: [PATCH 2/7] test u64_max --- packages/kamino-sdk/package-lock.json | 10 +++++----- packages/kamino-sdk/src/Kamino.ts | 2 ++ packages/kamino-sdk/tests/stratCreation.test.ts | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/kamino-sdk/package-lock.json b/packages/kamino-sdk/package-lock.json index 1ed02201..d6697009 100644 --- a/packages/kamino-sdk/package-lock.json +++ b/packages/kamino-sdk/package-lock.json @@ -6,11 +6,11 @@ "packages": { "": { "name": "@hubbleprotocol/kamino-sdk", - "version": "3.0.10", + "version": "3.0.25", "license": "Apache-2.0", "dependencies": { "@hubbleprotocol/hubble-config": "^3.0.0", - "@hubbleprotocol/hubble-idl": "^3.0.10", + "@hubbleprotocol/hubble-idl": "^3.0.20", "@hubbleprotocol/scope-sdk": "^3.0.6", "@jup-ag/api": "^6.0.1", "@jup-ag/core": "=3.0.0-beta.18", @@ -470,9 +470,9 @@ } }, "node_modules/@hubbleprotocol/hubble-idl": { - "version": "3.0.10", - "resolved": "https://registry.npmjs.org/@hubbleprotocol/hubble-idl/-/hubble-idl-3.0.10.tgz", - "integrity": "sha512-evGUuPxqy9rQceOdCNu90GQxJ2egwdphwiKcP7KHWANr8VVhKJgP7rmxW9O9OZY/uBF8L0ARQnGagK2w1rK4WQ==" + "version": "3.0.20", + "resolved": "https://registry.npmjs.org/@hubbleprotocol/hubble-idl/-/hubble-idl-3.0.20.tgz", + "integrity": "sha512-1zh9oiGrLeVbbYFMDGq/E23l5xFieLLkOO81dfh7UzFM3eUTyf8h0IqbTXlqcL5/Nu1KnTgKlryjziCBH2+lGA==" }, "node_modules/@hubbleprotocol/scope-sdk": { "version": "3.0.6", diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 41202eca..525a1f56 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -2927,6 +2927,8 @@ export class Kamino { * @returns transaction instruction for removing SOL from the topup vault */ withdrawTopupVault = async (owner: PublicKey, amount: Decimal): Promise => { + console.log("siliu"); + console.log("amount", amount.toString()); if (amount.lessThanOrEqualTo(0)) { throw Error('Must withdraw a positive amount of SOL.'); } diff --git a/packages/kamino-sdk/tests/stratCreation.test.ts b/packages/kamino-sdk/tests/stratCreation.test.ts index 82a50c74..b1f4c4a5 100644 --- a/packages/kamino-sdk/tests/stratCreation.test.ts +++ b/packages/kamino-sdk/tests/stratCreation.test.ts @@ -6,7 +6,7 @@ import { TransactionInstruction, VersionedTransaction, } from '@solana/web3.js'; -import { Kamino, OrcaService, RaydiumService, sendTransactionWithLogs, sleep } from '../src'; +import { Kamino, OrcaService, RaydiumService, sendTransactionWithLogs, sleep, U64_MAX } from '../src'; import Decimal from 'decimal.js'; import { createTransactionWithExtraBudget } from '../src'; import { @@ -39,7 +39,7 @@ describe('Kamino strategy creation SDK Tests', () => { const signerPrivateKey = []; const signer = Keypair.fromSecretKey(Uint8Array.from(signerPrivateKey)); - it('calculate amounts', async () => { + it('withdraw topup vault', async () => { let kamino = new Kamino( cluster, connection, @@ -49,6 +49,16 @@ describe('Kamino strategy creation SDK Tests', () => { RAYDIUM_PROGRAM_ID ); + console.log("foo"); + let x = new Decimal(U64_MAX); + console.log("x", x.toString()); + const upkeepIxn = await kamino.withdrawTopupVault( + new PublicKey('Cfuy5T6osdazUeLego5LFycBQebm9PP3H7VNdCndXXEN'), + new Decimal(U64_MAX) + ); + }); + + it('calculate amounts', async () => { let amounts = await kamino.calculateAmountsToBeDepositedWithSwap( new PublicKey('Cfuy5T6osdazUeLego5LFycBQebm9PP3H7VNdCndXXEN'), new Decimal(0), From 32fb3e2d748f14c301243200aff9bb18ae7e1968 Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 16:13:45 +0200 Subject: [PATCH 3/7] fix const declaration --- packages/kamino-sdk/src/Kamino.ts | 5 +---- packages/kamino-sdk/src/constants/numericalValues.ts | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 packages/kamino-sdk/src/constants/numericalValues.ts diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 525a1f56..3c1609e1 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -164,7 +164,7 @@ import BN from 'bn.js'; import StrategyWithAddress from './models/StrategyWithAddress'; import { Idl, Program, Provider } from '@project-serum/anchor'; import { Rebalancing, Uninitialized } from './kamino-client/types/StrategyStatus'; -import { FRONTEND_KAMINO_STRATEGY_URL, METADATA_PROGRAM_ID } from './constants'; +import { FRONTEND_KAMINO_STRATEGY_URL, METADATA_PROGRAM_ID, U64_MAX } from './constants'; import { CollateralInfo, ExecutiveWithdrawActionKind, @@ -329,7 +329,6 @@ import { } from './rebalance_methods/autodriftRebalance'; import { KaminoPrices, OraclePricesAndCollateralInfos } from './models'; import { getRemoveLiquidityQuote } from './whirpools-client/shim/remove-liquidity'; -import { U64_MAX } from './utils/consts'; export const KAMINO_IDL = KaminoIdl; export class Kamino { @@ -2927,8 +2926,6 @@ export class Kamino { * @returns transaction instruction for removing SOL from the topup vault */ withdrawTopupVault = async (owner: PublicKey, amount: Decimal): Promise => { - console.log("siliu"); - console.log("amount", amount.toString()); if (amount.lessThanOrEqualTo(0)) { throw Error('Must withdraw a positive amount of SOL.'); } diff --git a/packages/kamino-sdk/src/constants/numericalValues.ts b/packages/kamino-sdk/src/constants/numericalValues.ts new file mode 100644 index 00000000..ea552ce4 --- /dev/null +++ b/packages/kamino-sdk/src/constants/numericalValues.ts @@ -0,0 +1 @@ +export const U64_MAX = "18446744073709551615"; From c07c9f631848261fb4d6f0c4908d2baefcae843e Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 16:18:45 +0200 Subject: [PATCH 4/7] fix prettier --- packages/kamino-sdk/src/constants/numericalValues.ts | 2 +- packages/kamino-sdk/tests/stratCreation.test.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/kamino-sdk/src/constants/numericalValues.ts b/packages/kamino-sdk/src/constants/numericalValues.ts index ea552ce4..51458dd0 100644 --- a/packages/kamino-sdk/src/constants/numericalValues.ts +++ b/packages/kamino-sdk/src/constants/numericalValues.ts @@ -1 +1 @@ -export const U64_MAX = "18446744073709551615"; +export const U64_MAX = '18446744073709551615'; diff --git a/packages/kamino-sdk/tests/stratCreation.test.ts b/packages/kamino-sdk/tests/stratCreation.test.ts index b1f4c4a5..fce6b1ef 100644 --- a/packages/kamino-sdk/tests/stratCreation.test.ts +++ b/packages/kamino-sdk/tests/stratCreation.test.ts @@ -39,7 +39,7 @@ describe('Kamino strategy creation SDK Tests', () => { const signerPrivateKey = []; const signer = Keypair.fromSecretKey(Uint8Array.from(signerPrivateKey)); - it('withdraw topup vault', async () => { + it.skip('withdraw topup vault', async () => { let kamino = new Kamino( cluster, connection, @@ -49,9 +49,6 @@ describe('Kamino strategy creation SDK Tests', () => { RAYDIUM_PROGRAM_ID ); - console.log("foo"); - let x = new Decimal(U64_MAX); - console.log("x", x.toString()); const upkeepIxn = await kamino.withdrawTopupVault( new PublicKey('Cfuy5T6osdazUeLego5LFycBQebm9PP3H7VNdCndXXEN'), new Decimal(U64_MAX) From 7aadde71972e68bec063577b145d244bda25a6c2 Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 16:22:51 +0200 Subject: [PATCH 5/7] fix deps --- packages/kamino-sdk/src/constants/index.ts | 1 + packages/kamino-sdk/src/utils/consts.ts | 1 - packages/kamino-sdk/src/utils/index.ts | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 packages/kamino-sdk/src/utils/consts.ts diff --git a/packages/kamino-sdk/src/constants/index.ts b/packages/kamino-sdk/src/constants/index.ts index 83dd70c2..e0871037 100644 --- a/packages/kamino-sdk/src/constants/index.ts +++ b/packages/kamino-sdk/src/constants/index.ts @@ -1,2 +1,3 @@ export * from './frontend'; export * from './metadata'; +export * from './numericalValues'; diff --git a/packages/kamino-sdk/src/utils/consts.ts b/packages/kamino-sdk/src/utils/consts.ts deleted file mode 100644 index ac81e62f..00000000 --- a/packages/kamino-sdk/src/utils/consts.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const U64_MAX = '18446744073709551615'; diff --git a/packages/kamino-sdk/src/utils/index.ts b/packages/kamino-sdk/src/utils/index.ts index bd0818da..235d544f 100644 --- a/packages/kamino-sdk/src/utils/index.ts +++ b/packages/kamino-sdk/src/utils/index.ts @@ -6,4 +6,3 @@ export * from './math'; export * from './types'; export * from './orca'; export * from './instructions'; -export * from './consts'; From ee254ea2a8462586e642991d34ef245fe4ec2745 Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 20:53:18 +0200 Subject: [PATCH 6/7] fix colltolamports --- packages/kamino-sdk/src/Kamino.ts | 10 ++++++++-- packages/kamino-sdk/tests/stratCreation.test.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 3c1609e1..84365a42 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -2930,12 +2930,18 @@ export class Kamino { throw Error('Must withdraw a positive amount of SOL.'); } const topupVault = this.getUserTopupVault(owner); + console.log('topupVault', topupVault.toString()); + + const solBalance = await this._connection.getBalance(topupVault); + console.log('solBalance', solBalance.toString()); let solToWithdraw: Decimal; if (amount.eq(new Decimal(U64_MAX))) { - solToWithdraw = lamportsToNumberDecimal(new Decimal(await this._connection.getBalance(topupVault)), DECIMALS_SOL); + solToWithdraw = new Decimal(await this._connection.getBalance(topupVault)); + + console.log('solToWithdraw', solToWithdraw.toString()); } else { - solToWithdraw = lamportsToNumberDecimal(amount, DECIMALS_SOL); + solToWithdraw = collToLamportsDecimal(amount, DECIMALS_SOL); } const args: WithdrawFromTopupArgs = { diff --git a/packages/kamino-sdk/tests/stratCreation.test.ts b/packages/kamino-sdk/tests/stratCreation.test.ts index fce6b1ef..1375b8f4 100644 --- a/packages/kamino-sdk/tests/stratCreation.test.ts +++ b/packages/kamino-sdk/tests/stratCreation.test.ts @@ -50,9 +50,18 @@ describe('Kamino strategy creation SDK Tests', () => { ); const upkeepIxn = await kamino.withdrawTopupVault( - new PublicKey('Cfuy5T6osdazUeLego5LFycBQebm9PP3H7VNdCndXXEN'), + new PublicKey('HzZH5jHVUPsw3qawUcQXG1SZJqNom3gt94eFHCWhq1KF'), new Decimal(U64_MAX) ); + + let ixs: TransactionInstruction[] = [upkeepIxn]; + console.log('ixs', ixs.length); + const createStratTx = await kamino.getTransactionV2Message(signer.publicKey, ixs); + const createStratTransactionV0 = new VersionedTransaction(createStratTx); + createStratTransactionV0.sign([signer]); + //@ts-ignore + let txHash = await sendAndConfirmTransaction(kamino._connection, createStratTransactionV0); + console.log('create strategy tx hash', txHash); }); it('calculate amounts', async () => { From 3823d15d913b68ef3c565af727571a407b152470 Mon Sep 17 00:00:00 2001 From: Silviu Troscot Date: Wed, 3 Jan 2024 20:54:31 +0200 Subject: [PATCH 7/7] remove logs --- packages/kamino-sdk/src/Kamino.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 84365a42..08fdbfc6 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -2930,16 +2930,12 @@ export class Kamino { throw Error('Must withdraw a positive amount of SOL.'); } const topupVault = this.getUserTopupVault(owner); - console.log('topupVault', topupVault.toString()); const solBalance = await this._connection.getBalance(topupVault); - console.log('solBalance', solBalance.toString()); let solToWithdraw: Decimal; if (amount.eq(new Decimal(U64_MAX))) { solToWithdraw = new Decimal(await this._connection.getBalance(topupVault)); - - console.log('solToWithdraw', solToWithdraw.toString()); } else { solToWithdraw = collToLamportsDecimal(amount, DECIMALS_SOL); }