@zebec-network/solana-payroll-sdk 2.0.0 → 2.1.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.
@@ -98,3 +98,36 @@ export declare function createTransferFeesInstruction(program: Program<ZebecPayr
98
98
  decimals: number;
99
99
  feeAmount: BN;
100
100
  }): Promise<TransactionInstruction>;
101
+ export declare function createInitYieldConfigInstruction(program: Program<ZebecPayrollIdl>, accounts: {
102
+ admin: PublicKey;
103
+ yieldConfig: PublicKey;
104
+ vault: PublicKey;
105
+ vaultUsdtAta: PublicKey;
106
+ usdtMint: PublicKey;
107
+ usxMint: PublicKey;
108
+ }, data: {
109
+ minUnlockAmount: BN;
110
+ unlockCooldown: BN;
111
+ }): Promise<TransactionInstruction>;
112
+ export declare function createYieldDepositInstruction(program: Program<ZebecPayrollIdl>, accounts: {
113
+ company: PublicKey;
114
+ companyDeposit: PublicKey;
115
+ yieldConfig: PublicKey;
116
+ vault: PublicKey;
117
+ vaultUsdtAta: PublicKey;
118
+ companyUsdtAta: PublicKey;
119
+ usdtMint: PublicKey;
120
+ }, data: {
121
+ amount: BN;
122
+ }): Promise<TransactionInstruction>;
123
+ export declare function createUnlockNowInstruction(program: Program<ZebecPayrollIdl>, accounts: {
124
+ admin: PublicKey;
125
+ feePayer: PublicKey;
126
+ company: PublicKey;
127
+ companyDeposit: PublicKey;
128
+ yieldConfig: PublicKey;
129
+ vault: PublicKey;
130
+ vaultUsdtAta: PublicKey;
131
+ companyUsdtAta: PublicKey;
132
+ usdtMint: PublicKey;
133
+ }): Promise<TransactionInstruction>;
@@ -131,3 +131,49 @@ export async function createTransferFeesInstruction(program, accounts, data) {
131
131
  })
132
132
  .instruction();
133
133
  }
134
+ export async function createInitYieldConfigInstruction(program, accounts, data) {
135
+ return program.methods
136
+ .initYieldConfig({
137
+ minUnlockAmount: data.minUnlockAmount,
138
+ unlockCooldown: data.unlockCooldown,
139
+ })
140
+ .accountsPartial({
141
+ admin: accounts.admin,
142
+ yieldConfig: accounts.yieldConfig,
143
+ vault: accounts.vault,
144
+ vaultUsdtAta: accounts.vaultUsdtAta,
145
+ usdtMint: accounts.usdtMint,
146
+ usxMint: accounts.usxMint,
147
+ })
148
+ .instruction();
149
+ }
150
+ export async function createYieldDepositInstruction(program, accounts, data) {
151
+ return program.methods
152
+ .yieldDeposit(data.amount)
153
+ .accountsPartial({
154
+ company: accounts.company,
155
+ companyDeposit: accounts.companyDeposit,
156
+ yieldConfig: accounts.yieldConfig,
157
+ vault: accounts.vault,
158
+ vaultUsdtAta: accounts.vaultUsdtAta,
159
+ companyUsdtAta: accounts.companyUsdtAta,
160
+ usdtMint: accounts.usdtMint,
161
+ })
162
+ .instruction();
163
+ }
164
+ export async function createUnlockNowInstruction(program, accounts) {
165
+ return program.methods
166
+ .unlockNow()
167
+ .accountsPartial({
168
+ admin: accounts.admin,
169
+ feePayer: accounts.feePayer,
170
+ company: accounts.company,
171
+ companyDeposit: accounts.companyDeposit,
172
+ yieldConfig: accounts.yieldConfig,
173
+ vault: accounts.vault,
174
+ vaultUsdtAta: accounts.vaultUsdtAta,
175
+ companyUsdtAta: accounts.companyUsdtAta,
176
+ usdtMint: accounts.usdtMint,
177
+ })
178
+ .instruction();
179
+ }
package/dist/pda.d.ts CHANGED
@@ -2,3 +2,6 @@ import { type Address } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  export declare function derivePayrollConfigPda(configName: string, configProgramId: Address): [PublicKey, number];
4
4
  export declare function derivePayrollVaultPda(metatadata: Address, payrollProgramId: Address): [PublicKey, number];
