@hawksightco/hawk-sdk 1.0.0 → 1.0.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/dist/src/anchor.d.ts +2 -0
- package/dist/src/anchor.d.ts.map +1 -1
- package/dist/src/anchor.js +2 -3
- package/dist/src/classes/Transactions.d.ts +28 -1
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +326 -0
- package/dist/src/classes/TxGenerator.d.ts +45 -0
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +191 -0
- package/package.json +3 -2
package/dist/src/anchor.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import * as web3 from "@solana/web3.js";
|
|
|
3
3
|
import * as anchor from "@coral-xyz/anchor";
|
|
4
4
|
import { IndexYieldFarming } from "./idl/iyf-main-idl";
|
|
5
5
|
import { IyfExtension } from "./idl/iyf-extension-idl";
|
|
6
|
+
import { WhirlpoolContext } from "@orca-so/whirlpools-sdk";
|
|
6
7
|
export declare class Anchor {
|
|
7
8
|
connection: web3.Connection;
|
|
8
9
|
private static _instance;
|
|
9
10
|
provider: anchor.AnchorProvider;
|
|
10
11
|
iyfMain: anchor.Program<IndexYieldFarming>;
|
|
11
12
|
iyfExtension: anchor.Program<IyfExtension>;
|
|
13
|
+
whirlpoolCtx: WhirlpoolContext;
|
|
12
14
|
private constructor();
|
|
13
15
|
static initialize(connection: web3.Connection): void;
|
|
14
16
|
static instance(): Anchor;
|
package/dist/src/anchor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../src/anchor.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAwB,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../../src/anchor.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAmB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAwB,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAO7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qBAAa,MAAM;IASR,UAAU,EAAE,IAAI,CAAC,UAAU;IAPpC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;IACjC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3C,YAAY,EAAE,gBAAgB,CAAA;IAE9B,OAAO;IASP,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IAI7C,MAAM,CAAC,QAAQ,IAAI,MAAM;CAO1B"}
|
package/dist/src/anchor.js
CHANGED
|
@@ -33,15 +33,14 @@ const iyf_main_idl_1 = require("./idl/iyf-main-idl");
|
|
|
33
33
|
const iyf_extension_idl_1 = require("./idl/iyf-extension-idl");
|
|
34
34
|
const nodewallet_1 = __importDefault(require("@coral-xyz/anchor/dist/cjs/nodewallet"));
|
|
35
35
|
const addresses_1 = require("./addresses");
|
|
36
|
-
|
|
36
|
+
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
37
37
|
class Anchor {
|
|
38
|
-
// whirlpoolCtx:
|
|
39
38
|
constructor(connection) {
|
|
40
39
|
this.connection = connection;
|
|
41
40
|
this.provider = new anchor.AnchorProvider(connection, new nodewallet_1.default(web3.Keypair.generate()), {});
|
|
42
41
|
this.iyfMain = new anchor.Program(iyf_main_idl_1.IDL, addresses_1.IYF_MAIN, this.provider);
|
|
43
42
|
this.iyfExtension = new anchor.Program(iyf_extension_idl_1.IDL, addresses_1.IYF_EXTENSION, this.provider);
|
|
44
|
-
|
|
43
|
+
this.whirlpoolCtx = whirlpools_sdk_1.WhirlpoolContext.withProvider(this.provider, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
45
44
|
}
|
|
46
45
|
static initialize(connection) {
|
|
47
46
|
Anchor._instance = new Anchor(connection);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
2
|
import * as web3 from "@solana/web3.js";
|
|
3
|
-
import { MeteoraClaim, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, OrcaOpenPosition, OrcaClosePosition, TransactionMetadataResponse } from '../types';
|
|
3
|
+
import { MeteoraClaim, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, OrcaOpenPosition, OrcaClosePosition, OrcaDeposit, OrcaWithdraw, OrcaClaimRewards, TransactionMetadataResponse } from '../types';
|
|
4
4
|
export declare class Transactions {
|
|
5
5
|
/**
|
|
6
6
|
* Generate UserPDA
|
|
@@ -103,6 +103,33 @@ export declare class Transactions {
|
|
|
103
103
|
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
104
104
|
*/
|
|
105
105
|
orcaClosePosition({ connection, params }: TxgenParams<OrcaClosePosition>): Promise<TransactionMetadataResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Creates orca instruction that deposits to a position
|
|
108
|
+
*
|
|
109
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
110
|
+
* @param payer The public key of the payer for transaction fees.
|
|
111
|
+
* @param params Parameters required
|
|
112
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
113
|
+
*/
|
|
114
|
+
orcaDeposit({ connection, params }: TxgenParams<OrcaDeposit>): Promise<TransactionMetadataResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Creates orca instruction that withdraws from a position
|
|
117
|
+
*
|
|
118
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
119
|
+
* @param payer The public key of the payer for transaction fees.
|
|
120
|
+
* @param params Parameters required
|
|
121
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
122
|
+
*/
|
|
123
|
+
orcaWithdraw({ connection, params }: TxgenParams<OrcaWithdraw>): Promise<TransactionMetadataResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates orca instruction that claims fees and rewards
|
|
126
|
+
*
|
|
127
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
128
|
+
* @param payer The public key of the payer for transaction fees.
|
|
129
|
+
* @param params Parameters required
|
|
130
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
131
|
+
*/
|
|
132
|
+
orcaClaimRewards({ connection, params }: TxgenParams<OrcaClaimRewards>): Promise<TransactionMetadataResponse>;
|
|
106
133
|
}
|
|
107
134
|
export declare const txgen: Transactions;
|
|
108
135
|
//# sourceMappingURL=Transactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAiBxC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,+BAA+B,EAC/B,cAAc,EACd,0BAA0B,EAC1B,gBAAgB,EAChB,eAAe,EACf,QAAQ,EAGR,W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AO,CAAC,2BAA2B,CAAC;IAwF3G;;;;;;;OAOG;IACG,gBAAgB,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAoGpH;AAED,eAAO,MAAM,KAAK,cAAqB,CAAC"}
|
|
@@ -46,7 +46,10 @@ const functions_2 = require("../functions");
|
|
|
46
46
|
const hsToMeteora_1 = require("../hsToMeteora");
|
|
47
47
|
const meteora_1 = require("../meteora");
|
|
48
48
|
const anchor_1 = require("../anchor");
|
|
49
|
+
// import { PDAUtil } from "@orca-so/whirlpools-sdk";
|
|
50
|
+
const hawksight_1 = require("../hawksight");
|
|
49
51
|
const types_2 = require("../types");
|
|
52
|
+
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
50
53
|
class Transactions {
|
|
51
54
|
/**
|
|
52
55
|
* Generate UserPDA
|
|
@@ -737,6 +740,329 @@ class Transactions {
|
|
|
737
740
|
});
|
|
738
741
|
});
|
|
739
742
|
}
|
|
743
|
+
/**
|
|
744
|
+
* Creates orca instruction that deposits to a position
|
|
745
|
+
*
|
|
746
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
747
|
+
* @param payer The public key of the payer for transaction fees.
|
|
748
|
+
* @param params Parameters required
|
|
749
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
750
|
+
*/
|
|
751
|
+
orcaDeposit(_a) {
|
|
752
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
753
|
+
const farm = addresses_1.USDC_FARM;
|
|
754
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
755
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
756
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
757
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
758
|
+
if (positionData === null) {
|
|
759
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
760
|
+
}
|
|
761
|
+
const whirlpool = positionData.whirlpool;
|
|
762
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
763
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
764
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
765
|
+
const tokenSeeds = [
|
|
766
|
+
{ owner: params.userWallet, mint: mintA },
|
|
767
|
+
{ owner: params.userWallet, mint: mintB },
|
|
768
|
+
];
|
|
769
|
+
const resultMap = yield (0, functions_2.tokenAccountExists)(connection, tokenSeeds);
|
|
770
|
+
resultMap.map((result, index) => {
|
|
771
|
+
const tokenKey = result.tokenKey;
|
|
772
|
+
const token = tokenSeeds[index];
|
|
773
|
+
if (!result.exists) {
|
|
774
|
+
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
778
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
779
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
780
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
781
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
782
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
783
|
+
const depositIx = yield (0, hawksight_1.depositMultipleToken)({
|
|
784
|
+
payer: params.userWallet,
|
|
785
|
+
deposit: [
|
|
786
|
+
{
|
|
787
|
+
mint: mintA,
|
|
788
|
+
amount: params.totalXAmount,
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
mint: mintB,
|
|
792
|
+
amount: params.totalYAmount,
|
|
793
|
+
},
|
|
794
|
+
]
|
|
795
|
+
});
|
|
796
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
797
|
+
.orcaDeposit()
|
|
798
|
+
.accounts({
|
|
799
|
+
farm,
|
|
800
|
+
userPda,
|
|
801
|
+
authority: params.userWallet,
|
|
802
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
803
|
+
positionMint: params.positionMint,
|
|
804
|
+
whirlpool,
|
|
805
|
+
position,
|
|
806
|
+
positionTokenAccount,
|
|
807
|
+
tokenOwnerAccountA,
|
|
808
|
+
tokenOwnerAccountB,
|
|
809
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
810
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
811
|
+
tickArrayLower,
|
|
812
|
+
tickArrayUpper,
|
|
813
|
+
ownerFeeA,
|
|
814
|
+
ownerFeeB,
|
|
815
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
816
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
817
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
818
|
+
})
|
|
819
|
+
.instruction();
|
|
820
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
821
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
822
|
+
.accounts({
|
|
823
|
+
farm,
|
|
824
|
+
userPda,
|
|
825
|
+
authority: params.userWallet,
|
|
826
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
827
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
828
|
+
})
|
|
829
|
+
.remainingAccounts([
|
|
830
|
+
orcaOpenPositionIx.keys[4],
|
|
831
|
+
orcaOpenPositionIx.keys[5],
|
|
832
|
+
orcaOpenPositionIx.keys[6],
|
|
833
|
+
orcaOpenPositionIx.keys[7],
|
|
834
|
+
orcaOpenPositionIx.keys[8],
|
|
835
|
+
orcaOpenPositionIx.keys[9],
|
|
836
|
+
orcaOpenPositionIx.keys[10],
|
|
837
|
+
orcaOpenPositionIx.keys[11],
|
|
838
|
+
orcaOpenPositionIx.keys[12],
|
|
839
|
+
orcaOpenPositionIx.keys[13],
|
|
840
|
+
orcaOpenPositionIx.keys[14],
|
|
841
|
+
orcaOpenPositionIx.keys[15],
|
|
842
|
+
orcaOpenPositionIx.keys[16],
|
|
843
|
+
orcaOpenPositionIx.keys[17],
|
|
844
|
+
orcaOpenPositionIx.keys[18],
|
|
845
|
+
])
|
|
846
|
+
.instruction();
|
|
847
|
+
const clearRemainingTokensIxs = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
848
|
+
payer: params.userWallet,
|
|
849
|
+
withdraw: [
|
|
850
|
+
{ mint: mintA },
|
|
851
|
+
{ mint: mintB },
|
|
852
|
+
],
|
|
853
|
+
});
|
|
854
|
+
const mainInstructions = [depositIx, orcaOpenPositionIxViaMain, clearRemainingTokensIxs];
|
|
855
|
+
return (0, functions_2.createTransactionMeta)({
|
|
856
|
+
payer: params.userWallet,
|
|
857
|
+
description: `Deposit to Orca Position: ${position}`,
|
|
858
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
859
|
+
mainInstructions,
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Creates orca instruction that withdraws from a position
|
|
865
|
+
*
|
|
866
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
867
|
+
* @param payer The public key of the payer for transaction fees.
|
|
868
|
+
* @param params Parameters required
|
|
869
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
870
|
+
*/
|
|
871
|
+
orcaWithdraw(_a) {
|
|
872
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
873
|
+
const farm = addresses_1.USDC_FARM;
|
|
874
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
875
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
876
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
877
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
878
|
+
if (positionData === null) {
|
|
879
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
880
|
+
}
|
|
881
|
+
const whirlpool = positionData.whirlpool;
|
|
882
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
883
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
884
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
885
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
886
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
887
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
888
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
889
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
890
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
891
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
892
|
+
.orcaWithdraw(params.liquidityAmount)
|
|
893
|
+
.accounts({
|
|
894
|
+
farm,
|
|
895
|
+
userPda,
|
|
896
|
+
authority: params.userWallet,
|
|
897
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
898
|
+
positionMint: params.positionMint,
|
|
899
|
+
whirlpool,
|
|
900
|
+
position,
|
|
901
|
+
positionTokenAccount,
|
|
902
|
+
tokenOwnerAccountA,
|
|
903
|
+
tokenOwnerAccountB,
|
|
904
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
905
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
906
|
+
tickArrayLower,
|
|
907
|
+
tickArrayUpper,
|
|
908
|
+
ownerFeeA,
|
|
909
|
+
ownerFeeB,
|
|
910
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
911
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
912
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
913
|
+
})
|
|
914
|
+
.instruction();
|
|
915
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
916
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
917
|
+
.accounts({
|
|
918
|
+
farm,
|
|
919
|
+
userPda,
|
|
920
|
+
authority: params.userWallet,
|
|
921
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
922
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
923
|
+
})
|
|
924
|
+
.remainingAccounts([
|
|
925
|
+
orcaOpenPositionIx.keys[4],
|
|
926
|
+
orcaOpenPositionIx.keys[5],
|
|
927
|
+
orcaOpenPositionIx.keys[6],
|
|
928
|
+
orcaOpenPositionIx.keys[7],
|
|
929
|
+
orcaOpenPositionIx.keys[8],
|
|
930
|
+
orcaOpenPositionIx.keys[9],
|
|
931
|
+
orcaOpenPositionIx.keys[10],
|
|
932
|
+
orcaOpenPositionIx.keys[11],
|
|
933
|
+
orcaOpenPositionIx.keys[12],
|
|
934
|
+
orcaOpenPositionIx.keys[13],
|
|
935
|
+
orcaOpenPositionIx.keys[14],
|
|
936
|
+
orcaOpenPositionIx.keys[15],
|
|
937
|
+
orcaOpenPositionIx.keys[16],
|
|
938
|
+
orcaOpenPositionIx.keys[17],
|
|
939
|
+
orcaOpenPositionIx.keys[18],
|
|
940
|
+
])
|
|
941
|
+
.instruction();
|
|
942
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
943
|
+
payer: params.userWallet,
|
|
944
|
+
withdraw: [
|
|
945
|
+
{ mint: mintA },
|
|
946
|
+
{ mint: mintB },
|
|
947
|
+
],
|
|
948
|
+
});
|
|
949
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
950
|
+
return (0, functions_2.createTransactionMeta)({
|
|
951
|
+
payer: params.userWallet,
|
|
952
|
+
description: `Withdraw deposits from Orca Position: ${position}`,
|
|
953
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
954
|
+
mainInstructions,
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Creates orca instruction that claims fees and rewards
|
|
960
|
+
*
|
|
961
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
962
|
+
* @param payer The public key of the payer for transaction fees.
|
|
963
|
+
* @param params Parameters required
|
|
964
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
965
|
+
*/
|
|
966
|
+
orcaClaimRewards(_a) {
|
|
967
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
968
|
+
const farm = addresses_1.USDC_FARM;
|
|
969
|
+
const userPda = (0, functions_2.generateUserPda)(params.userWallet, farm);
|
|
970
|
+
const position = (0, functions_2.generateOrcaPositionPDA)(params.positionMint);
|
|
971
|
+
const positionTokenAccount = (0, functions_2.generateAta)(userPda, params.positionMint);
|
|
972
|
+
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
973
|
+
if (positionData === null) {
|
|
974
|
+
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
975
|
+
}
|
|
976
|
+
const whirlpool = positionData.whirlpool;
|
|
977
|
+
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
978
|
+
const mintA = whirlpoolData.tokenMintA;
|
|
979
|
+
const mintB = whirlpoolData.tokenMintB;
|
|
980
|
+
const tokenOwnerAccountA = (0, functions_2.generateAta)(userPda, mintA);
|
|
981
|
+
const tokenOwnerAccountB = (0, functions_2.generateAta)(userPda, mintB);
|
|
982
|
+
const { publicKey: tickArrayLower } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
983
|
+
const { publicKey: tickArrayUpper } = whirlpools_sdk_1.PDAUtil.getTickArrayFromTickIndex(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
984
|
+
const ownerFeeA = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
985
|
+
const ownerFeeB = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
986
|
+
const remainingAccounts = [];
|
|
987
|
+
for (const rewardInfo of whirlpoolData.rewardInfos) {
|
|
988
|
+
if (rewardInfo.mint.toString() !== web3.SystemProgram.programId.toString()) {
|
|
989
|
+
const rewardOwnerAccount = (0, functions_2.generateAta)(userPda, rewardInfo.mint);
|
|
990
|
+
const rewardVault = rewardInfo.vault;
|
|
991
|
+
const rewardFee = (0, functions_2.generateAta)(addresses_1.SITE_FEE_OWNER, rewardInfo.mint);
|
|
992
|
+
remainingAccounts.push({ pubkey: rewardOwnerAccount, isSigner: false, isWritable: true });
|
|
993
|
+
remainingAccounts.push({ pubkey: rewardVault, isSigner: false, isWritable: true });
|
|
994
|
+
remainingAccounts.push({ pubkey: rewardFee, isSigner: false, isWritable: true });
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
whirlpoolData.rewardInfos[0].mint;
|
|
998
|
+
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
999
|
+
.orcaClaimRewards()
|
|
1000
|
+
.accounts({
|
|
1001
|
+
farm,
|
|
1002
|
+
userPda,
|
|
1003
|
+
authority: params.userWallet,
|
|
1004
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1005
|
+
whirlpool,
|
|
1006
|
+
positionMint: params.positionMint,
|
|
1007
|
+
position,
|
|
1008
|
+
tickArrayLower,
|
|
1009
|
+
tickArrayUpper,
|
|
1010
|
+
positionTokenAccount,
|
|
1011
|
+
tokenVaultA: whirlpoolData.tokenVaultA,
|
|
1012
|
+
tokenVaultB: whirlpoolData.tokenVaultB,
|
|
1013
|
+
tokenOwnerAccountA,
|
|
1014
|
+
tokenOwnerAccountB,
|
|
1015
|
+
ownerFeeA,
|
|
1016
|
+
ownerFeeB,
|
|
1017
|
+
orcaWhirlpoolProgram: addresses_1.ORCA_WHIRLPOOL_PROGRAM,
|
|
1018
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1019
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
1020
|
+
})
|
|
1021
|
+
.remainingAccounts(remainingAccounts)
|
|
1022
|
+
.instruction();
|
|
1023
|
+
const orcaOpenPositionIxViaMain = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1024
|
+
.iyfExtensionExecute(orcaOpenPositionIx.data)
|
|
1025
|
+
.accounts({
|
|
1026
|
+
farm,
|
|
1027
|
+
userPda,
|
|
1028
|
+
authority: params.userWallet,
|
|
1029
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
1030
|
+
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1031
|
+
})
|
|
1032
|
+
.remainingAccounts([
|
|
1033
|
+
orcaOpenPositionIx.keys[4],
|
|
1034
|
+
orcaOpenPositionIx.keys[5],
|
|
1035
|
+
orcaOpenPositionIx.keys[6],
|
|
1036
|
+
orcaOpenPositionIx.keys[7],
|
|
1037
|
+
orcaOpenPositionIx.keys[8],
|
|
1038
|
+
orcaOpenPositionIx.keys[9],
|
|
1039
|
+
orcaOpenPositionIx.keys[10],
|
|
1040
|
+
orcaOpenPositionIx.keys[11],
|
|
1041
|
+
orcaOpenPositionIx.keys[12],
|
|
1042
|
+
orcaOpenPositionIx.keys[13],
|
|
1043
|
+
orcaOpenPositionIx.keys[14],
|
|
1044
|
+
orcaOpenPositionIx.keys[15],
|
|
1045
|
+
orcaOpenPositionIx.keys[16],
|
|
1046
|
+
orcaOpenPositionIx.keys[17],
|
|
1047
|
+
orcaOpenPositionIx.keys[18],
|
|
1048
|
+
])
|
|
1049
|
+
.instruction();
|
|
1050
|
+
const withdrawFromPda = yield (0, hawksight_1.withdrawMultipleToken)({
|
|
1051
|
+
payer: params.userWallet,
|
|
1052
|
+
withdraw: [
|
|
1053
|
+
{ mint: mintA },
|
|
1054
|
+
{ mint: mintB },
|
|
1055
|
+
],
|
|
1056
|
+
});
|
|
1057
|
+
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
1058
|
+
return (0, functions_2.createTransactionMeta)({
|
|
1059
|
+
payer: params.userWallet,
|
|
1060
|
+
description: `Claim rewards from Orca Position: ${position}`,
|
|
1061
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1062
|
+
mainInstructions,
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
740
1066
|
}
|
|
741
1067
|
exports.Transactions = Transactions;
|
|
742
1068
|
exports.txgen = new Transactions();
|
|
@@ -72,5 +72,50 @@ export declare class TxGenerator {
|
|
|
72
72
|
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
73
73
|
*/
|
|
74
74
|
meteoraInitializeBinArrays(connection: web3.Connection, payer: string, params: _client.TxInitializeBinArraysBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates orca instruction that opens new position
|
|
77
|
+
*
|
|
78
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
79
|
+
* @param payer The public key of the payer for transaction fees.
|
|
80
|
+
* @param params Parameters required
|
|
81
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
82
|
+
*/
|
|
83
|
+
orcaOpenPosition(connection: web3.Connection, payer: string, params: _client.TxOpenPositionBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
84
|
+
/**
|
|
85
|
+
* Creates orca instruction that closes position
|
|
86
|
+
*
|
|
87
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
88
|
+
* @param payer The public key of the payer for transaction fees.
|
|
89
|
+
* @param params Parameters required
|
|
90
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
91
|
+
*/
|
|
92
|
+
orcaClosePosition(connection: web3.Connection, payer: string, params: _client.TxClosePositionBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
93
|
+
/**
|
|
94
|
+
* Creates orca instruction that deposits to a position
|
|
95
|
+
*
|
|
96
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
97
|
+
* @param payer The public key of the payer for transaction fees.
|
|
98
|
+
* @param params Parameters required
|
|
99
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
100
|
+
*/
|
|
101
|
+
orcaDeposit(connection: web3.Connection, payer: string, params: _client.TxDepositBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates orca instruction that withdraws from a position
|
|
104
|
+
*
|
|
105
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
106
|
+
* @param payer The public key of the payer for transaction fees.
|
|
107
|
+
* @param params Parameters required
|
|
108
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
109
|
+
*/
|
|
110
|
+
orcaWithdraw(connection: web3.Connection, payer: string, params: _client.TxWithdrawBody1): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
111
|
+
/**
|
|
112
|
+
* Creates orca instruction that claims fees and rewards
|
|
113
|
+
*
|
|
114
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
115
|
+
* @param payer The public key of the payer for transaction fees.
|
|
116
|
+
* @param params Parameters required
|
|
117
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
118
|
+
*/
|
|
119
|
+
orcaClaimRewards(connection: web3.Connection, payer: string, params: _client.TxClaimRewardsBody): Promise<ResponseWithStatus<TransactionMetadata>>;
|
|
75
120
|
}
|
|
76
121
|
//# sourceMappingURL=TxGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TxGenerator.d.ts","sourceRoot":"","sources":["../../../src/classes/TxGenerator.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAkE,MAAM,UAAU,CAAC;AACnI,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;;;GAIG;AACH,qBAAa,WAAW;IAQpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc;IAPnD;;;;OAIG;gBAEgB,MAAM,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc;IAGnD;;;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196 @@ class TxGenerator {
|
|
|
309
309
|
}
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Creates orca instruction that opens new position
|
|
314
|
+
*
|
|
315
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
316
|
+
* @param payer The public key of the payer for transaction fees.
|
|
317
|
+
* @param params Parameters required
|
|
318
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
319
|
+
*/
|
|
320
|
+
orcaOpenPosition(connection, payer, params) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
// Initialize anchor
|
|
323
|
+
anchor_1.Anchor.initialize(connection);
|
|
324
|
+
try {
|
|
325
|
+
const result = yield Transactions_1.txgen.orcaOpenPosition({
|
|
326
|
+
connection,
|
|
327
|
+
params: {
|
|
328
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
329
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
330
|
+
whirlpool: new web3.PublicKey(params.whirlpool),
|
|
331
|
+
tickLowerIndex: parseInt(params.tickLowerIndex),
|
|
332
|
+
tickUpperIndex: parseInt(params.tickUpperIndex),
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
status: 200,
|
|
337
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
catch (e) {
|
|
341
|
+
return {
|
|
342
|
+
status: 400,
|
|
343
|
+
data: {
|
|
344
|
+
code: "custom",
|
|
345
|
+
message: e,
|
|
346
|
+
path: [],
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Creates orca instruction that closes position
|
|
354
|
+
*
|
|
355
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
356
|
+
* @param payer The public key of the payer for transaction fees.
|
|
357
|
+
* @param params Parameters required
|
|
358
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
359
|
+
*/
|
|
360
|
+
orcaClosePosition(connection, payer, params) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
// Initialize anchor
|
|
363
|
+
anchor_1.Anchor.initialize(connection);
|
|
364
|
+
try {
|
|
365
|
+
const result = yield Transactions_1.txgen.orcaClosePosition({
|
|
366
|
+
connection,
|
|
367
|
+
params: {
|
|
368
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
369
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
status: 200,
|
|
374
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
catch (e) {
|
|
378
|
+
return {
|
|
379
|
+
status: 400,
|
|
380
|
+
data: {
|
|
381
|
+
code: "custom",
|
|
382
|
+
message: e,
|
|
383
|
+
path: [],
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Creates orca instruction that deposits to a position
|
|
391
|
+
*
|
|
392
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
393
|
+
* @param payer The public key of the payer for transaction fees.
|
|
394
|
+
* @param params Parameters required
|
|
395
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
396
|
+
*/
|
|
397
|
+
orcaDeposit(connection, payer, params) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
// Initialize anchor
|
|
400
|
+
anchor_1.Anchor.initialize(connection);
|
|
401
|
+
try {
|
|
402
|
+
const result = yield Transactions_1.txgen.orcaDeposit({
|
|
403
|
+
connection,
|
|
404
|
+
params: {
|
|
405
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
406
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
407
|
+
totalXAmount: new bn_js_1.BN(params.totalXAmount),
|
|
408
|
+
totalYAmount: new bn_js_1.BN(params.totalYAmount),
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return {
|
|
412
|
+
status: 200,
|
|
413
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
catch (e) {
|
|
417
|
+
return {
|
|
418
|
+
status: 400,
|
|
419
|
+
data: {
|
|
420
|
+
code: "custom",
|
|
421
|
+
message: e,
|
|
422
|
+
path: [],
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Creates orca instruction that withdraws from a position
|
|
430
|
+
*
|
|
431
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
432
|
+
* @param payer The public key of the payer for transaction fees.
|
|
433
|
+
* @param params Parameters required
|
|
434
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
435
|
+
*/
|
|
436
|
+
orcaWithdraw(connection, payer, params) {
|
|
437
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
438
|
+
// Initialize anchor
|
|
439
|
+
anchor_1.Anchor.initialize(connection);
|
|
440
|
+
try {
|
|
441
|
+
const result = yield Transactions_1.txgen.orcaWithdraw({
|
|
442
|
+
connection,
|
|
443
|
+
params: {
|
|
444
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
445
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
446
|
+
liquidityAmount: new bn_js_1.BN(params.liquidityAmount),
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
return {
|
|
450
|
+
status: 200,
|
|
451
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
catch (e) {
|
|
455
|
+
return {
|
|
456
|
+
status: 400,
|
|
457
|
+
data: {
|
|
458
|
+
code: "custom",
|
|
459
|
+
message: e,
|
|
460
|
+
path: [],
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Creates orca instruction that claims fees and rewards
|
|
468
|
+
*
|
|
469
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
470
|
+
* @param payer The public key of the payer for transaction fees.
|
|
471
|
+
* @param params Parameters required
|
|
472
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse or TransactionMetadata.
|
|
473
|
+
*/
|
|
474
|
+
orcaClaimRewards(connection, payer, params) {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
+
// Initialize anchor
|
|
477
|
+
anchor_1.Anchor.initialize(connection);
|
|
478
|
+
try {
|
|
479
|
+
const result = yield Transactions_1.txgen.orcaClaimRewards({
|
|
480
|
+
connection,
|
|
481
|
+
params: {
|
|
482
|
+
userWallet: new web3.PublicKey(params.userWallet),
|
|
483
|
+
positionMint: new web3.PublicKey(params.positionMint),
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return {
|
|
487
|
+
status: 200,
|
|
488
|
+
data: yield (0, functions_1.createTxMetadata)(this.generalUtility, connection, payer, result),
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
catch (e) {
|
|
492
|
+
return {
|
|
493
|
+
status: 400,
|
|
494
|
+
data: {
|
|
495
|
+
code: "custom",
|
|
496
|
+
message: e,
|
|
497
|
+
path: [],
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
312
503
|
}
|
|
313
504
|
exports.TxGenerator = TxGenerator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hawksightco/hawk-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Hawksight v2 SDK",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"repository": "https://github.com/ghabxph/hawk-api-client.git",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"@coral-xyz/anchor": "^0.28.0",
|
|
25
25
|
"@hawksightco/swagger-client": "^0.0.29",
|
|
26
26
|
"@meteora-ag/dlmm": "^1.0.51",
|
|
27
|
-
"@
|
|
27
|
+
"@orca-so/whirlpools-sdk": "^0.13.3",
|
|
28
28
|
"@solana/spl-token": "^0.4.6",
|
|
29
|
+
"@solana/web3.js": "^1.89.1",
|
|
29
30
|
"bn.js": "^5.2.1",
|
|
30
31
|
"lodash": "^4.17.21"
|
|
31
32
|
},
|