@zebec-network/solana-payroll-sdk 2.6.0-dev.2 → 2.7.0

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/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
- # The MIT License (MIT)
2
-
3
- Copyright © 2025 Zebec Network
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # The MIT License (MIT)
2
+
3
+ Copyright © 2025 Zebec Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -141,9 +141,6 @@ export declare function createCompleteUnlockInstruction(program: Program<ZebecPa
141
141
  companyTokenAta: PublicKey;
142
142
  depositMint: PublicKey;
143
143
  centralVault: PublicKey;
144
- centralVaultUsxAta: PublicKey;
145
- usxMint: PublicKey;
146
- companyUsxAta: PublicKey;
147
144
  }, data: {
148
145
  companyId: number[];
149
146
  nonce: BN;
@@ -160,6 +157,19 @@ export declare function createDistributeRewardsInstruction(program: Program<Zebe
160
157
  }[];
161
158
  checkId: number[];
162
159
  }, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
160
+ export declare function createWithdrawRewardsInstruction(program: Program<ZebecPayrollIdl>, accounts: {
161
+ admin: PublicKey;
162
+ centralVault: PublicKey;
163
+ company: PublicKey;
164
+ companyDeposit: PublicKey;
165
+ yieldConfig: PublicKey;
166
+ centralVaultUsxAta: PublicKey;
167
+ companyUsxAta: PublicKey;
168
+ usxMint: PublicKey;
169
+ }, data: {
170
+ companyId: number[];
171
+ nonce: BN;
172
+ }): Promise<TransactionInstruction>;
163
173
  export declare function createCreateCardInstruction(payrollProgram: Program<ZebecPayrollIdl>, accounts: {
164
174
  cardPurchasePda: PublicKey;
165
175
  cardVault: PublicKey;
@@ -184,9 +184,6 @@ export async function createCompleteUnlockInstruction(program, accounts, data) {
184
184
  companyTokenAta: accounts.companyTokenAta,
185
185
  depositMint: accounts.depositMint,
186
186
  centralVault: accounts.centralVault,
187
- centralVaultUsxAta: accounts.centralVaultUsxAta,
188
- usxMint: accounts.usxMint,
189
- companyUsxAta: accounts.companyUsxAta,
190
187
  })
191
188
  .instruction();
192
189
  }
@@ -201,6 +198,21 @@ export async function createDistributeRewardsInstruction(program, accounts, data
201
198
  .remainingAccounts(remainingAccounts)
202
199
  .instruction();
203
200
  }