5
+ export declare function deriveYieldConfigPda(payrollProgramId: Address): [PublicKey, number];
6
+ export declare function deriveYieldVaultPda(payrollProgramId: Address): [PublicKey, number];
7
+ export declare function deriveCompanyDepositPda(company: Address, payrollProgramId: Address): [PublicKey, number];
package/dist/pda.js CHANGED
@@ -6,9 +6,23 @@ import { PublicKey } from "@solana/web3.js";
6
6
  const PAYROLL_CONFIG_SEEDS = {
7
7
  PAYROLL_CONFIG: utils.bytes.utf8.encode("payroll_config"),
8
8
  };
9
+ const YIELD_SEEDS = {
10
+ YIELD_CONFIG: utils.bytes.utf8.encode("yield_config"),
11
+ YIELD_VAULT: utils.bytes.utf8.encode("yield_vault"),
12
+ COMPANY_DEPOSIT: utils.bytes.utf8.encode("Yield"),
13
+ };
9
14
  export function derivePayrollConfigPda(configName, configProgramId) {
10
15
  return PublicKey.findProgramAddressSync([PAYROLL_CONFIG_SEEDS.PAYROLL_CONFIG, utils.bytes.utf8.encode(configName)], translateAddress(configProgramId));
11
16
  }
12
17
  export function derivePayrollVaultPda(metatadata, payrollProgramId) {
13
18
  return PublicKey.findProgramAddressSync([translateAddress(metatadata).toBuffer()], translateAddress(payrollProgramId));
14
19
  }
20
+ export function deriveYieldConfigPda(payrollProgramId) {
21
+ return PublicKey.findProgramAddressSync([YIELD_SEEDS.YIELD_CONFIG], translateAddress(payrollProgramId));
22
+ }
23
+ export function deriveYieldVaultPda(payrollProgramId) {
24
+ return PublicKey.findProgramAddressSync([YIELD_SEEDS.YIELD_VAULT], translateAddress(payrollProgramId));
25
+ }
26
+ export function deriveCompanyDepositPda(company, payrollProgramId) {
27
+ return PublicKey.findProgramAddressSync([translateAddress(company).toBuffer(), YIELD_SEEDS.COMPANY_DEPOSIT], translateAddress(payrollProgramId));
28
+ }
@@ -1,9 +1,9 @@
1
1
  import { type Address, type Program } from "@coral-xyz/anchor";
