@zebec-network/solana-payroll-sdk 2.2.0 → 2.3.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/README.md +0 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/instructions.d.ts +40 -20
- package/dist/instructions.js +36 -22
- package/dist/pda.d.ts +3 -3
- package/dist/pda.js +18 -14
- package/dist/services.d.ts +9 -18
- package/dist/services.js +143 -56
- package/dist/types.d.ts +46 -11
- package/package.json +47 -47
package/README.md
CHANGED
|
Binary file
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
package/dist/instructions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BN, Program } from "@coral-xyz/anchor";
|
|
2
|
-
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import type { AccountMeta, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
3
|
import type { ZebecPayroll as ZebecPayrollIdl } from "@zebec-network/zebec_payroll";
|
|
4
4
|
export declare function createCreatePayrollInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
5
5
|
sender: PublicKey;
|
|
@@ -98,35 +98,55 @@ export declare function createTransferFeesInstruction(program: Program<ZebecPayr
|
|
|
98
98
|
decimals: number;
|
|
99
99
|
feeAmount: BN;
|
|
100
100
|
}): Promise<TransactionInstruction>;
|
|
101
|
-
export declare function
|
|
102
|
-
|
|
101
|
+
export declare function createYieldDepositInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
102
|
+
company: PublicKey;
|
|
103
|
+
companyDeposit: PublicKey;
|
|
103
104
|
yieldConfig: PublicKey;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
centralVault: PublicKey;
|
|
106
|
+
centralVaultTokenAta: PublicKey;
|
|
107
|
+
companyNonce: PublicKey;
|
|
108
|
+
companyTokenAta: PublicKey;
|
|
109
|
+
depositMint: PublicKey;
|
|
108
110
|
}, data: {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
amount: BN;
|
|
112
|
+
nonce: BN;
|
|
113
|
+
companyId: number[];
|
|
111
114
|
}): Promise<TransactionInstruction>;
|
|
112
|
-
export declare function
|
|
115
|
+
export declare function createRequestUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
113
116
|
company: PublicKey;
|
|
114
117
|
companyDeposit: PublicKey;
|
|
115
118
|
yieldConfig: PublicKey;
|
|
116
|
-
vault: PublicKey;
|
|
117
|
-
vaultUsdtAta: PublicKey;
|
|
118
|
-
companyUsdtAta: PublicKey;
|
|
119
|
-
usdtMint: PublicKey;
|
|
120
119
|
}, data: {
|
|
121
|
-
|
|
120
|
+
companyId: number[];
|
|
121
|
+
nonce: BN;
|
|
122
|
+
}): Promise<TransactionInstruction>;
|
|
123
|
+
export declare function createCancelUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
124
|
+
company: PublicKey;
|
|
125
|
+
companyDeposit: PublicKey;
|
|
126
|
+
}, data: {
|
|
127
|
+
companyId: number[];
|
|
128
|
+
nonce: BN;
|
|
122
129
|
}): Promise<TransactionInstruction>;
|
|
123
|
-
export declare function
|
|
130
|
+
export declare function createCompleteUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
131
|
+
admin: PublicKey;
|
|
124
132
|
feePayer: PublicKey;
|
|
125
133
|
company: PublicKey;
|
|
126
134
|
companyDeposit: PublicKey;
|
|
127
135
|
yieldConfig: PublicKey;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
centralVaultTokenAta: PublicKey;
|
|
137
|
+
companyTokenAta: PublicKey;
|
|
138
|
+
depositMint: PublicKey;
|
|
139
|
+
}, data: {
|
|
140
|
+
companyId: number[];
|
|
141
|
+
nonce: BN;
|
|
132
142
|
}): Promise<TransactionInstruction>;
|
|
143
|
+
export declare function createDistributeRewardsInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
144
|
+
admin: PublicKey;
|
|
145
|
+
yieldConfig: PublicKey;
|
|
146
|
+
}, data: {
|
|
147
|
+
distributions: {
|
|
148
|
+
companyId: number[];
|
|
149
|
+
nonce: BN;
|
|
150
|
+
amount: BN;
|
|
151
|
+
}[];
|
|
152
|
+
}, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
|
package/dist/instructions.js
CHANGED
|
@@ -131,48 +131,62 @@ export async function createTransferFeesInstruction(program, accounts, data) {
|
|
|
131
131
|
})
|
|
132
132
|
.instruction();
|
|
133
133
|
}
|
|
134
|
-
export async function
|
|
134
|
+
export async function createYieldDepositInstruction(program, accounts, data) {
|
|
135
135
|
return program.methods
|
|
136
|
-
.
|
|
137
|
-
minUnlockAmount: data.minUnlockAmount,
|
|
138
|
-
unlockCooldown: data.unlockCooldown,
|
|
139
|
-
})
|
|
136
|
+
.yieldDeposit(data.nonce, data.companyId, data.amount)
|
|
140
137
|
.accountsPartial({
|
|
141
|
-
|
|
138
|
+
company: accounts.company,
|
|
139
|
+
companyDeposit: accounts.companyDeposit,
|
|
142
140
|
yieldConfig: accounts.yieldConfig,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
centralVault: accounts.centralVault,
|
|
142
|
+
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
143
|
+
companyNonce: accounts.companyNonce,
|
|
144
|
+
companyTokenAta: accounts.companyTokenAta,
|
|
145
|
+
depositMint: accounts.depositMint,
|
|
147
146
|
})
|
|
148
147
|
.instruction();
|
|
149
148
|
}
|
|
150
|
-
export async function
|
|
149
|
+
export async function createRequestUnlockInstruction(program, accounts, data) {
|
|
151
150
|
return program.methods
|
|
152
|
-
.
|
|
151
|
+
.requestUnlock(data.companyId, data.nonce)
|
|
153
152
|
.accountsPartial({
|
|
154
153
|
company: accounts.company,
|
|
155
154
|
companyDeposit: accounts.companyDeposit,
|
|
156
155
|
yieldConfig: accounts.yieldConfig,
|
|
157
|
-
vault: accounts.vault,
|
|
158
|
-
vaultUsdtAta: accounts.vaultUsdtAta,
|
|
159
|
-
companyUsdtAta: accounts.companyUsdtAta,
|
|
160
|
-
usdtMint: accounts.usdtMint,
|
|
161
156
|
})
|
|
162
157
|
.instruction();
|
|
163
158
|
}
|
|
164
|
-
export async function
|
|
159
|
+
export async function createCancelUnlockInstruction(program, accounts, data) {
|
|
165
160
|
return program.methods
|
|
166
|
-
.
|
|
161
|
+
.cancelUnlock(data.companyId, data.nonce)
|
|
167
162
|
.accountsPartial({
|
|
163
|
+
company: accounts.company,
|
|
164
|
+
companyDeposit: accounts.companyDeposit,
|
|
165
|
+
})
|
|
166
|
+
.instruction();
|
|
167
|
+
}
|
|
168
|
+
export async function createCompleteUnlockInstruction(program, accounts, data) {
|
|
169
|
+
return program.methods
|
|
170
|
+
.completeUnlock(data.companyId, data.nonce)
|
|
171
|
+
.accountsPartial({
|
|
172
|
+
admin: accounts.admin,
|
|
168
173
|
feePayer: accounts.feePayer,
|
|
169
174
|
company: accounts.company,
|
|
170
175
|
companyDeposit: accounts.companyDeposit,
|
|
171
176
|
yieldConfig: accounts.yieldConfig,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
178
|
+
companyTokenAta: accounts.companyTokenAta,
|
|
179
|
+
depositMint: accounts.depositMint,
|
|
180
|
+
})
|
|
181
|
+
.instruction();
|
|
182
|
+
}
|
|
183
|
+
export async function createDistributeRewardsInstruction(program, accounts, data, remainingAccounts) {
|
|
184
|
+
return program.methods
|
|
185
|
+
.distributeRewards(data.distributions)
|
|
186
|
+
.accountsPartial({
|
|
187
|
+
admin: accounts.admin,
|
|
188
|
+
yieldConfig: accounts.yieldConfig,
|
|
176
189
|
})
|
|
190
|
+
.remainingAccounts(remainingAccounts)
|
|
177
191
|
.instruction();
|
|
178
192
|
}
|
package/dist/pda.d.ts
CHANGED
|
@@ -2,6 +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(
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
5
|
+
export declare function deriveYieldConfigPda(configProgramId: Address): [PublicKey, number];
|
|
6
|
+
export declare function deriveCompanyDepositPda(companyId: Buffer, nonce: bigint, payrollProgramId: Address): [PublicKey, number];
|
|
7
|
+
export declare function deriveCompanyNoncePda(companyId: Buffer, payrollProgramId: Address): [PublicKey, number];
|
package/dist/pda.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { translateAddress, utils } from "@coral-xyz/anchor";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// } as const;
|
|
6
|
-
const PAYROLL_CONFIG_SEEDS = {
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
const ZEBEC_CONFIG_PROGRAM_SEEDS = {
|
|
7
5
|
PAYROLL_CONFIG: utils.bytes.utf8.encode("payroll_config"),
|
|
8
|
-
};
|
|
9
|
-
const YIELD_SEEDS = {
|
|
10
6
|
YIELD_CONFIG: utils.bytes.utf8.encode("yield_config"),
|
|
11
|
-
|
|
7
|
+
};
|
|
8
|
+
const PAYROLL_PROGRAM_SEEDS = {
|
|
12
9
|
COMPANY_DEPOSIT: utils.bytes.utf8.encode("Yield"),
|
|
13
10
|
};
|
|
14
11
|
export function derivePayrollConfigPda(configName, configProgramId) {
|
|
15
|
-
return PublicKey.findProgramAddressSync([
|
|
12
|
+
return PublicKey.findProgramAddressSync([
|
|
13
|
+
ZEBEC_CONFIG_PROGRAM_SEEDS.PAYROLL_CONFIG,
|
|
14
|
+
utils.bytes.utf8.encode(configName),
|
|
15
|
+
], translateAddress(configProgramId));
|
|
16
16
|
}
|
|
17
17
|
export function derivePayrollVaultPda(metatadata, payrollProgramId) {
|
|
18
18
|
return PublicKey.findProgramAddressSync([translateAddress(metatadata).toBuffer()], translateAddress(payrollProgramId));
|
|
19
19
|
}
|
|
20
|
-
export function deriveYieldConfigPda(
|
|
21
|
-
return PublicKey.findProgramAddressSync([
|
|
20
|
+
export function deriveYieldConfigPda(configProgramId) {
|
|
21
|
+
return PublicKey.findProgramAddressSync([ZEBEC_CONFIG_PROGRAM_SEEDS.YIELD_CONFIG], translateAddress(configProgramId));
|
|
22
22
|
}
|
|
23
|
-
export function
|
|
24
|
-
return PublicKey.findProgramAddressSync([
|
|
23
|
+
export function deriveCompanyDepositPda(companyId, nonce, payrollProgramId) {
|
|
24
|
+
return PublicKey.findProgramAddressSync([
|
|
25
|
+
companyId,
|
|
26
|
+
new BN(nonce).toArrayLike(Buffer, "le", 8),
|
|
27
|
+
PAYROLL_PROGRAM_SEEDS.COMPANY_DEPOSIT,
|
|
28
|
+
], translateAddress(payrollProgramId));
|
|
25
29
|
}
|
|
26
|
-
export function
|
|
27
|
-
return PublicKey.findProgramAddressSync([
|
|
30
|
+
export function deriveCompanyNoncePda(companyId, payrollProgramId) {
|
|
31
|
+
return PublicKey.findProgramAddressSync([companyId], translateAddress(payrollProgramId));
|
|
28
32
|
}
|
package/dist/services.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Address, type Program } from "@coral-xyz/anchor";
|
|
2
|
-
import { type Commitment
|
|
2
|
+
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, ChangePayrollReceiverParams, CreateMultiplePayrollParams, CreatePayrollParams,
|
|
6
|
+
import type { CancelMultiplePayrollParams, CancelPayrollParams, CancelUnlockParams, ChangePayrollReceiverParams, CompanyDepositInfo, CompanyNonceInfo, CompleteUnlockParams, CreateMultiplePayrollParams, CreatePayrollParams, DistributeRewardsParams, PauseResumeMultiplePayrollParams, PauseResumePayrollParams, PayrollConfigInfo, PayrollMetadataInfo, RequestUnlockParams, SetMultipleTopupDelegateParams, SetTopupDelegateParams, TokenMetadata, TopupMultiplePayrollParams, TopupPayrollParams, WithdrawMultiplePayrollParams, 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>;
|
|
@@ -20,19 +20,10 @@ export declare function setTopupDelegate(payrollProgram: Program<ZebecPayrollIdl
|
|
|
20
20
|
export declare function setMultipleTopupDelegate(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: SetMultipleTopupDelegateParams): Promise<MultiTransactionPayload>;
|
|
21
21
|
export declare function topupPayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: TopupPayrollParams): Promise<TransactionPayload>;
|
|
22
22
|
export declare function topupMultiplePayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: TopupMultiplePayrollParams): Promise<MultiTransactionPayload>;
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function yieldDeposit(payrollProgram: Program<ZebecPayrollIdl>, params: YieldDepositParams): Promise<TransactionPayload>;
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
depositTime: import("bn.js");
|
|
31
|
-
hasDeposited: boolean;
|
|
32
|
-
pendingUnlock: {
|
|
33
|
-
usdtAmount: import("bn.js");
|
|
34
|
-
usxAmount: import("bn.js");
|
|
35
|
-
requestTime: import("bn.js");
|
|
36
|
-
} | null;
|
|
37
|
-
bump: number;
|
|
38
|
-
}>;
|
|
23
|
+
export declare function getCompanyNonceInfo(payrollProgram: Program<ZebecPayrollIdl>, companyIdBuffer: Buffer, commitment?: Commitment): Promise<CompanyNonceInfo | null>;
|
|
24
|
+
export declare function yieldDeposit(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: YieldDepositParams, commitment?: Commitment): Promise<TransactionPayload>;
|
|
25
|
+
export declare function requestUnlock(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: RequestUnlockParams): Promise<TransactionPayload>;
|
|
26
|
+
export declare function cancelUnlock(payrollProgram: Program<ZebecPayrollIdl>, params: CancelUnlockParams): Promise<TransactionPayload>;
|
|
27
|
+
export declare function completeUnlock(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: CompleteUnlockParams, commitment?: Commitment): Promise<TransactionPayload>;
|
|
28
|
+
export declare function distributeRewards(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: DistributeRewardsParams): Promise<TransactionPayload>;
|
|
29
|
+
export declare function getCompanyDeposit(payrollProgram: Program<ZebecPayrollIdl>, company: Address): Promise<CompanyDepositInfo | null>;
|
package/dist/services.js
CHANGED
|
@@ -7,9 +7,9 @@ import { bpsToPercent, percentToBps } from "@zebec-network/core-utils";
|
|
|
7
7
|
import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync, getMintDecimals, MultiTransactionPayload, TEN_BIGNUM, TransactionPayload, UNITS_PER_USDC, } from "@zebec-network/solana-common";
|
|
8
8
|
import { BigNumber } from "bignumber.js";
|
|
9
9
|
import { BN } from "bn.js";
|
|
10
|
-
import { PAYROLL_NAME_BUFFER_SIZE } from "./constants.js";
|
|
11
|
-
import { createCancelPayrollInstruction, createChangeRecipientInstruction, createCreatePayrollInstruction,
|
|
12
|
-
import { deriveCompanyDepositPda, derivePayrollConfigPda, derivePayrollVaultPda, deriveYieldConfigPda,
|
|
10
|
+
import { PAYROLL_NAME_BUFFER_SIZE, USX_DECIMALS } from "./constants.js";
|
|
11
|
+
import { createCancelPayrollInstruction, createCancelUnlockInstruction, createChangeRecipientInstruction, createCompleteUnlockInstruction, createCreatePayrollInstruction, createDistributeRewardsInstruction, createPauseResumePayrollInstruction, createRequestUnlockInstruction, createSetTopupDelegateInstruction, createTopupPayrollInstruction, createTransferFeesInstruction, createWithdrawPayrollInstruction, createYieldDepositInstruction, } from "./instructions.js";
|
|
12
|
+
import { deriveCompanyDepositPda, deriveCompanyNoncePda, derivePayrollConfigPda, derivePayrollVaultPda, deriveYieldConfigPda, } 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);
|
|
@@ -690,75 +690,162 @@ export async function topupMultiplePayroll(payrollProgram, configProgram, params
|
|
|
690
690
|
}));
|
|
691
691
|
return createMultiTransactionPayload(payrollProgram, caller, transactionData);
|
|
692
692
|
}
|
|
693
|
-
export async function
|
|
694
|
-
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
693
|
+
export async function getCompanyNonceInfo(payrollProgram, companyIdBuffer, commitment) {
|
|
694
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
695
|
+
const [companyNonce] = deriveCompanyNoncePda(companyIdBuffer, payrollProgram.programId);
|
|
696
|
+
const data = await payrollProgram.account.companyNonce.fetchNullable(companyNonce, commitment);
|
|
697
|
+
if (!data) {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
return {
|
|
701
|
+
companyId: Buffer.from(data.companyId),
|
|
702
|
+
nonce: BigInt(data.nonce.toString()),
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
export async function yieldDeposit(payrollProgram, configsProgram, params, commitment) {
|
|
706
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
707
|
+
const company = translateAddress(params.company);
|
|
708
|
+
const depositMint = translateAddress(params.depoistMint);
|
|
709
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
710
|
+
const configData = await configsProgram.account.yieldConfig.fetchNullable(yieldConfig, commitment);
|
|
711
|
+
if (!configData) {
|
|
712
|
+
throw new Error("Yield config is not initialized in Zebec Configs Program");
|
|
713
|
+
}
|
|
714
|
+
const centralVault = configData.centralVault;
|
|
715
|
+
const [companyNonce] = deriveCompanyNoncePda(Buffer.from(params.companyId), payrollProgram.programId);
|
|
716
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
717
|
+
const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint, centralVault, true);
|
|
718
|
+
const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
|
|
719
|
+
const tokenDecimals = await getMintDecimals(payrollProgram.provider.connection, depositMint);
|
|
720
|
+
const amount = new BN(BigNumber(params.amount).times(TEN_BIGNUM.pow(tokenDecimals)).toFixed(0));
|
|
721
|
+
const ix = await createYieldDepositInstruction(payrollProgram, {
|
|
722
|
+
company,
|
|
723
|
+
companyDeposit,
|
|
706
724
|
yieldConfig,
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
725
|
+
centralVault,
|
|
726
|
+
centralVaultTokenAta,
|
|
727
|
+
companyNonce,
|
|
728
|
+
companyTokenAta,
|
|
729
|
+
depositMint,
|
|
711
730
|
}, {
|
|
712
|
-
|
|
713
|
-
|
|
731
|
+
amount,
|
|
732
|
+
companyId: Array.from(params.companyId),
|
|
733
|
+
nonce: new BN(params.nonce),
|
|
714
734
|
});
|
|
715
|
-
return createTransactionPayload(payrollProgram,
|
|
735
|
+
return createTransactionPayload(payrollProgram, company, [ix]);
|
|
716
736
|
}
|
|
717
|
-
export async function
|
|
737
|
+
export async function requestUnlock(payrollProgram, configsProgram, params) {
|
|
718
738
|
const company = translateAddress(params.company);
|
|
719
|
-
const
|
|
720
|
-
const [
|
|
721
|
-
const [
|
|
722
|
-
const
|
|
723
|
-
const vaultUsdtAta = getAssociatedTokenAddressSync(usdtMint, vault, true);
|
|
724
|
-
const companyUsdtAta = getAssociatedTokenAddressSync(usdtMint, company, true);
|
|
725
|
-
const usdtDecimals = await getMintDecimals(payrollProgram.provider.connection, usdtMint);
|
|
726
|
-
const amount = new BN(BigNumber(params.amount).times(TEN_BIGNUM.pow(usdtDecimals)).toFixed(0));
|
|
727
|
-
const ix = await createYieldDepositInstruction(payrollProgram, {
|
|
739
|
+
const feePayer = translateAddress(params.feePayer);
|
|
740
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
741
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
742
|
+
const ix = await createRequestUnlockInstruction(payrollProgram, {
|
|
728
743
|
company,
|
|
729
744
|
companyDeposit,
|
|
730
745
|
yieldConfig,
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
return createTransactionPayload(payrollProgram, company, [ix]);
|
|
746
|
+
}, {
|
|
747
|
+
companyId: Array.from(params.companyId),
|
|
748
|
+
nonce: new BN(params.nonce.toString()),
|
|
749
|
+
});
|
|
750
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
737
751
|
}
|
|
738
|
-
export async function
|
|
752
|
+
export async function cancelUnlock(payrollProgram, params) {
|
|
739
753
|
const company = translateAddress(params.company);
|
|
740
|
-
const
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
754
|
+
const feePayer = translateAddress(params.feePayer);
|
|
755
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
756
|
+
const ix = await createCancelUnlockInstruction(payrollProgram, {
|
|
757
|
+
company,
|
|
758
|
+
companyDeposit,
|
|
759
|
+
}, {
|
|
760
|
+
companyId: Array.from(params.companyId),
|
|
761
|
+
nonce: new BN(params.nonce.toString()),
|
|
762
|
+
});
|
|
763
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
764
|
+
}
|
|
765
|
+
export async function completeUnlock(payrollProgram, configsProgram, params, commitment) {
|
|
766
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
767
|
+
const company = translateAddress(params.company);
|
|
768
|
+
const feePayer = translateAddress(params.feePayer);
|
|
769
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
770
|
+
const configData = await configsProgram.account.yieldConfig.fetchNullable(yieldConfig, commitment);
|
|
771
|
+
if (!configData) {
|
|
772
|
+
throw new Error("YieldConfigNotFound: Yield config is not initialized in Zebec Configs Program");
|
|
773
|
+
}
|
|
774
|
+
// central vault is also the admin
|
|
775
|
+
const admin = configData.centralVault;
|
|
776
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
777
|
+
const companyDepositData = await payrollProgram.account.companyDeposit.fetchNullable(companyDeposit, commitment);
|
|
778
|
+
if (!companyDepositData) {
|
|
779
|
+
throw new Error(`CompanyDepositNotFound: Company Deposit does not exists for nonce: ${params.nonce.toString()}n and companyId: [${Array.from(params.companyId).toString()}]`);
|
|
780
|
+
}
|
|
781
|
+
const depositMint = companyDepositData.depositMint;
|
|
782
|
+
const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint, admin, true);
|
|
783
|
+
const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
|
|
784
|
+
const ix = await createCompleteUnlockInstruction(payrollProgram, {
|
|
785
|
+
admin,
|
|
750
786
|
feePayer,
|
|
751
787
|
company,
|
|
752
788
|
companyDeposit,
|
|
753
789
|
yieldConfig,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
790
|
+
centralVaultTokenAta,
|
|
791
|
+
companyTokenAta,
|
|
792
|
+
depositMint,
|
|
793
|
+
}, {
|
|
794
|
+
companyId: Array.from(params.companyId),
|
|
795
|
+
nonce: new BN(params.nonce.toString()),
|
|
758
796
|
});
|
|
759
797
|
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
760
798
|
}
|
|
799
|
+
export async function distributeRewards(payrollProgram, configsProgram, params) {
|
|
800
|
+
const admin = translateAddress(params.admin);
|
|
801
|
+
const feePayer = translateAddress(params.feePayer);
|
|
802
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
803
|
+
const distributions = params.distributions.map((d) => ({
|
|
804
|
+
companyId: Array.from(d.companyId),
|
|
805
|
+
nonce: new BN(d.nonce.toString()),
|
|
806
|
+
amount: new BN(BigNumber(d.amount)
|
|
807
|
+
.times(BigNumber(10).pow(USX_DECIMALS))
|
|
808
|
+
.toFixed(0, BigNumber.ROUND_FLOOR)),
|
|
809
|
+
}));
|
|
810
|
+
const remainingAccounts = params.distributions.map((d) => ({
|
|
811
|
+
pubkey: deriveCompanyDepositPda(Buffer.from(d.companyId), d.nonce, payrollProgram.programId)[0],
|
|
812
|
+
isSigner: false,
|
|
813
|
+
isWritable: true,
|
|
814
|
+
}));
|
|
815
|
+
const ix = await createDistributeRewardsInstruction(payrollProgram, {
|
|
816
|
+
admin,
|
|
817
|
+
yieldConfig,
|
|
818
|
+
}, { distributions }, remainingAccounts);
|
|
819
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
820
|
+
}
|
|
761
821
|
export async function getCompanyDeposit(payrollProgram, company) {
|
|
762
|
-
const
|
|
763
|
-
|
|
822
|
+
const data = await payrollProgram.account.companyDeposit.fetch(translateAddress(company));
|
|
823
|
+
if (!data) {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
const tokenDecimals = await getMintDecimals(payrollProgram.provider.connection, data.depositMint);
|
|
827
|
+
return {
|
|
828
|
+
company: data.company,
|
|
829
|
+
companyId: Buffer.from(data.companyId),
|
|
830
|
+
nonce: BigInt(data.nonce.toString()),
|
|
831
|
+
depositMint: data.depositMint,
|
|
832
|
+
depositedAmount: BigNumber(data.depositedAmount.toString())
|
|
833
|
+
.div(BigNumber(10).pow(tokenDecimals))
|
|
834
|
+
.toFixed(),
|
|
835
|
+
rewardsReceived: BigNumber(data.rewardsReceived.toString())
|
|
836
|
+
.div(BigNumber(10).pow(USX_DECIMALS))
|
|
837
|
+
.toFixed(),
|
|
838
|
+
depositTime: data.depositTime.toNumber(),
|
|
839
|
+
pendingUnlock: data.pendingUnlock
|
|
840
|
+
? {
|
|
841
|
+
tokenAmount: BigNumber(data.pendingUnlock.tokenAmount.toString())
|
|
842
|
+
.div(BigNumber(10).pow(tokenDecimals))
|
|
843
|
+
.toFixed(),
|
|
844
|
+
usxAmount: BigNumber(data.pendingUnlock.tokenAmount.toString())
|
|
845
|
+
.div(BigNumber(10).pow(USX_DECIMALS))
|
|
846
|
+
.toFixed(),
|
|
847
|
+
requestTime: data.pendingUnlock.requestTime.toNumber(),
|
|
848
|
+
}
|
|
849
|
+
: null,
|
|
850
|
+
};
|
|
764
851
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -198,22 +198,39 @@ export type SetMultipleTopupDelegateParams = {
|
|
|
198
198
|
amount: Numeric;
|
|
199
199
|
}[];
|
|
200
200
|
};
|
|
201
|
-
export type InitYieldConfigParams = {
|
|
202
|
-
admin: Address;
|
|
203
|
-
usdtMint: Address;
|
|
204
|
-
usxMint: Address;
|
|
205
|
-
minUnlockAmount: Numeric;
|
|
206
|
-
unlockCooldown: number;
|
|
207
|
-
};
|
|
208
201
|
export type YieldDepositParams = {
|
|
202
|
+
companyId: Buffer | Uint8Array;
|
|
209
203
|
company: Address;
|
|
210
|
-
|
|
204
|
+
nonce: bigint;
|
|
205
|
+
depoistMint: Address;
|
|
211
206
|
amount: Numeric;
|
|
212
207
|
};
|
|
213
|
-
export type
|
|
214
|
-
feePayer
|
|
208
|
+
export type RequestUnlockParams = {
|
|
209
|
+
feePayer: Address;
|
|
210
|
+
company: Address;
|
|
211
|
+
companyId: Buffer | Uint8Array;
|
|
212
|
+
nonce: bigint;
|
|
213
|
+
};
|
|
214
|
+
export type CancelUnlockParams = {
|
|
215
|
+
feePayer: Address;
|
|
216
|
+
company: Address;
|
|
217
|
+
companyId: Buffer | Uint8Array;
|
|
218
|
+
nonce: bigint;
|
|
219
|
+
};
|
|
220
|
+
export type CompleteUnlockParams = {
|
|
221
|
+
feePayer: Address;
|
|
215
222
|
company: Address;
|
|
216
|
-
|
|
223
|
+
companyId: Buffer | Uint8Array;
|
|
224
|
+
nonce: bigint;
|
|
225
|
+
};
|
|
226
|
+
export type DistributeRewardsParams = {
|
|
227
|
+
admin: Address;
|
|
228
|
+
feePayer: Address;
|
|
229
|
+
distributions: {
|
|
230
|
+
companyId: Buffer | Uint8Array;
|
|
231
|
+
nonce: bigint;
|
|
232
|
+
amount: Numeric;
|
|
233
|
+
}[];
|
|
217
234
|
};
|
|
218
235
|
export type PayrollFeeInfo = {
|
|
219
236
|
symbol: string;
|
|
@@ -237,3 +254,21 @@ export type PayrollFeeInfo = {
|
|
|
237
254
|
feeAmount: number;
|
|
238
255
|
feeAmountRaw: string;
|
|
239
256
|
};
|
|
257
|
+
export type CompanyNonceInfo = {
|
|
258
|
+
companyId: Buffer;
|
|
259
|
+
nonce: bigint;
|
|
260
|
+
};
|
|
261
|
+
export type CompanyDepositInfo = {
|
|
262
|
+
company: Address;
|
|
263
|
+
companyId: Buffer;
|
|
264
|
+
nonce: bigint;
|
|
265
|
+
depositMint: Address;
|
|
266
|
+
depositedAmount: Numeric;
|
|
267
|
+
rewardsReceived: Numeric;
|
|
268
|
+
depositTime: number;
|
|
269
|
+
pendingUnlock: {
|
|
270
|
+
tokenAmount: Numeric;
|
|
271
|
+
usxAmount: Numeric;
|
|
272
|
+
requestTime: number;
|
|
273
|
+
} | null;
|
|
274
|
+
};
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "Zebec Network",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@coral-xyz/anchor": "^0.31.1",
|
|
5
|
-
"@metaplex-foundation/mpl-token-metadata": "^3.4.0",
|
|
6
|
-
"@metaplex-foundation/umi": "^1.5.1",
|
|
7
|
-
"@metaplex-foundation/umi-bundle-defaults": "^1.5.1",
|
|
8
|
-
"@metaplex-foundation/umi-web3js-adapters": "^1.5.1",
|
|
9
|
-
"@solana/spl-token": "^0.4.14",
|
|
10
|
-
"@solana/web3.js": "^1.98.2",
|
|
11
|
-
"@zebec-network/core-utils": "^1.
|
|
12
|
-
"@zebec-network/solana-common": "^2.6.0",
|
|
13
|
-
"@zebec-network/zebec_configs": "^1.
|
|
14
|
-
"@zebec-network/zebec_payroll": "^1.4.
|
|
15
|
-
"bignumber.js": "^11.
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@types/bn.js": "^5.2.0",
|
|
19
|
-
"@types/mocha": "^10.0.10",
|
|
20
|
-
"@types/node": "^25.6.0",
|
|
21
|
-
"dotenv": "^17.4.2",
|
|
22
|
-
"mocha": "^11.7.5",
|
|
23
|
-
"rimraf": "^6.1.3",
|
|
24
|
-
"ts-mocha": "^11.1.0",
|
|
25
|
-
"ts-node": "^10.9.2",
|
|
26
|
-
"typescript": "^6.0.3"
|
|
27
|
-
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"main": "dist/index.js",
|
|
33
|
-
"name": "@zebec-network/solana-payroll-sdk",
|
|
34
|
-
"private": false,
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "npm run clean && tsc",
|
|
37
|
-
"clean": "rimraf ./dist",
|
|
38
|
-
"format": "npx @biomejs/biome format --write",
|
|
39
|
-
"prepare": "npm run build",
|
|
40
|
-
"run:example": "node --loader ts-node/esm -- example/buildTransactionAndSendForSigning.ts",
|
|
41
|
-
"test": "ts-mocha -p ./tsconfig.json -t 1000000000 test/**/*.test.ts",
|
|
42
|
-
"test:single": "ts-mocha -p ./tsconfig.json -t 1000000000 --"
|
|
43
|
-
},
|
|
44
|
-
"type": "module",
|
|
45
|
-
"types": "dist/index.d.ts",
|
|
46
|
-
"version": "2.
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "Zebec Network",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@coral-xyz/anchor": "^0.31.1",
|
|
5
|
+
"@metaplex-foundation/mpl-token-metadata": "^3.4.0",
|
|
6
|
+
"@metaplex-foundation/umi": "^1.5.1",
|
|
7
|
+
"@metaplex-foundation/umi-bundle-defaults": "^1.5.1",
|
|
8
|
+
"@metaplex-foundation/umi-web3js-adapters": "^1.5.1",
|
|
9
|
+
"@solana/spl-token": "^0.4.14",
|
|
10
|
+
"@solana/web3.js": "^1.98.2",
|
|
11
|
+
"@zebec-network/core-utils": "^1.3.0",
|
|
12
|
+
"@zebec-network/solana-common": "^2.6.0",
|
|
13
|
+
"@zebec-network/zebec_configs": "^1.2.2",
|
|
14
|
+
"@zebec-network/zebec_payroll": "^1.4.5",
|
|
15
|
+
"bignumber.js": "^11.1.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bn.js": "^5.2.0",
|
|
19
|
+
"@types/mocha": "^10.0.10",
|
|
20
|
+
"@types/node": "^25.6.0",
|
|
21
|
+
"dotenv": "^17.4.2",
|
|
22
|
+
"mocha": "^11.7.5",
|
|
23
|
+
"rimraf": "^6.1.3",
|
|
24
|
+
"ts-mocha": "^11.1.0",
|
|
25
|
+
"ts-node": "^10.9.2",
|
|
26
|
+
"typescript": "^6.0.3"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"main": "dist/index.js",
|
|
33
|
+
"name": "@zebec-network/solana-payroll-sdk",
|
|
34
|
+
"private": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "npm run clean && tsc",
|
|
37
|
+
"clean": "rimraf ./dist",
|
|
38
|
+
"format": "npx @biomejs/biome format --write",
|
|
39
|
+
"prepare": "npm run build",
|
|
40
|
+
"run:example": "node --loader ts-node/esm -- example/buildTransactionAndSendForSigning.ts",
|
|
41
|
+
"test": "ts-mocha -p ./tsconfig.json -t 1000000000 test/**/*.test.ts",
|
|
42
|
+
"test:single": "ts-mocha -p ./tsconfig.json -t 1000000000 --"
|
|
43
|
+
},
|
|
44
|
+
"type": "module",
|
|
45
|
+
"types": "dist/index.d.ts",
|
|
46
|
+
"version": "2.3.1"
|
|
47
|
+
}
|