201
+ export async function createWithdrawRewardsInstruction(program, accounts, data) {
202
+ return program.methods
203
+ .withdrawRewards(data.companyId, data.nonce)
204
+ .accountsPartial({
205
+ admin: accounts.admin,
206
+ centralVault: accounts.centralVault,
207
+ company: accounts.company,
208
+ companyDeposit: accounts.companyDeposit,
209
+ yieldConfig: accounts.yieldConfig,
210
+ centralVaultUsxAta: accounts.centralVaultUsxAta,
211
+ companyUsxAta: accounts.companyUsxAta,
212
+ usxMint: accounts.usxMint,
213
+ })
214
+ .instruction();
215
+ }
204
216
  export async function createCreateCardInstruction(payrollProgram, accounts, data) {
205
217
  return payrollProgram.methods
206
218
  .enterpriseCreateCard({
@@ -3,7 +3,7 @@ import { type Commitment } from "@solana/web3.js";
3
3
  import { MultiTransactionPayload, TransactionPayload } from "@zebec-network/solana-common";
4
4
  import type { ZebecConfigs as ZebecConfigsIdl } from "@zebec-network/zebec_configs";
5
5
  import type { ZebecPayroll as ZebecPayrollIdl } from "@zebec-network/zebec_payroll";
6
- import type { CancelMultiplePayrollParams, CancelPayrollParams, CancelUnlockParams, CardPurchaseInfo, ChangePayrollReceiverParams, CompanyDepositInfo, CompanyNonceInfo, CompleteUnlockParams, CreateCardParams, CreateMultiplePayrollParams, CreatePayrollParams, DistributeRewardsParams, PauseResumeMultiplePayrollParams, PauseResumePayrollParams, PayrollConfigInfo, PayrollMetadataInfo, RequestUnlockParams, SetMultipleTopupDelegateParams, SetTopupDelegateParams, SwapAndCreateCardParams, TokenMetadata, TopupMultiplePayrollParams, TopupPayrollParams, UserPurchaseRecordInfo, WithdrawMultiplePayrollParams, WithdrawPayrollParams, YieldDepositParams } from "./types.js";
6
+ import type { CancelMultiplePayrollParams, CancelPayrollParams, CancelUnlockParams, CardPurchaseInfo, ChangePayrollReceiverParams, CompanyDepositInfo, CompanyNonceInfo, CompleteUnlockParams, CreateCardParams, CreateMultiplePayrollParams, CreatePayrollParams, DistributeRewardsParams, PauseResumeMultiplePayrollParams, PauseResumePayrollParams, PayrollConfigInfo, PayrollMetadataInfo, RequestUnlockParams, SetMultipleTopupDelegateParams, SetTopupDelegateParams, SwapAndCreateCardParams, TokenMetadata, TopupMultiplePayrollParams, TopupPayrollParams, UserPurchaseRecordInfo, WithdrawMultiplePayrollParams, WithdrawPayrollParams, WithdrawRewardsParams, YieldDepositParams } from "./types.js";
7
7
  export declare function getPayrollConfig(configProgram: Program<ZebecConfigsIdl>, configName: string): Promise<PayrollConfigInfo>;
8
8
  export declare function getWhitelistedTokens(configProgram: Program<ZebecConfigsIdl>, configName: string, commitment?: "processed" | "confirmed" | "finalized"): Promise<TokenMetadata[]>;
9
9
  export declare function getPayrollMetadataInfo(program: Program<ZebecPayrollIdl>, payrollMetadata: Address, commitment?: Commitment): Promise<PayrollMetadataInfo>;
@@ -26,6 +26,7 @@ export declare function requestUnlock(payrollProgram: Program<ZebecPayrollIdl>,
26
26
  export declare function cancelUnlock(payrollProgram: Program<ZebecPayrollIdl>, params: CancelUnlockParams): Promise<TransactionPayload>;
27
27
  export declare function completeUnlock(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: CompleteUnlockParams, commitment?: Commitment): Promise<TransactionPayload>;
28
28
  export declare function distributeRewards(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: DistributeRewardsParams): Promise<TransactionPayload>;
29
+ export declare function withdrawRewards(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: WithdrawRewardsParams, commitment?: Commitment): Promise<TransactionPayload>;
29
30
  export declare function getCompanyDeposit(payrollProgram: Program<ZebecPayrollIdl>, company: Address): Promise<CompanyDepositInfo | null>;
30
31
  export declare function createCard(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: CreateCardParams): Promise<TransactionPayload>;
31
32
  export declare function swapAndCreateCard(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: SwapAndCreateCardParams): Promise<TransactionPayload>;
package/dist/services.js CHANGED
@@ -9,7 +9,7 @@ import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync,
9
9
  import { BigNumber } from "bignumber.js";
10
10
  import { BN } from "bn.js";
11
11
  import { CARD_LOOKUP_TABLE_ADDRESS, ED25519_SIGNATURE_SIZE, JUPITER_AGGREGATOR_PROGRAM_ID, JUPITER_SWAP_API, PAYROLL_NAME_BUFFER_SIZE, PAYROLL_TOKEN_PRICE_MESSAGE_SIZE, USX_DECIMALS, } from "./constants.js";
12
- import { createCancelPayrollInstruction, createCancelUnlockInstruction, createChangeRecipientInstruction, createCompleteUnlockInstruction, createCreateCardInstruction, createCreatePayrollInstruction, createDistributeRewardsInstruction, createPauseResumePayrollInstruction, createRequestUnlockInstruction, createSetTopupDelegateInstruction, createSwapAndCreateCardInstruction, createTopupPayrollInstruction, createWithdrawPayrollInstruction, createYieldDepositInstruction, } from "./instructions.js";
12
+ import { createCancelPayrollInstruction, createCancelUnlockInstruction, createChangeRecipientInstruction, createCompleteUnlockInstruction, createCreateCardInstruction, createCreatePayrollInstruction, createDistributeRewardsInstruction, createPauseResumePayrollInstruction, createRequestUnlockInstruction, createSetTopupDelegateInstruction, createSwapAndCreateCardInstruction, createTopupPayrollInstruction, createWithdrawPayrollInstruction, createWithdrawRewardsInstruction, createYieldDepositInstruction, } from "./instructions.js";
13
13
  import { deriveCheckAccountPda, deriveCompanyDepositPda, deriveCompanyNoncePda, deriveEnterpriseCardConfigPda, deriveEnterpriseCardIndexPda, deriveEnterpriseCardPurchasePda, deriveEnterpriseUserPurchaseRecordPda, derivePayrollConfigPda, derivePayrollVaultPda, deriveYieldConfigPda, } from "./pda.js";
14
14
  import { deductFeeFromAmount, getConnectionFromProgram,
15
15
  // getFeeInfoForPayroll,
@@ -761,7 +761,6 @@ export async function completeUnlock(payrollProgram, configsProgram, params, com
761
761
  }
762
762
  const admin = configData.admin;
763
763
  const centralVault = configData.centralVault;
764
- const usxMint = configData.usxMint;
765
764
  if (params.companyVaultKeypair &&
766
765
  !centralVault.equals(params.companyVaultKeypair.publicKey)) {
767
766
  throw new Error("Given keypair is not of companyVault");
@@ -773,9 +772,7 @@ export async function completeUnlock(payrollProgram, configsProgram, params, com
773
772
  }
774
773
  const depositMint = companyDepositData.depositMint;
775
774
  const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint, centralVault, true);
776
- const centralVaultUsxAta = getAssociatedTokenAddressSync(usxMint, centralVault, true);
777
775
  const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
778
- const companyUsxAta = getAssociatedTokenAddressSync(usxMint, company, true);
779
776
  const ix = await createCompleteUnlockInstruction(payrollProgram, {
780
777
  admin,
781
778
  feePayer,
@@ -784,11 +781,8 @@ export async function completeUnlock(payrollProgram, configsProgram, params, com
784
781
  yieldConfig,
785
782
  centralVault,
786
783
  centralVaultTokenAta,
787
- centralVaultUsxAta,
788
784
  companyTokenAta,
789
- companyUsxAta,
790
785
  depositMint,
791
- usxMint,
792
786
  }, {
793
787
  companyId: Array.from(params.companyId),
794
788
  nonce: new BN(params.nonce.toString()),
@@ -826,6 +820,42 @@ export async function distributeRewards(payrollProgram, configsProgram, params)
826
820
  }, remainingAccounts);
827
821
  return createTransactionPayload(payrollProgram, feePayer, [ix]);
828
822
  }
823
+ export async function withdrawRewards(payrollProgram, configsProgram, params, commitment) {
824
+ commitment = commitment ?? payrollProgram.provider.connection.commitment;
825
+ const company = translateAddress(params.company);
826
+ const feePayer = params.feePayer
827
+ ? translateAddress(params.feePayer)
828
+ : company;
829
+ const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
830
+ const configData = await configsProgram.account.yieldConfig.fetchNullable(yieldConfig, commitment);
831
+ if (!configData) {
832
+ throw new Error("Yield config is not initialized in Zebec Configs Program");
833
+ }
834
+ const admin = params.admin
835
+ ? translateAddress(params.admin)
836
+ : configData.admin;
837
+ const centralVault = params.centralVault
838
+ ? translateAddress(params.centralVault)
839
+ : configData.centralVault;
840
+ const usxMint = configData.usxMint;
841
+ const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
842
+ const centralVaultUsxAta = getAssociatedTokenAddressSync(usxMint, centralVault, true);
843
+ const companyUsxAta = getAssociatedTokenAddressSync(usxMint, company, true);
844
+ const ix = await createWithdrawRewardsInstruction(payrollProgram, {
845
+ admin,
846
+ centralVault,
847
+ company,
848
+ companyDeposit,
849
+ yieldConfig,
850
+ centralVaultUsxAta,
851
+ companyUsxAta,
852
+ usxMint,
853
+ }, {
854
+ companyId: Array.from(params.companyId),
855
+ nonce: new BN(params.nonce.toString()),
856
+ });
857
+ return createTransactionPayload(payrollProgram, feePayer, [ix]);
858
+ }
829
859
  export async function getCompanyDeposit(payrollProgram, company) {
830
860
  const data = await payrollProgram.account.companyDeposit.fetch(translateAddress(company));
831
861
  if (!data) {
package/dist/types.d.ts CHANGED
@@ -231,6 +231,14 @@ export type CompleteUnlockParams = {
231
231
  nonce: bigint;
232
232
  companyVaultKeypair?: Keypair;
233
233
  };
234
+ export type WithdrawRewardsParams = {
235
+ company: Address;
236
+ companyId: Buffer | Uint8Array;
237
+ nonce: bigint;
238
+ feePayer?: Address;
239
+ admin?: Address;
240
+ centralVault?: Address;
241
+ };
234
242
  export type DistributeRewardsParams = {
235
243
  admin: Address;
236
244
  feePayer: Address;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "@zebec-network/core-utils": "^1.3.1",
12
12
  "@zebec-network/solana-common": "^2.6.1",
13
13
  "@zebec-network/zebec_configs": "^1.2.6",
14
- "@zebec-network/zebec_payroll": "^1.5.4",
14
+ "@zebec-network/zebec_payroll": "1.5.6",
15
15
  "bignumber.js": "^11.1.1",
16
16
  "bn.js": "^5.2.3"
17
17
  },
@@ -45,5 +45,5 @@
45
45
  },
46
46
  "type": "module",
47
47
  "types": "dist/index.d.ts",
48
- "version": "2.6.0-dev.2"
48
+ "version": "2.7.0"
49
49
  }