2
- import { type Commitment } from "@solana/web3.js";
2
+ import { type Commitment, PublicKey } 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 { CancelPayrollParams, ChangePayrollReceiverParams, CreateMultiplePayrollParams, CreatePayrollParams, PayrollConfigInfo, PayrollMetadataInfo, SetTopupDelegateParams, TokenMetadata, TopupPayrollParams, WithdrawPayrollParams } from "./types.js";
6
+ import type { CancelPayrollParams, ChangePayrollReceiverParams, CreateMultiplePayrollParams, CreatePayrollParams, InitYieldConfigParams, PayrollConfigInfo, PayrollMetadataInfo, SetTopupDelegateParams, TokenMetadata, TopupPayrollParams, UnlockNowParams, WithdrawPayrollParams, 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>;
@@ -17,3 +17,19 @@ export declare function withdrawPayroll(payrollProgram: Program<ZebecPayrollIdl>
17
17
  export declare function changePayrollReceiver(program: Program<ZebecPayrollIdl>, params: ChangePayrollReceiverParams): Promise<TransactionPayload>;
18
18
  export declare function setTopupDelegate(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: SetTopupDelegateParams): Promise<TransactionPayload>;
19
19
  export declare function topupPayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: TopupPayrollParams): Promise<TransactionPayload>;
20
+ export declare function initYieldConfig(payrollProgram: Program<ZebecPayrollIdl>, params: InitYieldConfigParams): Promise<TransactionPayload>;
21
+ export declare function yieldDeposit(payrollProgram: Program<ZebecPayrollIdl>, params: YieldDepositParams): Promise<TransactionPayload>;
22
+ export declare function unlockNow(payrollProgram: Program<ZebecPayrollIdl>, params: UnlockNowParams): Promise<TransactionPayload>;
23
+ export declare function getCompanyDeposit(payrollProgram: Program<ZebecPayrollIdl>, company: Address): Promise<{
24
+ company: PublicKey;
25
+ depositedAmount: import("bn.js");
26
+ rewardsReceived: import("bn.js");
27
+ depositTime: import("bn.js");
28
+ hasDeposited: boolean;
29
+ pendingUnlock: {
30
+ usdtAmount: import("bn.js");
31
+ usxAmount: import("bn.js");
32
+ requestTime: import("bn.js");
33
+ } | null;
34
+ bump: number;
35
+ }>;
package/dist/services.js CHANGED
@@ -8,8 +8,8 @@ import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync,
8
8
  import { BigNumber } from "bignumber.js";
9
9
  import { BN } from "bn.js";
10
10
  import { PAYROLL_NAME_BUFFER_SIZE } from "./constants.js";
11
- import { createCancelPayrollInstruction, createChangeRecipientInstruction, createCreatePayrollInstruction, createPauseResumePayrollInstruction, createSetTopupDelegateInstruction, createTopupPayrollInstruction, createTransferFeesInstruction, createWithdrawPayrollInstruction, } from "./instructions.js";
12
- import { derivePayrollConfigPda, derivePayrollVaultPda } from "./pda.js";
11
+ import { createCancelPayrollInstruction, createChangeRecipientInstruction, createCreatePayrollInstruction, createInitYieldConfigInstruction, createPauseResumePayrollInstruction, createSetTopupDelegateInstruction, createTopupPayrollInstruction, createTransferFeesInstruction, createUnlockNowInstruction, createWithdrawPayrollInstruction, createYieldDepositInstruction, } from "./instructions.js";
12
+ import { deriveCompanyDepositPda, derivePayrollConfigPda, derivePayrollVaultPda, deriveYieldConfigPda, deriveYieldVaultPda, } from "./pda.js";
13
13
  import { getFeeInfoForPayroll } from "./utils.js";
14
14
  export async function getPayrollConfig(configProgram, configName) {
15
15
  const [payrollConfigPda] = derivePayrollConfigPda(configName, configProgram.programId);
@@ -526,3 +526,75 @@ export async function topupPayroll(payrollProgram, configProgram, params) {
526
526
  });
527
527
  return createPayload(payrollProgram, caller, [ix]);
528
528
  }
