@drift-labs/vaults-sdk 0.5.19 → 0.5.21
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/cli/cli.ts +33 -0
- package/cli/commands/index.ts +1 -0
- package/cli/commands/initVault.ts +44 -19
- package/cli/commands/managerApplyProfitShare.ts +32 -0
- package/cli/commands/managerCancelWithdraw.ts +8 -3
- package/cli/commands/managerDeposit.ts +8 -3
- package/cli/commands/managerRequestWithdraw.ts +17 -5
- package/cli/commands/managerUpdateMarginTradingEnabled.ts +9 -4
- package/cli/commands/managerUpdatePoolId.ts +36 -0
- package/cli/commands/managerUpdateVault.ts +9 -4
- package/cli/commands/managerUpdateVaultDelegate.ts +9 -3
- package/cli/commands/managerUpdateVaultManager.ts +77 -0
- package/cli/commands/managerWithdraw.ts +8 -3
- package/cli/utils.ts +14 -1
- package/lib/types/drift_vaults.d.ts +21 -0
- package/lib/types/drift_vaults.js +21 -0
- package/lib/vaultClient.d.ts +68 -8
- package/lib/vaultClient.js +189 -94
- package/package.json +2 -2
- package/src/idl/drift_vaults.json +21 -0
- package/src/types/drift_vaults.ts +42 -0
- package/src/vaultClient.ts +373 -115
package/src/vaultClient.ts
CHANGED
|
@@ -555,9 +555,27 @@ export class VaultClient {
|
|
|
555
555
|
hurdleRate: number;
|
|
556
556
|
permissioned: boolean;
|
|
557
557
|
vaultProtocol?: VaultProtocolParams;
|
|
558
|
+
manager?: PublicKey;
|
|
558
559
|
},
|
|
559
560
|
uiTxParams?: TxParams
|
|
560
561
|
): Promise<TransactionSignature> {
|
|
562
|
+
const ix = await this.getInitializeVaultIx(params);
|
|
563
|
+
return await this.createAndSendTxn([ix], uiTxParams);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
public async getInitializeVaultIx(params: {
|
|
567
|
+
name: number[];
|
|
568
|
+
spotMarketIndex: number;
|
|
569
|
+
redeemPeriod: BN;
|
|
570
|
+
maxTokens: BN;
|
|
571
|
+
minDepositAmount: BN;
|
|
572
|
+
managementFee: BN;
|
|
573
|
+
profitShare: number;
|
|
574
|
+
hurdleRate: number;
|
|
575
|
+
permissioned: boolean;
|
|
576
|
+
vaultProtocol?: VaultProtocolParams;
|
|
577
|
+
manager?: PublicKey;
|
|
578
|
+
}): Promise<TransactionInstruction> {
|
|
561
579
|
const { vaultProtocol: vaultProtocolParams, ...vaultParams } = params;
|
|
562
580
|
const vault = getVaultAddressSync(this.program.programId, params.name);
|
|
563
581
|
const tokenAccount = getTokenVaultAddressSync(
|
|
@@ -610,12 +628,11 @@ export class VaultClient {
|
|
|
610
628
|
.accounts({
|
|
611
629
|
...accounts,
|
|
612
630
|
vaultProtocol,
|
|
613
|
-
payer: uiAuthority,
|
|
614
|
-
manager: uiAuthority,
|
|
631
|
+
payer: params.manager ?? uiAuthority,
|
|
632
|
+
manager: params.manager ?? uiAuthority,
|
|
615
633
|
})
|
|
616
634
|
.instruction();
|
|
617
|
-
|
|
618
|
-
return await this.createAndSendTxn(ixs, uiTxParams);
|
|
635
|
+
return initializeVaultWithProtocolIx;
|
|
619
636
|
} else {
|
|
620
637
|
const _params: VaultParams = vaultParams;
|
|
621
638
|
|
|
@@ -624,12 +641,11 @@ export class VaultClient {
|
|
|
624
641
|
.initializeVault(_params)
|
|
625
642
|
.accounts({
|
|
626
643
|
...accounts,
|
|
627
|
-
payer: uiAuthority,
|
|
628
|
-
manager: uiAuthority,
|
|
644
|
+
payer: params.manager ?? uiAuthority,
|
|
645
|
+
manager: params.manager ?? uiAuthority,
|
|
629
646
|
})
|
|
630
647
|
.instruction();
|
|
631
|
-
|
|
632
|
-
return await this.createAndSendTxn(ixs, uiTxParams);
|
|
648
|
+
return initializeVaultIx;
|
|
633
649
|
}
|
|
634
650
|
}
|
|
635
651
|
|
|
@@ -645,6 +661,14 @@ export class VaultClient {
|
|
|
645
661
|
delegate: PublicKey,
|
|
646
662
|
uiTxParams?: TxParams
|
|
647
663
|
): Promise<TransactionSignature> {
|
|
664
|
+
const updateDelegateIx = await this.getUpdateDelegateIx(vault, delegate);
|
|
665
|
+
return await this.createAndSendTxn([updateDelegateIx], uiTxParams);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
public async getUpdateDelegateIx(
|
|
669
|
+
vault: PublicKey,
|
|
670
|
+
delegate: PublicKey
|
|
671
|
+
): Promise<TransactionInstruction> {
|
|
648
672
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
649
673
|
const accounts = {
|
|
650
674
|
vault: vault,
|
|
@@ -652,11 +676,10 @@ export class VaultClient {
|
|
|
652
676
|
driftProgram: this.driftClient.program.programId,
|
|
653
677
|
};
|
|
654
678
|
|
|
655
|
-
|
|
679
|
+
return await this.program.methods
|
|
656
680
|
.updateDelegate(delegate)
|
|
657
|
-
.accounts({ ...accounts, manager:
|
|
681
|
+
.accounts({ ...accounts, manager: vaultAccount.manager })
|
|
658
682
|
.instruction();
|
|
659
|
-
return await this.createAndSendTxn([updateDelegateIx], uiTxParams);
|
|
660
683
|
}
|
|
661
684
|
|
|
662
685
|
/**
|
|
@@ -670,6 +693,18 @@ export class VaultClient {
|
|
|
670
693
|
enabled: boolean,
|
|
671
694
|
uiTxParams?: TxParams
|
|
672
695
|
): Promise<TransactionSignature> {
|
|
696
|
+
const updateMarginTradingEnabledIx =
|
|
697
|
+
await this.getUpdateMarginTradingEnabledIx(vault, enabled);
|
|
698
|
+
return await this.createAndSendTxn(
|
|
699
|
+
[updateMarginTradingEnabledIx],
|
|
700
|
+
uiTxParams
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
public async getUpdateMarginTradingEnabledIx(
|
|
705
|
+
vault: PublicKey,
|
|
706
|
+
enabled: boolean
|
|
707
|
+
): Promise<TransactionInstruction> {
|
|
673
708
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
674
709
|
const accounts = {
|
|
675
710
|
vault: vault,
|
|
@@ -701,15 +736,11 @@ export class VaultClient {
|
|
|
701
736
|
// do nothing
|
|
702
737
|
}
|
|
703
738
|
|
|
704
|
-
|
|
739
|
+
return await this.program.methods
|
|
705
740
|
.updateMarginTradingEnabled(enabled)
|
|
706
|
-
.accounts({ ...accounts, manager:
|
|
741
|
+
.accounts({ ...accounts, manager: vaultAccount.manager })
|
|
707
742
|
.remainingAccounts(remainingAccounts)
|
|
708
743
|
.instruction();
|
|
709
|
-
return await this.createAndSendTxn(
|
|
710
|
-
[updateMarginTradingEnabledIx],
|
|
711
|
-
uiTxParams
|
|
712
|
-
);
|
|
713
744
|
}
|
|
714
745
|
|
|
715
746
|
/**
|
|
@@ -780,7 +811,7 @@ export class VaultClient {
|
|
|
780
811
|
|
|
781
812
|
return await this.program.methods
|
|
782
813
|
.updateUserPoolId(poolId)
|
|
783
|
-
.accounts({ ...accounts, manager:
|
|
814
|
+
.accounts({ ...accounts, manager: vaultAccount.manager })
|
|
784
815
|
.remainingAccounts(remainingAccounts)
|
|
785
816
|
.instruction();
|
|
786
817
|
}
|
|
@@ -826,6 +857,25 @@ export class VaultClient {
|
|
|
826
857
|
uiTxParams?: TxParams,
|
|
827
858
|
managerTokenAccount?: PublicKey
|
|
828
859
|
): Promise<TransactionSignature> {
|
|
860
|
+
const managerDepositIxs = await this.getManagerDepositIx(
|
|
861
|
+
vault,
|
|
862
|
+
amount,
|
|
863
|
+
managerTokenAccount
|
|
864
|
+
);
|
|
865
|
+
return await this.createAndSendTxn(managerDepositIxs, uiTxParams);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
*
|
|
870
|
+
* @param vault vault address to deposit to
|
|
871
|
+
* @param amount amount to deposit
|
|
872
|
+
* @returns
|
|
873
|
+
*/
|
|
874
|
+
public async getManagerDepositIx(
|
|
875
|
+
vault: PublicKey,
|
|
876
|
+
amount: BN,
|
|
877
|
+
managerTokenAccount?: PublicKey
|
|
878
|
+
): Promise<Array<TransactionInstruction>> {
|
|
829
879
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
830
880
|
const driftSpotMarket = this.driftClient.getSpotMarketAccount(
|
|
831
881
|
vaultAccount.spotMarketIndex
|
|
@@ -869,7 +919,8 @@ export class VaultClient {
|
|
|
869
919
|
managerTokenAccount ??
|
|
870
920
|
getAssociatedTokenAddressSync(
|
|
871
921
|
driftSpotMarket.mint,
|
|
872
|
-
|
|
922
|
+
vaultAccount.manager,
|
|
923
|
+
true
|
|
873
924
|
),
|
|
874
925
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
875
926
|
};
|
|
@@ -885,14 +936,11 @@ export class VaultClient {
|
|
|
885
936
|
.accounts({
|
|
886
937
|
...accounts,
|
|
887
938
|
userTokenAccount,
|
|
888
|
-
manager:
|
|
939
|
+
manager: vaultAccount.manager,
|
|
889
940
|
})
|
|
890
941
|
.remainingAccounts(remainingAccounts)
|
|
891
942
|
.instruction();
|
|
892
|
-
return
|
|
893
|
-
[...preIxs, managerDepositIx, ...postIxs],
|
|
894
|
-
uiTxParams
|
|
895
|
-
);
|
|
943
|
+
return [...preIxs, managerDepositIx, ...postIxs];
|
|
896
944
|
}
|
|
897
945
|
|
|
898
946
|
public async managerRequestWithdraw(
|
|
@@ -901,16 +949,25 @@ export class VaultClient {
|
|
|
901
949
|
withdrawUnit: WithdrawUnit,
|
|
902
950
|
uiTxParams?: TxParams
|
|
903
951
|
): Promise<TransactionSignature> {
|
|
952
|
+
const requestWithdrawIx = await this.getManagerRequestWithdrawIx(
|
|
953
|
+
vault,
|
|
954
|
+
amount,
|
|
955
|
+
withdrawUnit
|
|
956
|
+
);
|
|
957
|
+
return await this.createAndSendTxn([requestWithdrawIx], uiTxParams);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
public async getManagerRequestWithdrawIx(
|
|
961
|
+
vault: PublicKey,
|
|
962
|
+
amount: BN,
|
|
963
|
+
withdrawUnit: WithdrawUnit
|
|
964
|
+
): Promise<TransactionInstruction> {
|
|
904
965
|
this.program.idl.types;
|
|
905
966
|
// @ts-ignore
|
|
906
967
|
const vaultAccount = (await this.program.account.vault.fetch(
|
|
907
968
|
vault
|
|
908
969
|
)) as Vault;
|
|
909
970
|
|
|
910
|
-
if (!this.driftClient.wallet.publicKey.equals(vaultAccount.manager)) {
|
|
911
|
-
throw new Error(`Only the manager of the vault can request a withdraw.`);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
971
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
915
972
|
const userStatsKey = getUserStatsAccountPublicKey(
|
|
916
973
|
this.driftClient.program.programId,
|
|
@@ -932,26 +989,31 @@ export class VaultClient {
|
|
|
932
989
|
driftUserStats: userStatsKey,
|
|
933
990
|
};
|
|
934
991
|
|
|
935
|
-
|
|
992
|
+
return this.program.instruction.managerRequestWithdraw(
|
|
936
993
|
// @ts-ignore
|
|
937
994
|
amount,
|
|
938
995
|
withdrawUnit,
|
|
939
996
|
{
|
|
940
997
|
accounts: {
|
|
941
|
-
manager:
|
|
998
|
+
manager: vaultAccount.manager,
|
|
942
999
|
...accounts,
|
|
943
1000
|
},
|
|
944
1001
|
remainingAccounts,
|
|
945
1002
|
}
|
|
946
1003
|
);
|
|
947
|
-
|
|
948
|
-
return await this.createAndSendTxn([requestWithdrawIx], uiTxParams);
|
|
949
1004
|
}
|
|
950
1005
|
|
|
951
1006
|
public async managerCancelWithdrawRequest(
|
|
952
1007
|
vault: PublicKey,
|
|
953
1008
|
uiTxParams?: TxParams
|
|
954
1009
|
): Promise<TransactionSignature> {
|
|
1010
|
+
const ix = await this.getManagerCancelWithdrawRequestIx(vault);
|
|
1011
|
+
return await this.createAndSendTxn([ix], uiTxParams);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
public async getManagerCancelWithdrawRequestIx(
|
|
1015
|
+
vault: PublicKey
|
|
1016
|
+
): Promise<TransactionInstruction> {
|
|
955
1017
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
956
1018
|
|
|
957
1019
|
const userStatsKey = getUserStatsAccountPublicKey(
|
|
@@ -960,7 +1022,7 @@ export class VaultClient {
|
|
|
960
1022
|
);
|
|
961
1023
|
|
|
962
1024
|
const accounts = {
|
|
963
|
-
manager:
|
|
1025
|
+
manager: vaultAccount.manager,
|
|
964
1026
|
vault,
|
|
965
1027
|
driftUser: vaultAccount.user,
|
|
966
1028
|
driftUserStats: userStatsKey,
|
|
@@ -977,24 +1039,24 @@ export class VaultClient {
|
|
|
977
1039
|
userStats
|
|
978
1040
|
);
|
|
979
1041
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
return await this.createAndSendTxn([cancelRequestWithdrawIx], uiTxParams);
|
|
1042
|
+
return this.program.instruction.mangerCancelWithdrawRequest({
|
|
1043
|
+
accounts,
|
|
1044
|
+
remainingAccounts,
|
|
1045
|
+
});
|
|
987
1046
|
}
|
|
988
1047
|
|
|
989
1048
|
public async managerWithdraw(
|
|
990
1049
|
vault: PublicKey,
|
|
991
1050
|
uiTxParams?: TxParams
|
|
992
1051
|
): Promise<TransactionSignature> {
|
|
993
|
-
const
|
|
1052
|
+
const ix = await this.getManagerWithdrawIx(vault);
|
|
1053
|
+
return this.createAndSendTxn([ix], uiTxParams);
|
|
1054
|
+
}
|
|
994
1055
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1056
|
+
public async getManagerWithdrawIx(
|
|
1057
|
+
vault: PublicKey
|
|
1058
|
+
): Promise<TransactionInstruction> {
|
|
1059
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
998
1060
|
|
|
999
1061
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1000
1062
|
const userStatsKey = getUserStatsAccountPublicKey(
|
|
@@ -1020,10 +1082,10 @@ export class VaultClient {
|
|
|
1020
1082
|
);
|
|
1021
1083
|
}
|
|
1022
1084
|
|
|
1023
|
-
|
|
1085
|
+
return this.program.instruction.managerWithdraw({
|
|
1024
1086
|
accounts: {
|
|
1025
1087
|
vault,
|
|
1026
|
-
manager:
|
|
1088
|
+
manager: vaultAccount.manager,
|
|
1027
1089
|
vaultTokenAccount: vaultAccount.tokenAccount,
|
|
1028
1090
|
driftUser: await getUserAccountPublicKey(
|
|
1029
1091
|
this.driftClient.program.programId,
|
|
@@ -1038,14 +1100,14 @@ export class VaultClient {
|
|
|
1038
1100
|
driftSpotMarketVault: spotMarket.vault,
|
|
1039
1101
|
userTokenAccount: getAssociatedTokenAddressSync(
|
|
1040
1102
|
spotMarket.mint,
|
|
1041
|
-
|
|
1103
|
+
vaultAccount.manager,
|
|
1104
|
+
true
|
|
1042
1105
|
),
|
|
1043
1106
|
driftSigner: this.driftClient.getStateAccount().signer,
|
|
1044
1107
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1045
1108
|
},
|
|
1046
1109
|
remainingAccounts,
|
|
1047
1110
|
});
|
|
1048
|
-
return this.createAndSendTxn([ix], uiTxParams);
|
|
1049
1111
|
}
|
|
1050
1112
|
|
|
1051
1113
|
public async managerUpdateVault(
|
|
@@ -1061,12 +1123,59 @@ export class VaultClient {
|
|
|
1061
1123
|
},
|
|
1062
1124
|
uiTxParams?: TxParams
|
|
1063
1125
|
): Promise<TransactionSignature> {
|
|
1064
|
-
const ix = this.
|
|
1126
|
+
const ix = await this.getManagerUpdateVaultIx(vault, params);
|
|
1127
|
+
return this.createAndSendTxn([ix], uiTxParams);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
public async getManagerUpdateVaultIx(
|
|
1131
|
+
vault: PublicKey,
|
|
1132
|
+
params: {
|
|
1133
|
+
redeemPeriod: BN | null;
|
|
1134
|
+
maxTokens: BN | null;
|
|
1135
|
+
managementFee: BN | null;
|
|
1136
|
+
minDepositAmount: BN | null;
|
|
1137
|
+
profitShare: number | null;
|
|
1138
|
+
hurdleRate: number | null;
|
|
1139
|
+
permissioned: boolean | null;
|
|
1140
|
+
}
|
|
1141
|
+
): Promise<TransactionInstruction> {
|
|
1142
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
1143
|
+
return this.program.instruction.updateVault(params, {
|
|
1065
1144
|
accounts: {
|
|
1066
1145
|
vault,
|
|
1067
|
-
manager:
|
|
1146
|
+
manager: vaultAccount.manager,
|
|
1068
1147
|
},
|
|
1069
1148
|
});
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
public async managerUpdateVaultManager(
|
|
1152
|
+
vault: PublicKey,
|
|
1153
|
+
manager: PublicKey,
|
|
1154
|
+
uiTxParams?: TxParams
|
|
1155
|
+
): Promise<TransactionSignature> {
|
|
1156
|
+
const ix = await this.getManagerUpdateVaultManagerIx(vault, manager);
|
|
1157
|
+
return this.createAndSendTxn([ix], uiTxParams);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
public async getManagerUpdateVaultManagerIx(
|
|
1161
|
+
vault: PublicKey,
|
|
1162
|
+
manager: PublicKey
|
|
1163
|
+
): Promise<TransactionInstruction> {
|
|
1164
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
1165
|
+
return this.program.instruction.updateVaultManager(manager, {
|
|
1166
|
+
accounts: {
|
|
1167
|
+
vault,
|
|
1168
|
+
manager: vaultAccount.manager,
|
|
1169
|
+
},
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
public async applyProfitShare(
|
|
1174
|
+
vault: PublicKey,
|
|
1175
|
+
vaultDepositor: PublicKey,
|
|
1176
|
+
uiTxParams?: TxParams
|
|
1177
|
+
): Promise<TransactionSignature> {
|
|
1178
|
+
const ix = await this.getApplyProfitShareIx(vault, vaultDepositor);
|
|
1070
1179
|
return this.createAndSendTxn([ix], uiTxParams);
|
|
1071
1180
|
}
|
|
1072
1181
|
|
|
@@ -1104,7 +1213,7 @@ export class VaultClient {
|
|
|
1104
1213
|
const accounts = {
|
|
1105
1214
|
vault,
|
|
1106
1215
|
vaultDepositor,
|
|
1107
|
-
manager:
|
|
1216
|
+
manager: vaultAccount.manager,
|
|
1108
1217
|
driftUserStats: getUserStatsAccountPublicKey(
|
|
1109
1218
|
this.driftClient.program.programId,
|
|
1110
1219
|
vault
|
|
@@ -1333,6 +1442,8 @@ export class VaultClient {
|
|
|
1333
1442
|
sharesBase
|
|
1334
1443
|
);
|
|
1335
1444
|
|
|
1445
|
+
const vaultAccount = await this.program.account.vault.fetch(params.vault);
|
|
1446
|
+
|
|
1336
1447
|
const accounts = {
|
|
1337
1448
|
vault: params.vault,
|
|
1338
1449
|
vaultDepositor: getTokenizedVaultAddressSync(
|
|
@@ -1345,7 +1456,7 @@ export class VaultClient {
|
|
|
1345
1456
|
mint: mintAddress,
|
|
1346
1457
|
}),
|
|
1347
1458
|
tokenMetadataProgram: this.metaplex.programs().getTokenMetadata().address,
|
|
1348
|
-
payer:
|
|
1459
|
+
payer: vaultAccount.manager,
|
|
1349
1460
|
};
|
|
1350
1461
|
|
|
1351
1462
|
const vaultTokenAta = getAssociatedTokenAddressSync(
|
|
@@ -1354,7 +1465,7 @@ export class VaultClient {
|
|
|
1354
1465
|
true
|
|
1355
1466
|
);
|
|
1356
1467
|
const createAtaIx = createAssociatedTokenAccountInstruction(
|
|
1357
|
-
|
|
1468
|
+
vaultAccount.manager,
|
|
1358
1469
|
vaultTokenAta,
|
|
1359
1470
|
params.vault,
|
|
1360
1471
|
mintAddress
|
|
@@ -1735,6 +1846,21 @@ export class VaultClient {
|
|
|
1735
1846
|
withdrawUnit: WithdrawUnit,
|
|
1736
1847
|
txParams?: TxParams
|
|
1737
1848
|
): Promise<TransactionSignature> {
|
|
1849
|
+
const ixs = await this.getRequestWithdrawIx(
|
|
1850
|
+
vaultDepositor,
|
|
1851
|
+
amount,
|
|
1852
|
+
withdrawUnit,
|
|
1853
|
+
txParams?.oracleFeedsToCrank
|
|
1854
|
+
);
|
|
1855
|
+
return await this.createAndSendTxn(ixs, txParams);
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
public async getRequestWithdrawIx(
|
|
1859
|
+
vaultDepositor: PublicKey,
|
|
1860
|
+
amount: BN,
|
|
1861
|
+
withdrawUnit: WithdrawUnit,
|
|
1862
|
+
oracleFeedsToCrank?: { feed: PublicKey; oracleSource: OracleSource }[]
|
|
1863
|
+
): Promise<TransactionInstruction[]> {
|
|
1738
1864
|
const vaultDepositorAccount =
|
|
1739
1865
|
await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
1740
1866
|
const vaultAccount = await this.program.account.vault.fetch(
|
|
@@ -1764,7 +1890,7 @@ export class VaultClient {
|
|
|
1764
1890
|
};
|
|
1765
1891
|
|
|
1766
1892
|
const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
|
|
1767
|
-
|
|
1893
|
+
oracleFeedsToCrank
|
|
1768
1894
|
);
|
|
1769
1895
|
|
|
1770
1896
|
const requestWithdrawIx = this.program.instruction.requestWithdraw(
|
|
@@ -1780,16 +1906,27 @@ export class VaultClient {
|
|
|
1780
1906
|
}
|
|
1781
1907
|
);
|
|
1782
1908
|
|
|
1783
|
-
return
|
|
1784
|
-
[...oracleFeedsToCrankIxs, requestWithdrawIx],
|
|
1785
|
-
txParams
|
|
1786
|
-
);
|
|
1909
|
+
return [...oracleFeedsToCrankIxs, requestWithdrawIx];
|
|
1787
1910
|
}
|
|
1788
1911
|
|
|
1789
1912
|
public async withdraw(
|
|
1790
1913
|
vaultDepositor: PublicKey,
|
|
1791
1914
|
txParams?: TxParams
|
|
1792
1915
|
): Promise<TransactionSignature> {
|
|
1916
|
+
const ixs = await this.getWithdrawIx(
|
|
1917
|
+
vaultDepositor,
|
|
1918
|
+
txParams?.oracleFeedsToCrank
|
|
1919
|
+
);
|
|
1920
|
+
return await this.createAndSendTxn(ixs, {
|
|
1921
|
+
cuLimit: 850_000, // overestimating to be safe
|
|
1922
|
+
...txParams,
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
public async getWithdrawIx(
|
|
1927
|
+
vaultDepositor: PublicKey,
|
|
1928
|
+
oracleFeedsToCrank?: { feed: PublicKey; oracleSource: OracleSource }[]
|
|
1929
|
+
): Promise<TransactionInstruction[]> {
|
|
1793
1930
|
const vaultDepositorAccount =
|
|
1794
1931
|
await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
1795
1932
|
const vaultAccount = await this.program.account.vault.fetch(
|
|
@@ -1880,7 +2017,7 @@ export class VaultClient {
|
|
|
1880
2017
|
};
|
|
1881
2018
|
|
|
1882
2019
|
const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
|
|
1883
|
-
|
|
2020
|
+
oracleFeedsToCrank
|
|
1884
2021
|
);
|
|
1885
2022
|
|
|
1886
2023
|
const ixs = [
|
|
@@ -1897,11 +2034,7 @@ export class VaultClient {
|
|
|
1897
2034
|
...postIxs,
|
|
1898
2035
|
];
|
|
1899
2036
|
|
|
1900
|
-
|
|
1901
|
-
return await this.createAndSendTxn(ixs, {
|
|
1902
|
-
cuLimit: (txParams?.cuLimit ?? 650_000) + (creationIxs > 0 ? 200_000 : 0),
|
|
1903
|
-
...txParams,
|
|
1904
|
-
});
|
|
2037
|
+
return ixs;
|
|
1905
2038
|
}
|
|
1906
2039
|
|
|
1907
2040
|
public async forceWithdraw(
|
|
@@ -1971,7 +2104,7 @@ export class VaultClient {
|
|
|
1971
2104
|
}
|
|
1972
2105
|
|
|
1973
2106
|
const accounts = {
|
|
1974
|
-
manager:
|
|
2107
|
+
manager: vaultAccount.manager,
|
|
1975
2108
|
vault: vaultDepositorAccount.vault,
|
|
1976
2109
|
vaultDepositor,
|
|
1977
2110
|
vaultTokenAccount: vaultAccount.tokenAccount,
|
|
@@ -2006,6 +2139,17 @@ export class VaultClient {
|
|
|
2006
2139
|
vaultDepositor: PublicKey,
|
|
2007
2140
|
txParams?: TxParams
|
|
2008
2141
|
): Promise<TransactionSignature> {
|
|
2142
|
+
const ixs = await this.getCancelRequestWithdrawIx(
|
|
2143
|
+
vaultDepositor,
|
|
2144
|
+
txParams?.oracleFeedsToCrank
|
|
2145
|
+
);
|
|
2146
|
+
return await this.createAndSendTxn(ixs, txParams);
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
public async getCancelRequestWithdrawIx(
|
|
2150
|
+
vaultDepositor: PublicKey,
|
|
2151
|
+
oracleFeedsToCrank: TxParams['oracleFeedsToCrank']
|
|
2152
|
+
): Promise<TransactionInstruction[]> {
|
|
2009
2153
|
const vaultDepositorAccount =
|
|
2010
2154
|
await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
2011
2155
|
const vaultAccount = await this.program.account.vault.fetch(
|
|
@@ -2036,14 +2180,16 @@ export class VaultClient {
|
|
|
2036
2180
|
);
|
|
2037
2181
|
|
|
2038
2182
|
if (this.cliMode) {
|
|
2039
|
-
return
|
|
2040
|
-
.
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2183
|
+
return [
|
|
2184
|
+
await this.program.methods
|
|
2185
|
+
.cancelRequestWithdraw()
|
|
2186
|
+
.accounts(accounts)
|
|
2187
|
+
.remainingAccounts(remainingAccounts)
|
|
2188
|
+
.instruction(),
|
|
2189
|
+
];
|
|
2044
2190
|
} else {
|
|
2045
2191
|
const oracleFeedsToCrankIxs = await this.getOracleFeedsToCrank(
|
|
2046
|
-
|
|
2192
|
+
oracleFeedsToCrank
|
|
2047
2193
|
);
|
|
2048
2194
|
|
|
2049
2195
|
const cancelRequestWithdrawIx =
|
|
@@ -2055,10 +2201,7 @@ export class VaultClient {
|
|
|
2055
2201
|
remainingAccounts,
|
|
2056
2202
|
});
|
|
2057
2203
|
|
|
2058
|
-
return
|
|
2059
|
-
[...oracleFeedsToCrankIxs, cancelRequestWithdrawIx],
|
|
2060
|
-
txParams
|
|
2061
|
-
);
|
|
2204
|
+
return [...oracleFeedsToCrankIxs, cancelRequestWithdrawIx];
|
|
2062
2205
|
}
|
|
2063
2206
|
}
|
|
2064
2207
|
|
|
@@ -2072,6 +2215,13 @@ export class VaultClient {
|
|
|
2072
2215
|
vaultDepositor: PublicKey,
|
|
2073
2216
|
txParams?: TxParams
|
|
2074
2217
|
): Promise<TransactionSignature> {
|
|
2218
|
+
const ix = await this.getLiquidateIx(vaultDepositor);
|
|
2219
|
+
return await this.createAndSendTxn([ix], txParams);
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
public async getLiquidateIx(
|
|
2223
|
+
vaultDepositor: PublicKey
|
|
2224
|
+
): Promise<TransactionInstruction> {
|
|
2075
2225
|
const vaultDepositorAccount =
|
|
2076
2226
|
await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
2077
2227
|
const vault = vaultDepositorAccount.vault;
|
|
@@ -2110,17 +2260,15 @@ export class VaultClient {
|
|
|
2110
2260
|
.liquidate()
|
|
2111
2261
|
.accounts(accounts)
|
|
2112
2262
|
.remainingAccounts(remainingAccounts)
|
|
2113
|
-
.
|
|
2263
|
+
.instruction();
|
|
2114
2264
|
} else {
|
|
2115
|
-
|
|
2265
|
+
return this.program.instruction.liquidate({
|
|
2116
2266
|
accounts: {
|
|
2117
2267
|
authority: this.driftClient.wallet.publicKey,
|
|
2118
2268
|
...accounts,
|
|
2119
2269
|
},
|
|
2120
2270
|
remainingAccounts,
|
|
2121
2271
|
});
|
|
2122
|
-
|
|
2123
|
-
return await this.createAndSendTxn([liquidateIx], txParams);
|
|
2124
2272
|
}
|
|
2125
2273
|
}
|
|
2126
2274
|
|
|
@@ -2238,8 +2386,20 @@ export class VaultClient {
|
|
|
2238
2386
|
*/
|
|
2239
2387
|
public async initializeInsuranceFundStake(
|
|
2240
2388
|
vault: PublicKey,
|
|
2241
|
-
spotMarketIndex: number
|
|
2389
|
+
spotMarketIndex: number,
|
|
2390
|
+
txParams?: TxParams
|
|
2242
2391
|
): Promise<TransactionSignature> {
|
|
2392
|
+
const ixs = await this.getInitializeInsuranceFundStakeIx(
|
|
2393
|
+
vault,
|
|
2394
|
+
spotMarketIndex
|
|
2395
|
+
);
|
|
2396
|
+
return await this.createAndSendTxn([ixs], txParams);
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
public async getInitializeInsuranceFundStakeIx(
|
|
2400
|
+
vault: PublicKey,
|
|
2401
|
+
spotMarketIndex: number
|
|
2402
|
+
): Promise<TransactionInstruction> {
|
|
2243
2403
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2244
2404
|
|
|
2245
2405
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
@@ -2273,7 +2433,7 @@ export class VaultClient {
|
|
|
2273
2433
|
driftState: await this.driftClient.getStatePublicKey(),
|
|
2274
2434
|
driftProgram: this.driftClient.program.programId,
|
|
2275
2435
|
})
|
|
2276
|
-
.
|
|
2436
|
+
.instruction();
|
|
2277
2437
|
}
|
|
2278
2438
|
|
|
2279
2439
|
/**
|
|
@@ -2287,8 +2447,24 @@ export class VaultClient {
|
|
|
2287
2447
|
vault: PublicKey,
|
|
2288
2448
|
spotMarketIndex: number,
|
|
2289
2449
|
amount: BN,
|
|
2290
|
-
managerTokenAccount?: PublicKey
|
|
2450
|
+
managerTokenAccount?: PublicKey,
|
|
2451
|
+
txParams?: TxParams
|
|
2291
2452
|
): Promise<TransactionSignature> {
|
|
2453
|
+
const ixs = await this.getAddToInsuranceFundStakeIx(
|
|
2454
|
+
vault,
|
|
2455
|
+
spotMarketIndex,
|
|
2456
|
+
amount,
|
|
2457
|
+
managerTokenAccount
|
|
2458
|
+
);
|
|
2459
|
+
return await this.createAndSendTxn([ixs], txParams);
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
public async getAddToInsuranceFundStakeIx(
|
|
2463
|
+
vault: PublicKey,
|
|
2464
|
+
spotMarketIndex: number,
|
|
2465
|
+
amount: BN,
|
|
2466
|
+
managerTokenAccount?: PublicKey
|
|
2467
|
+
): Promise<TransactionInstruction> {
|
|
2292
2468
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2293
2469
|
|
|
2294
2470
|
if (!vaultAccount.manager.equals(this.driftClient.wallet.publicKey)) {
|
|
@@ -2317,7 +2493,8 @@ export class VaultClient {
|
|
|
2317
2493
|
if (!managerTokenAccount) {
|
|
2318
2494
|
managerTokenAccount = getAssociatedTokenAddressSync(
|
|
2319
2495
|
spotMarket.mint,
|
|
2320
|
-
|
|
2496
|
+
vaultAccount.manager,
|
|
2497
|
+
true
|
|
2321
2498
|
);
|
|
2322
2499
|
}
|
|
2323
2500
|
|
|
@@ -2343,14 +2520,28 @@ export class VaultClient {
|
|
|
2343
2520
|
driftSigner: this.driftClient.getStateAccount().signer,
|
|
2344
2521
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2345
2522
|
})
|
|
2346
|
-
.
|
|
2523
|
+
.instruction();
|
|
2347
2524
|
}
|
|
2348
2525
|
|
|
2349
2526
|
public async requestRemoveInsuranceFundStake(
|
|
2350
2527
|
vault: PublicKey,
|
|
2351
2528
|
spotMarketIndex: number,
|
|
2352
|
-
amount: BN
|
|
2529
|
+
amount: BN,
|
|
2530
|
+
txParams?: TxParams
|
|
2353
2531
|
): Promise<TransactionSignature> {
|
|
2532
|
+
const ix = await this.getRequestRemoveInsuranceFundStakeIx(
|
|
2533
|
+
vault,
|
|
2534
|
+
spotMarketIndex,
|
|
2535
|
+
amount
|
|
2536
|
+
);
|
|
2537
|
+
return await this.createAndSendTxn([ix], txParams);
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
public async getRequestRemoveInsuranceFundStakeIx(
|
|
2541
|
+
vault: PublicKey,
|
|
2542
|
+
spotMarketIndex: number,
|
|
2543
|
+
amount: BN
|
|
2544
|
+
): Promise<TransactionInstruction> {
|
|
2354
2545
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2355
2546
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2356
2547
|
this.driftClient.program.programId,
|
|
@@ -2373,20 +2564,32 @@ export class VaultClient {
|
|
|
2373
2564
|
.requestRemoveInsuranceFundStake(spotMarketIndex, amount)
|
|
2374
2565
|
.accounts({
|
|
2375
2566
|
vault,
|
|
2376
|
-
manager:
|
|
2567
|
+
manager: vaultAccount.manager,
|
|
2377
2568
|
driftSpotMarket: spotMarket.pubkey,
|
|
2378
2569
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2379
2570
|
insuranceFundVault: ifVaultPublicKey,
|
|
2380
2571
|
driftUserStats: vaultAccount.userStats,
|
|
2381
2572
|
driftProgram: this.driftClient.program.programId,
|
|
2382
2573
|
})
|
|
2383
|
-
.
|
|
2574
|
+
.instruction();
|
|
2384
2575
|
}
|
|
2385
2576
|
|
|
2386
2577
|
public async cancelRequestRemoveInsuranceFundStake(
|
|
2387
2578
|
vault: PublicKey,
|
|
2388
|
-
spotMarketIndex: number
|
|
2579
|
+
spotMarketIndex: number,
|
|
2580
|
+
txParams?: TxParams
|
|
2389
2581
|
): Promise<TransactionSignature> {
|
|
2582
|
+
const ix = await this.getCancelRequestRemoveInsuranceFundStakeIx(
|
|
2583
|
+
vault,
|
|
2584
|
+
spotMarketIndex
|
|
2585
|
+
);
|
|
2586
|
+
return await this.createAndSendTxn([ix], txParams);
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
public async getCancelRequestRemoveInsuranceFundStakeIx(
|
|
2590
|
+
vault: PublicKey,
|
|
2591
|
+
spotMarketIndex: number
|
|
2592
|
+
): Promise<TransactionInstruction> {
|
|
2390
2593
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2391
2594
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2392
2595
|
this.driftClient.program.programId,
|
|
@@ -2408,21 +2611,35 @@ export class VaultClient {
|
|
|
2408
2611
|
.cancelRequestRemoveInsuranceFundStake(spotMarketIndex)
|
|
2409
2612
|
.accounts({
|
|
2410
2613
|
vault: vault,
|
|
2411
|
-
manager:
|
|
2614
|
+
manager: vaultAccount.manager,
|
|
2412
2615
|
driftSpotMarket: spotMarket.pubkey,
|
|
2413
2616
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2414
2617
|
insuranceFundVault: ifVaultPublicKey,
|
|
2415
2618
|
driftUserStats: vaultAccount.userStats,
|
|
2416
2619
|
driftProgram: this.driftClient.program.programId,
|
|
2417
2620
|
})
|
|
2418
|
-
.
|
|
2621
|
+
.instruction();
|
|
2419
2622
|
}
|
|
2420
2623
|
|
|
2421
2624
|
public async removeInsuranceFundStake(
|
|
2422
2625
|
vault: PublicKey,
|
|
2423
2626
|
spotMarketIndex: number,
|
|
2424
|
-
managerTokenAccount?: PublicKey
|
|
2627
|
+
managerTokenAccount?: PublicKey,
|
|
2628
|
+
txParams?: TxParams
|
|
2425
2629
|
): Promise<TransactionSignature> {
|
|
2630
|
+
const ixs = await this.getRemoveInsuranceFundStakeIx(
|
|
2631
|
+
vault,
|
|
2632
|
+
spotMarketIndex,
|
|
2633
|
+
managerTokenAccount
|
|
2634
|
+
);
|
|
2635
|
+
return await this.createAndSendTxn([ixs], txParams);
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
public async getRemoveInsuranceFundStakeIx(
|
|
2639
|
+
vault: PublicKey,
|
|
2640
|
+
spotMarketIndex: number,
|
|
2641
|
+
managerTokenAccount?: PublicKey
|
|
2642
|
+
): Promise<TransactionInstruction> {
|
|
2426
2643
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2427
2644
|
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2428
2645
|
this.driftClient.program.programId,
|
|
@@ -2443,7 +2660,8 @@ export class VaultClient {
|
|
|
2443
2660
|
if (!managerTokenAccount) {
|
|
2444
2661
|
managerTokenAccount = getAssociatedTokenAddressSync(
|
|
2445
2662
|
spotMarket.mint,
|
|
2446
|
-
|
|
2663
|
+
vaultAccount.manager,
|
|
2664
|
+
true
|
|
2447
2665
|
);
|
|
2448
2666
|
}
|
|
2449
2667
|
|
|
@@ -2468,14 +2686,28 @@ export class VaultClient {
|
|
|
2468
2686
|
driftProgram: this.driftClient.program.programId,
|
|
2469
2687
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2470
2688
|
})
|
|
2471
|
-
.
|
|
2689
|
+
.instruction();
|
|
2472
2690
|
}
|
|
2473
2691
|
|
|
2474
2692
|
public async protocolRequestWithdraw(
|
|
2475
2693
|
vault: PublicKey,
|
|
2476
2694
|
amount: BN,
|
|
2477
|
-
withdrawUnit: WithdrawUnit
|
|
2695
|
+
withdrawUnit: WithdrawUnit,
|
|
2696
|
+
txParams?: TxParams
|
|
2478
2697
|
): Promise<TransactionSignature> {
|
|
2698
|
+
const ix = await this.getProtocolRequestWithdrawIx(
|
|
2699
|
+
vault,
|
|
2700
|
+
amount,
|
|
2701
|
+
withdrawUnit
|
|
2702
|
+
);
|
|
2703
|
+
return await this.createAndSendTxn([ix], txParams);
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
public async getProtocolRequestWithdrawIx(
|
|
2707
|
+
vault: PublicKey,
|
|
2708
|
+
amount: BN,
|
|
2709
|
+
withdrawUnit: WithdrawUnit
|
|
2710
|
+
): Promise<TransactionInstruction> {
|
|
2479
2711
|
// @ts-ignore
|
|
2480
2712
|
const vaultAccount = (await this.program.account.vault.fetch(
|
|
2481
2713
|
vault
|
|
@@ -2516,7 +2748,7 @@ export class VaultClient {
|
|
|
2516
2748
|
.managerRequestWithdraw(amount, withdrawUnit)
|
|
2517
2749
|
.accounts(accounts)
|
|
2518
2750
|
.remainingAccounts(remainingAccounts)
|
|
2519
|
-
.
|
|
2751
|
+
.instruction();
|
|
2520
2752
|
} else {
|
|
2521
2753
|
const requestWithdrawIx = this.program.instruction.managerRequestWithdraw(
|
|
2522
2754
|
// @ts-ignore
|
|
@@ -2524,20 +2756,28 @@ export class VaultClient {
|
|
|
2524
2756
|
withdrawUnit,
|
|
2525
2757
|
{
|
|
2526
2758
|
accounts: {
|
|
2527
|
-
manager:
|
|
2759
|
+
manager: vaultAccount.manager,
|
|
2528
2760
|
...accounts,
|
|
2529
2761
|
},
|
|
2530
2762
|
remainingAccounts,
|
|
2531
2763
|
}
|
|
2532
2764
|
);
|
|
2533
2765
|
|
|
2534
|
-
return
|
|
2766
|
+
return requestWithdrawIx;
|
|
2535
2767
|
}
|
|
2536
2768
|
}
|
|
2537
2769
|
|
|
2538
2770
|
public async protocolCancelWithdrawRequest(
|
|
2539
|
-
vault: PublicKey
|
|
2771
|
+
vault: PublicKey,
|
|
2772
|
+
txParams?: TxParams
|
|
2540
2773
|
): Promise<TransactionSignature> {
|
|
2774
|
+
const ixs = await this.getProtocolCancelWithdrawRequestIx(vault);
|
|
2775
|
+
return await this.createAndSendTxn(ixs, txParams);
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
public async getProtocolCancelWithdrawRequestIx(
|
|
2779
|
+
vault: PublicKey
|
|
2780
|
+
): Promise<TransactionInstruction[]> {
|
|
2541
2781
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2542
2782
|
|
|
2543
2783
|
const userStatsKey = getUserStatsAccountPublicKey(
|
|
@@ -2546,7 +2786,7 @@ export class VaultClient {
|
|
|
2546
2786
|
);
|
|
2547
2787
|
|
|
2548
2788
|
const accounts = {
|
|
2549
|
-
manager:
|
|
2789
|
+
manager: vaultAccount.manager,
|
|
2550
2790
|
vault,
|
|
2551
2791
|
driftUserStats: userStatsKey,
|
|
2552
2792
|
driftUser: vaultAccount.user,
|
|
@@ -2564,28 +2804,38 @@ export class VaultClient {
|
|
|
2564
2804
|
);
|
|
2565
2805
|
|
|
2566
2806
|
if (this.cliMode) {
|
|
2567
|
-
return
|
|
2568
|
-
.
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2807
|
+
return [
|
|
2808
|
+
await this.program.methods
|
|
2809
|
+
.mangerCancelWithdrawRequest()
|
|
2810
|
+
.accounts(accounts)
|
|
2811
|
+
.remainingAccounts(remainingAccounts)
|
|
2812
|
+
.instruction(),
|
|
2813
|
+
];
|
|
2572
2814
|
} else {
|
|
2573
2815
|
const cancelRequestWithdrawIx =
|
|
2574
2816
|
this.program.instruction.mangerCancelWithdrawRequest({
|
|
2575
2817
|
accounts: {
|
|
2576
2818
|
...accounts,
|
|
2577
|
-
manager:
|
|
2819
|
+
manager: vaultAccount.manager,
|
|
2578
2820
|
},
|
|
2579
2821
|
remainingAccounts,
|
|
2580
2822
|
});
|
|
2581
2823
|
|
|
2582
|
-
return
|
|
2824
|
+
return [cancelRequestWithdrawIx];
|
|
2583
2825
|
}
|
|
2584
2826
|
}
|
|
2585
2827
|
|
|
2586
2828
|
public async protocolWithdraw(
|
|
2587
|
-
vault: PublicKey
|
|
2829
|
+
vault: PublicKey,
|
|
2830
|
+
txParams?: TxParams
|
|
2588
2831
|
): Promise<TransactionSignature> {
|
|
2832
|
+
const ixs = await this.getProtocolWithdrawIx(vault);
|
|
2833
|
+
return await this.createAndSendTxn(ixs, txParams);
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2836
|
+
public async getProtocolWithdrawIx(
|
|
2837
|
+
vault: PublicKey
|
|
2838
|
+
): Promise<TransactionInstruction[]> {
|
|
2589
2839
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2590
2840
|
|
|
2591
2841
|
if (!this.driftClient.wallet.publicKey.equals(vaultAccount.manager)) {
|
|
@@ -2619,7 +2869,7 @@ export class VaultClient {
|
|
|
2619
2869
|
const ix = this.program.instruction.managerWithdraw({
|
|
2620
2870
|
accounts: {
|
|
2621
2871
|
vault,
|
|
2622
|
-
manager:
|
|
2872
|
+
manager: vaultAccount.manager,
|
|
2623
2873
|
vaultTokenAccount: vaultAccount.tokenAccount,
|
|
2624
2874
|
driftUser: await getUserAccountPublicKey(
|
|
2625
2875
|
this.driftClient.program.programId,
|
|
@@ -2638,9 +2888,7 @@ export class VaultClient {
|
|
|
2638
2888
|
},
|
|
2639
2889
|
remainingAccounts,
|
|
2640
2890
|
});
|
|
2641
|
-
return
|
|
2642
|
-
cuLimit: 1_000_000,
|
|
2643
|
-
});
|
|
2891
|
+
return [ix];
|
|
2644
2892
|
}
|
|
2645
2893
|
|
|
2646
2894
|
private async getOracleFeedsToCrank(
|
|
@@ -2676,15 +2924,24 @@ export class VaultClient {
|
|
|
2676
2924
|
},
|
|
2677
2925
|
txParams?: TxParams
|
|
2678
2926
|
): Promise<TransactionSignature> {
|
|
2679
|
-
const ix = await this.
|
|
2927
|
+
const ix = await this.getUpdateVaultProtocolIx(vault, params);
|
|
2928
|
+
return await this.createAndSendTxn([ix], txParams);
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
public async getUpdateVaultProtocolIx(
|
|
2932
|
+
vault: PublicKey,
|
|
2933
|
+
params: {
|
|
2934
|
+
protocolFee: BN | null;
|
|
2935
|
+
protocolProfitShare: number | null;
|
|
2936
|
+
}
|
|
2937
|
+
): Promise<TransactionInstruction> {
|
|
2938
|
+
return this.program.methods
|
|
2680
2939
|
.updateVaultProtocol(params)
|
|
2681
2940
|
.accounts({
|
|
2682
2941
|
vault,
|
|
2683
2942
|
vaultProtocol: this.getVaultProtocolAddress(vault),
|
|
2684
2943
|
})
|
|
2685
2944
|
.instruction();
|
|
2686
|
-
|
|
2687
|
-
return await this.createAndSendTxn([ix], txParams);
|
|
2688
2945
|
}
|
|
2689
2946
|
|
|
2690
2947
|
public async updateCumulativeFuelAmount(
|
|
@@ -2834,11 +3091,12 @@ export class VaultClient {
|
|
|
2834
3091
|
vault: PublicKey,
|
|
2835
3092
|
fuelDistributionMode: FuelDistributionMode
|
|
2836
3093
|
): Promise<TransactionInstruction> {
|
|
3094
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2837
3095
|
return this.program.methods
|
|
2838
3096
|
.managerUpdateFuelDistributionMode(fuelDistributionMode as number)
|
|
2839
3097
|
.accounts({
|
|
2840
3098
|
vault,
|
|
2841
|
-
manager:
|
|
3099
|
+
manager: vaultAccount.manager,
|
|
2842
3100
|
})
|
|
2843
3101
|
.instruction();
|
|
2844
3102
|
}
|