@zebec-network/solana-payroll-sdk 2.2.0 → 2.3.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/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/instructions.d.ts +53 -20
- package/dist/instructions.js +50 -21
- package/dist/pda.d.ts +3 -3
- package/dist/pda.js +18 -14
- package/dist/services.d.ts +10 -18
- package/dist/services.js +177 -56
- package/dist/types.d.ts +51 -10
- package/package.json +4 -4
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,68 @@ 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
101
|
export declare function createYieldDepositInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
113
102
|
company: PublicKey;
|
|
114
103
|
companyDeposit: PublicKey;
|
|
115
104
|
yieldConfig: PublicKey;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
105
|
+
centralVault: PublicKey;
|
|
106
|
+
centralVaultTokenAta: PublicKey;
|
|
107
|
+
companyNonce: PublicKey;
|
|
108
|
+
companyTokenAta: PublicKey;
|
|
109
|
+
depositMint: PublicKey;
|
|
120
110
|
}, data: {
|
|
121
111
|
amount: BN;
|
|
112
|
+
nonce: BN;
|
|
113
|
+
companyId: number[];
|
|
122
114
|
}): Promise<TransactionInstruction>;
|
|
123
115
|
export declare function createUnlockNowInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
124
116
|
feePayer: PublicKey;
|
|
125
117
|
company: PublicKey;
|
|
126
118
|
companyDeposit: PublicKey;
|
|
127
119
|
yieldConfig: PublicKey;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
admin: PublicKey;
|
|
121
|
+
centralVaultTokenAta: PublicKey;
|
|
122
|
+
companyTokenAta: PublicKey;
|
|
123
|
+
depositMint: PublicKey;
|
|
124
|
+
}, data: {
|
|
125
|
+
nonce: BN;
|
|
126
|
+
companyId: number[];
|
|
132
127
|
}): Promise<TransactionInstruction>;
|
|
128
|
+
export declare function createRequestUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
129
|
+
company: PublicKey;
|
|
130
|
+
companyDeposit: PublicKey;
|
|
131
|
+
yieldConfig: PublicKey;
|
|
132
|
+
}, data: {
|
|
133
|
+
companyId: number[];
|
|
134
|
+
nonce: BN;
|
|
135
|
+
}): Promise<TransactionInstruction>;
|
|
136
|
+
export declare function createCancelUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
137
|
+
company: PublicKey;
|
|
138
|
+
companyDeposit: PublicKey;
|
|
139
|
+
}, data: {
|
|
140
|
+
companyId: number[];
|
|
141
|
+
nonce: BN;
|
|
142
|
+
}): Promise<TransactionInstruction>;
|
|
143
|
+
export declare function createCompleteUnlockInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
144
|
+
admin: PublicKey;
|
|
145
|
+
feePayer: PublicKey;
|
|
146
|
+
company: PublicKey;
|
|
147
|
+
companyDeposit: PublicKey;
|
|
148
|
+
yieldConfig: PublicKey;
|
|
149
|
+
centralVaultTokenAta: PublicKey;
|
|
150
|
+
companyTokenAta: PublicKey;
|
|
151
|
+
depositMint: PublicKey;
|
|
152
|
+
}, data: {
|
|
153
|
+
companyId: number[];
|
|
154
|
+
nonce: BN;
|
|
155
|
+
}): Promise<TransactionInstruction>;
|
|
156
|
+
export declare function createDistributeRewardsInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
157
|
+
admin: PublicKey;
|
|
158
|
+
yieldConfig: PublicKey;
|
|
159
|
+
}, data: {
|
|
160
|
+
distributions: {
|
|
161
|
+
companyId: number[];
|
|
162
|
+
nonce: BN;
|
|
163
|
+
amount: BN;
|
|
164
|
+
}[];
|
|
165
|
+
}, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
|
package/dist/instructions.js
CHANGED
|
@@ -131,48 +131,77 @@ 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
|
-
|
|
138
|
-
|
|
136
|
+
.yieldDeposit(data.nonce, data.companyId, data.amount)
|
|
137
|
+
.accountsPartial({
|
|
138
|
+
company: accounts.company,
|
|
139
|
+
companyDeposit: accounts.companyDeposit,
|
|
140
|
+
yieldConfig: accounts.yieldConfig,
|
|
141
|
+
centralVault: accounts.centralVault,
|
|
142
|
+
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
143
|
+
companyNonce: accounts.companyNonce,
|
|
144
|
+
companyTokenAta: accounts.companyTokenAta,
|
|
145
|
+
depositMint: accounts.depositMint,
|
|
139
146
|
})
|
|
147
|
+
.instruction();
|
|
148
|
+
}
|
|
149
|
+
export async function createUnlockNowInstruction(program, accounts, data) {
|
|
150
|
+
return program.methods
|
|
151
|
+
.unlockNow(data.companyId, data.nonce)
|
|
140
152
|
.accountsPartial({
|
|
141
|
-
|
|
153
|
+
feePayer: accounts.feePayer,
|
|
154
|
+
company: accounts.company,
|
|
155
|
+
companyDeposit: accounts.companyDeposit,
|
|
142
156
|
yieldConfig: accounts.yieldConfig,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
admin: accounts.admin,
|
|
158
|
+
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
159
|
+
companyTokenAta: accounts.companyTokenAta,
|
|
160
|
+
depositMint: accounts.depositMint,
|
|
147
161
|
})
|
|
148
162
|
.instruction();
|
|
149
163
|
}
|
|
150
|
-
export async function
|
|
164
|
+
export async function createRequestUnlockInstruction(program, accounts, data) {
|
|
151
165
|
return program.methods
|
|
152
|
-
.
|
|
166
|
+
.requestUnlock(data.companyId, data.nonce)
|
|
153
167
|
.accountsPartial({
|
|
154
168
|
company: accounts.company,
|
|
155
169
|
companyDeposit: accounts.companyDeposit,
|
|
156
170
|
yieldConfig: accounts.yieldConfig,
|
|
157
|
-
vault: accounts.vault,
|
|
158
|
-
vaultUsdtAta: accounts.vaultUsdtAta,
|
|
159
|
-
companyUsdtAta: accounts.companyUsdtAta,
|
|
160
|
-
usdtMint: accounts.usdtMint,
|
|
161
171
|
})
|
|
162
172
|
.instruction();
|
|
163
173
|
}
|
|
164
|
-
export async function
|
|
174
|
+
export async function createCancelUnlockInstruction(program, accounts, data) {
|
|
165
175
|
return program.methods
|
|
166
|
-
.
|
|
176
|
+
.cancelUnlock(data.companyId, data.nonce)
|
|
167
177
|
.accountsPartial({
|
|
178
|
+
company: accounts.company,
|
|
179
|
+
companyDeposit: accounts.companyDeposit,
|
|
180
|
+
})
|
|
181
|
+
.instruction();
|
|
182
|
+
}
|
|
183
|
+
export async function createCompleteUnlockInstruction(program, accounts, data) {
|
|
184
|
+
return program.methods
|
|
185
|
+
.completeUnlock(data.companyId, data.nonce)
|
|
186
|
+
.accountsPartial({
|
|
187
|
+
admin: accounts.admin,
|
|
168
188
|
feePayer: accounts.feePayer,
|
|
169
189
|
company: accounts.company,
|
|
170
190
|
companyDeposit: accounts.companyDeposit,
|
|
171
191
|
yieldConfig: accounts.yieldConfig,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
192
|
+
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
193
|
+
companyTokenAta: accounts.companyTokenAta,
|
|
194
|
+
depositMint: accounts.depositMint,
|
|
195
|
+
})
|
|
196
|
+
.instruction();
|
|
197
|
+
}
|
|
198
|
+
export async function createDistributeRewardsInstruction(program, accounts, data, remainingAccounts) {
|
|
199
|
+
return program.methods
|
|
200
|
+
.distributeRewards(data.distributions)
|
|
201
|
+
.accountsPartial({
|
|
202
|
+
admin: accounts.admin,
|
|
203
|
+
yieldConfig: accounts.yieldConfig,
|
|
176
204
|
})
|
|
205
|
+
.remainingAccounts(remainingAccounts)
|
|
177
206
|
.instruction();
|
|
178
207
|
}
|
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, UnlockNowParams, 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,11 @@ 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 unlockNow(payrollProgram: Program<ZebecPayrollIdl>, params: UnlockNowParams): Promise<TransactionPayload>;
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 unlockNow(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: UnlockNowParams, commitment?: Commitment): Promise<TransactionPayload>;
|
|
26
|
+
export declare function requestUnlock(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: RequestUnlockParams): Promise<TransactionPayload>;
|
|
27
|
+
export declare function cancelUnlock(payrollProgram: Program<ZebecPayrollIdl>, params: CancelUnlockParams): Promise<TransactionPayload>;
|
|
28
|
+
export declare function completeUnlock(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: CompleteUnlockParams, commitment?: Commitment): Promise<TransactionPayload>;
|
|
29
|
+
export declare function distributeRewards(payrollProgram: Program<ZebecPayrollIdl>, configsProgram: Program<ZebecConfigsIdl>, params: DistributeRewardsParams): Promise<TransactionPayload>;
|
|
30
|
+
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, createUnlockNowInstruction, 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,196 @@ 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
|
-
const ix = await createInitYieldConfigInstruction(payrollProgram, {
|
|
705
|
-
admin,
|
|
706
|
-
yieldConfig,
|
|
707
|
-
vault,
|
|
708
|
-
vaultUsdtAta,
|
|
709
|
-
usdtMint,
|
|
710
|
-
usxMint,
|
|
711
|
-
}, {
|
|
712
|
-
minUnlockAmount,
|
|
713
|
-
unlockCooldown: new BN(params.unlockCooldown),
|
|
714
|
-
});
|
|
715
|
-
return createTransactionPayload(payrollProgram, admin, [ix]);
|
|
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
|
+
};
|
|
716
704
|
}
|
|
717
|
-
export async function yieldDeposit(payrollProgram, params) {
|
|
705
|
+
export async function yieldDeposit(payrollProgram, configsProgram, params, commitment) {
|
|
706
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
718
707
|
const company = translateAddress(params.company);
|
|
719
|
-
const
|
|
720
|
-
const [
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const
|
|
726
|
-
const
|
|
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));
|
|
727
721
|
const ix = await createYieldDepositInstruction(payrollProgram, {
|
|
728
722
|
company,
|
|
729
723
|
companyDeposit,
|
|
730
724
|
yieldConfig,
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
725
|
+
centralVault,
|
|
726
|
+
centralVaultTokenAta,
|
|
727
|
+
companyNonce,
|
|
728
|
+
companyTokenAta,
|
|
729
|
+
depositMint,
|
|
730
|
+
}, {
|
|
731
|
+
amount,
|
|
732
|
+
companyId: Array.from(params.companyId),
|
|
733
|
+
nonce: new BN(params.nonce),
|
|
734
|
+
});
|
|
736
735
|
return createTransactionPayload(payrollProgram, company, [ix]);
|
|
737
736
|
}
|
|
738
|
-
export async function unlockNow(payrollProgram, params) {
|
|
737
|
+
export async function unlockNow(payrollProgram, configsProgram, params, commitment) {
|
|
738
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
739
739
|
const company = translateAddress(params.company);
|
|
740
|
-
const
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const
|
|
748
|
-
const
|
|
740
|
+
const feePayer = translateAddress(params.feePayer);
|
|
741
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
742
|
+
const configData = await configsProgram.account.yieldConfig.fetchNullable(yieldConfig, commitment);
|
|
743
|
+
if (!configData) {
|
|
744
|
+
throw new Error("YieldConfigNotFound: Yield config is not initialized in Zebec Configs Program");
|
|
745
|
+
}
|
|
746
|
+
// central vault is also the admin
|
|
747
|
+
const admin = configData.centralVault;
|
|
748
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
749
|
+
const companyDepositData = await payrollProgram.account.companyDeposit.fetchNullable(companyDeposit, commitment);
|
|
750
|
+
if (!companyDepositData) {
|
|
751
|
+
throw new Error(`CompanyDepositNotFound: Company Deposit does not exists for nonce: ${params.nonce.toString()}n and companyId: [${Array.from(params.companyId).toString()}]`);
|
|
752
|
+
}
|
|
753
|
+
const depositMint = companyDepositData.depositMint;
|
|
754
|
+
const adminTokenAta = getAssociatedTokenAddressSync(depositMint, admin, true);
|
|
755
|
+
const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
|
|
749
756
|
const ix = await createUnlockNowInstruction(payrollProgram, {
|
|
750
757
|
feePayer,
|
|
751
758
|
company,
|
|
752
759
|
companyDeposit,
|
|
753
760
|
yieldConfig,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
761
|
+
admin,
|
|
762
|
+
centralVaultTokenAta: adminTokenAta,
|
|
763
|
+
companyTokenAta,
|
|
764
|
+
depositMint,
|
|
765
|
+
}, {
|
|
766
|
+
companyId: Array.from(params.companyId),
|
|
767
|
+
nonce: new BN(params.nonce),
|
|
758
768
|
});
|
|
759
769
|
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
760
770
|
}
|
|
771
|
+
export async function requestUnlock(payrollProgram, configsProgram, params) {
|
|
772
|
+
const company = translateAddress(params.company);
|
|
773
|
+
const feePayer = translateAddress(params.feePayer);
|
|
774
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
775
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
776
|
+
const ix = await createRequestUnlockInstruction(payrollProgram, {
|
|
777
|
+
company,
|
|
778
|
+
companyDeposit,
|
|
779
|
+
yieldConfig,
|
|
780
|
+
}, {
|
|
781
|
+
companyId: Array.from(params.companyId),
|
|
782
|
+
nonce: new BN(params.nonce.toString()),
|
|
783
|
+
});
|
|
784
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
785
|
+
}
|
|
786
|
+
export async function cancelUnlock(payrollProgram, params) {
|
|
787
|
+
const company = translateAddress(params.company);
|
|
788
|
+
const feePayer = translateAddress(params.feePayer);
|
|
789
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
790
|
+
const ix = await createCancelUnlockInstruction(payrollProgram, {
|
|
791
|
+
company,
|
|
792
|
+
companyDeposit,
|
|
793
|
+
}, {
|
|
794
|
+
companyId: Array.from(params.companyId),
|
|
795
|
+
nonce: new BN(params.nonce.toString()),
|
|
796
|
+
});
|
|
797
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
798
|
+
}
|
|
799
|
+
export async function completeUnlock(payrollProgram, configsProgram, params, commitment) {
|
|
800
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
801
|
+
const company = translateAddress(params.company);
|
|
802
|
+
const feePayer = translateAddress(params.feePayer);
|
|
803
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
804
|
+
const configData = await configsProgram.account.yieldConfig.fetchNullable(yieldConfig, commitment);
|
|
805
|
+
if (!configData) {
|
|
806
|
+
throw new Error("YieldConfigNotFound: Yield config is not initialized in Zebec Configs Program");
|
|
807
|
+
}
|
|
808
|
+
// central vault is also the admin
|
|
809
|
+
const admin = configData.centralVault;
|
|
810
|
+
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
811
|
+
const companyDepositData = await payrollProgram.account.companyDeposit.fetchNullable(companyDeposit, commitment);
|
|
812
|
+
if (!companyDepositData) {
|
|
813
|
+
throw new Error(`CompanyDepositNotFound: Company Deposit does not exists for nonce: ${params.nonce.toString()}n and companyId: [${Array.from(params.companyId).toString()}]`);
|
|
814
|
+
}
|
|
815
|
+
const depositMint = companyDepositData.depositMint;
|
|
816
|
+
const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint, admin, true);
|
|
817
|
+
const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
|
|
818
|
+
const ix = await createCompleteUnlockInstruction(payrollProgram, {
|
|
819
|
+
admin,
|
|
820
|
+
feePayer,
|
|
821
|
+
company,
|
|
822
|
+
companyDeposit,
|
|
823
|
+
yieldConfig,
|
|
824
|
+
centralVaultTokenAta,
|
|
825
|
+
companyTokenAta,
|
|
826
|
+
depositMint,
|
|
827
|
+
}, {
|
|
828
|
+
companyId: Array.from(params.companyId),
|
|
829
|
+
nonce: new BN(params.nonce.toString()),
|
|
830
|
+
});
|
|
831
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
832
|
+
}
|
|
833
|
+
export async function distributeRewards(payrollProgram, configsProgram, params) {
|
|
834
|
+
const admin = translateAddress(params.admin);
|
|
835
|
+
const feePayer = translateAddress(params.feePayer);
|
|
836
|
+
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
837
|
+
const distributions = params.distributions.map((d) => ({
|
|
838
|
+
companyId: Array.from(d.companyId),
|
|
839
|
+
nonce: new BN(d.nonce.toString()),
|
|
840
|
+
amount: new BN(BigNumber(d.amount)
|
|
841
|
+
.times(BigNumber(10).pow(USX_DECIMALS))
|
|
842
|
+
.toFixed(0, BigNumber.ROUND_FLOOR)),
|
|
843
|
+
}));
|
|
844
|
+
const remainingAccounts = params.distributions.map((d) => ({
|
|
845
|
+
pubkey: deriveCompanyDepositPda(Buffer.from(d.companyId), d.nonce, payrollProgram.programId)[0],
|
|
846
|
+
isSigner: false,
|
|
847
|
+
isWritable: true,
|
|
848
|
+
}));
|
|
849
|
+
const ix = await createDistributeRewardsInstruction(payrollProgram, {
|
|
850
|
+
admin,
|
|
851
|
+
yieldConfig,
|
|
852
|
+
}, { distributions }, remainingAccounts);
|
|
853
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
854
|
+
}
|
|
761
855
|
export async function getCompanyDeposit(payrollProgram, company) {
|
|
762
|
-
const
|
|
763
|
-
|
|
856
|
+
const data = await payrollProgram.account.companyDeposit.fetch(translateAddress(company));
|
|
857
|
+
if (!data) {
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
const tokenDecimals = await getMintDecimals(payrollProgram.provider.connection, data.depositMint);
|
|
861
|
+
return {
|
|
862
|
+
company: data.company,
|
|
863
|
+
companyId: Buffer.from(data.companyId),
|
|
864
|
+
nonce: BigInt(data.nonce.toString()),
|
|
865
|
+
depositMint: data.depositMint,
|
|
866
|
+
depositedAmount: BigNumber(data.depositedAmount.toString())
|
|
867
|
+
.div(BigNumber(10).pow(tokenDecimals))
|
|
868
|
+
.toFixed(),
|
|
869
|
+
rewardsReceived: BigNumber(data.rewardsReceived.toString())
|
|
870
|
+
.div(BigNumber(10).pow(USX_DECIMALS))
|
|
871
|
+
.toFixed(),
|
|
872
|
+
depositTime: data.depositTime.toNumber(),
|
|
873
|
+
pendingUnlock: data.pendingUnlock
|
|
874
|
+
? {
|
|
875
|
+
tokenAmount: BigNumber(data.pendingUnlock.tokenAmount.toString())
|
|
876
|
+
.div(BigNumber(10).pow(tokenDecimals))
|
|
877
|
+
.toFixed(),
|
|
878
|
+
usxAmount: BigNumber(data.pendingUnlock.tokenAmount.toString())
|
|
879
|
+
.div(BigNumber(10).pow(USX_DECIMALS))
|
|
880
|
+
.toFixed(),
|
|
881
|
+
requestTime: data.pendingUnlock.requestTime.toNumber(),
|
|
882
|
+
}
|
|
883
|
+
: null,
|
|
884
|
+
};
|
|
764
885
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -198,22 +198,45 @@ 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
208
|
export type UnlockNowParams = {
|
|
214
|
-
feePayer
|
|
209
|
+
feePayer: Address;
|
|
210
|
+
company: Address;
|
|
211
|
+
nonce: bigint;
|
|
212
|
+
companyId: Buffer | Uint8Array;
|
|
213
|
+
};
|
|
214
|
+
export type RequestUnlockParams = {
|
|
215
|
+
feePayer: Address;
|
|
216
|
+
company: Address;
|
|
217
|
+
companyId: Buffer | Uint8Array;
|
|
218
|
+
nonce: bigint;
|
|
219
|
+
};
|
|
220
|
+
export type CancelUnlockParams = {
|
|
221
|
+
feePayer: Address;
|
|
222
|
+
company: Address;
|
|
223
|
+
companyId: Buffer | Uint8Array;
|
|
224
|
+
nonce: bigint;
|
|
225
|
+
};
|
|
226
|
+
export type CompleteUnlockParams = {
|
|
227
|
+
feePayer: Address;
|
|
215
228
|
company: Address;
|
|
216
|
-
|
|
229
|
+
companyId: Buffer | Uint8Array;
|
|
230
|
+
nonce: bigint;
|
|
231
|
+
};
|
|
232
|
+
export type DistributeRewardsParams = {
|
|
233
|
+
admin: Address;
|
|
234
|
+
feePayer: Address;
|
|
235
|
+
distributions: {
|
|
236
|
+
companyId: Buffer | Uint8Array;
|
|
237
|
+
nonce: bigint;
|
|
238
|
+
amount: Numeric;
|
|
239
|
+
}[];
|
|
217
240
|
};
|
|
218
241
|
export type PayrollFeeInfo = {
|
|
219
242
|
symbol: string;
|
|
@@ -237,3 +260,21 @@ export type PayrollFeeInfo = {
|
|
|
237
260
|
feeAmount: number;
|
|
238
261
|
feeAmountRaw: string;
|
|
239
262
|
};
|
|
263
|
+
export type CompanyNonceInfo = {
|
|
264
|
+
companyId: Buffer;
|
|
265
|
+
nonce: bigint;
|
|
266
|
+
};
|
|
267
|
+
export type CompanyDepositInfo = {
|
|
268
|
+
company: Address;
|
|
269
|
+
companyId: Buffer;
|
|
270
|
+
nonce: bigint;
|
|
271
|
+
depositMint: Address;
|
|
272
|
+
depositedAmount: Numeric;
|
|
273
|
+
rewardsReceived: Numeric;
|
|
274
|
+
depositTime: number;
|
|
275
|
+
pendingUnlock: {
|
|
276
|
+
tokenAmount: Numeric;
|
|
277
|
+
usxAmount: Numeric;
|
|
278
|
+
requestTime: number;
|
|
279
|
+
} | null;
|
|
280
|
+
};
|
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@solana/web3.js": "^1.98.2",
|
|
11
11
|
"@zebec-network/core-utils": "^1.2.0",
|
|
12
12
|
"@zebec-network/solana-common": "^2.6.0",
|
|
13
|
-
"@zebec-network/zebec_configs": "^1.
|
|
14
|
-
"@zebec-network/zebec_payroll": "^1.4.
|
|
13
|
+
"@zebec-network/zebec_configs": "^1.2.2",
|
|
14
|
+
"@zebec-network/zebec_payroll": "^1.4.2",
|
|
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.
|
|
47
|
-
}
|
|
46
|
+
"version": "2.3.0"
|
|
47
|
+
}
|