529
+ export async function initYieldConfig(payrollProgram, params) {
530
+ const admin = translateAddress(params.admin);
531
+ const usdtMint = translateAddress(params.usdtMint);
532
+ const usxMint = translateAddress(params.usxMint);
533
+ const [yieldConfig] = deriveYieldConfigPda(payrollProgram.programId);
534
+ const [vault] = deriveYieldVaultPda(payrollProgram.programId);
535
+ const vaultUsdtAta = getAssociatedTokenAddressSync(usdtMint, vault, true);
536
+ const usdtDecimals = await getMintDecimals(payrollProgram.provider.connection, usdtMint);
537
+ const minUnlockAmount = new BN(BigNumber(params.minUnlockAmount)
538
+ .times(TEN_BIGNUM.pow(usdtDecimals))
539
+ .toFixed(0));
540
+ const ix = await createInitYieldConfigInstruction(payrollProgram, {
541
+ admin,
542
+ yieldConfig,
543
+ vault,
544
+ vaultUsdtAta,
545
+ usdtMint,
546
+ usxMint,
547
+ }, {
548
+ minUnlockAmount,
549
+ unlockCooldown: new BN(params.unlockCooldown),
550
+ });
551
+ return createPayload(payrollProgram, admin, [ix]);
552
+ }
553
+ export async function yieldDeposit(payrollProgram, params) {
554
+ const company = translateAddress(params.company);
555
+ const usdtMint = translateAddress(params.usdtMint);
556
+ const [companyDeposit] = deriveCompanyDepositPda(company, payrollProgram.programId);
557
+ const [yieldConfig] = deriveYieldConfigPda(payrollProgram.programId);
558
+ const [vault] = deriveYieldVaultPda(payrollProgram.programId);
559
+ const vaultUsdtAta = getAssociatedTokenAddressSync(usdtMint, vault, true);
560
+ const companyUsdtAta = getAssociatedTokenAddressSync(usdtMint, company, true);
561
+ const usdtDecimals = await getMintDecimals(payrollProgram.provider.connection, usdtMint);
562
+ const amount = new BN(BigNumber(params.amount).times(TEN_BIGNUM.pow(usdtDecimals)).toFixed(0));
563
+ const ix = await createYieldDepositInstruction(payrollProgram, {
564
+ company,
565
+ companyDeposit,
566
+ yieldConfig,
567
+ vault,
568
+ vaultUsdtAta,
569
+ companyUsdtAta,
570
+ usdtMint,
571
+ }, { amount });
572
+ return createPayload(payrollProgram, company, [ix]);
573
+ }
574
+ export async function unlockNow(payrollProgram, params) {
575
+ const admin = translateAddress(params.admin);
576
+ const company = translateAddress(params.company);
577
+ const usdtMint = translateAddress(params.usdtMint);
578
+ const feePayer = params.feePayer ? translateAddress(params.feePayer) : admin;
579
+ const [companyDeposit] = deriveCompanyDepositPda(company, payrollProgram.programId);
580
+ const [yieldConfig] = deriveYieldConfigPda(payrollProgram.programId);
581
+ const [vault] = deriveYieldVaultPda(payrollProgram.programId);
582
+ const vaultUsdtAta = getAssociatedTokenAddressSync(usdtMint, vault, true);
583
+ const companyUsdtAta = getAssociatedTokenAddressSync(usdtMint, company, true);
584
+ const ix = await createUnlockNowInstruction(payrollProgram, {
585
+ admin,
586
+ feePayer,
587
+ company,
588
+ companyDeposit,
589
+ yieldConfig,
590
+ vault,
591
+ vaultUsdtAta,
592
+ companyUsdtAta,
593
+ usdtMint,
594
+ });
595
+ return createPayload(payrollProgram, feePayer, [ix]);
596
+ }
597
+ export async function getCompanyDeposit(payrollProgram, company) {
598
+ const account = await payrollProgram.account.companyDeposit.fetch(translateAddress(company));
599
+ return account;
600
+ }
package/dist/types.d.ts CHANGED
@@ -166,6 +166,24 @@ export type SetTopupDelegateParams = {
166
166
  payrollMetadata: Address;
167
167
  amount: Numeric;
168
168
  };
169
+ export type InitYieldConfigParams = {
170
+ admin: Address;
171
+ usdtMint: Address;
172
+ usxMint: Address;
173
+ minUnlockAmount: Numeric;
174
+ unlockCooldown: number;
175
+ };
176
+ export type YieldDepositParams = {
177
+ company: Address;
178
+ usdtMint: Address;
179
+ amount: Numeric;
180
+ };
181
+ export type UnlockNowParams = {
182
+ admin: Address;
183
+ feePayer?: Address;
184
+ company: Address;
185
+ usdtMint: Address;
186
+ };
169
187
  export type PayrollFeeInfo = {
170
188
  symbol: string;
171
189
  chain: string;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "@zebec-network/core-utils": "^1.2.0",
12
12
  "@zebec-network/solana-common": "^2.6.0",
13
13
  "@zebec-network/zebec_configs": "^1.1.1",
14
- "@zebec-network/zebec_payroll": "^1.3.2",
14
+ "@zebec-network/zebec_payroll": "^1.4.0",
15
15
  "bignumber.js": "^11.0.0"
16
16
  },
17
17
  "devDependencies": {
@@ -43,5 +43,5 @@
43
43
  },
44
44
  "type": "module",
45
45
  "types": "dist/index.d.ts",
46
- "version": "2.0.0"
47
- }
46
+ "version": "2.1.0"
47
+ }