@zebec-network/solana-payroll-sdk 2.1.1 → 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 +16 -21
- package/dist/services.js +363 -76
- package/dist/types.d.ts +83 -10
- package/package.json +3 -3
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,35 +1,30 @@
|
|
|
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 { 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>;
|
|
10
10
|
export declare function createPayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: CreatePayrollParams, payrollFeeBaseUrl: string): Promise<TransactionPayload>;
|
|
11
11
|
export declare function createMultiplePayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: CreateMultiplePayrollParams, payrollFeeBaseUrl: string): Promise<MultiTransactionPayload>;
|
|
12
12
|
export declare function cancelPayroll(program: Program<ZebecPayrollIdl>, params: CancelPayrollParams): Promise<TransactionPayload>;
|
|
13
|
-
export declare function
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export declare function cancelMultiplePayroll(program: Program<ZebecPayrollIdl>, params: CancelMultiplePayrollParams): Promise<MultiTransactionPayload>;
|
|
14
|
+
export declare function pauseResumePayroll(program: Program<ZebecPayrollIdl>, params: PauseResumePayrollParams): Promise<TransactionPayload>;
|
|
15
|
+
export declare function pauseResumeMultiplePayroll(program: Program<ZebecPayrollIdl>, params: PauseResumeMultiplePayrollParams): Promise<MultiTransactionPayload>;
|
|
16
16
|
export declare function withdrawPayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: WithdrawPayrollParams): Promise<TransactionPayload>;
|
|
17
|
+
export declare function withdrawMultiplePayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: WithdrawMultiplePayrollParams): Promise<MultiTransactionPayload>;
|
|
17
18
|
export declare function changePayrollReceiver(program: Program<ZebecPayrollIdl>, params: ChangePayrollReceiverParams): Promise<TransactionPayload>;
|
|
18
19
|
export declare function setTopupDelegate(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: SetTopupDelegateParams): Promise<TransactionPayload>;
|
|
20
|
+
export declare function setMultipleTopupDelegate(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: SetMultipleTopupDelegateParams): Promise<MultiTransactionPayload>;
|
|
19
21
|
export declare function topupPayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: TopupPayrollParams): Promise<TransactionPayload>;
|
|
20
|
-
export declare function
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pendingUnlock: {
|
|
30
|
-
usdtAmount: import("bn.js");
|
|
31
|
-
usxAmount: import("bn.js");
|
|
32
|
-
requestTime: import("bn.js");
|
|
33
|
-
} | null;
|
|
34
|
-
bump: number;
|
|
35
|
-
}>;
|
|
22
|
+
export declare function topupMultiplePayroll(payrollProgram: Program<ZebecPayrollIdl>, configProgram: Program<ZebecConfigsIdl>, params: TopupMultiplePayrollParams): Promise<MultiTransactionPayload>;
|
|
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);
|
|
@@ -168,14 +168,15 @@ export async function getPayrollMetadataInfo(program, payrollMetadata, commitmen
|
|
|
168
168
|
payrollRunId: utils.bytes.utf8.decode(Uint8Array.from(metadataInfo.payrollRunId).filter((byte) => byte !== 0)), // Remove padding zeros
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
function createTransactionPayload(program, payerKey, instructions, signers, addressLookupTableAccounts) {
|
|
172
172
|
const errorMap = new Map();
|
|
173
173
|
program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
|
|
174
174
|
const provider = program.provider;
|
|
175
175
|
let signTransaction;
|
|
176
176
|
if (provider instanceof AnchorProvider) {
|
|
177
177
|
signTransaction = async (tx) => {
|
|
178
|
-
|
|
178
|
+
const signed = await provider.wallet.signTransaction(tx);
|
|
179
|
+
return signed;
|
|
179
180
|
};
|
|
180
181
|
}
|
|
181
182
|
return new TransactionPayload(program.provider.connection, errorMap, {
|
|
@@ -185,6 +186,22 @@ async function createPayload(program, payerKey, instructions, signers, addressLo
|
|
|
185
186
|
addressLookupTableAccounts: addressLookupTableAccounts ?? [],
|
|
186
187
|
}, signTransaction);
|
|
187
188
|
}
|
|
189
|
+
function createMultiTransactionPayload(program, feePayer, transactionData) {
|
|
190
|
+
const errorMap = new Map();
|
|
191
|
+
program.idl.errors.map((error) => errorMap.set(error.code, error.msg));
|
|
192
|
+
const provider = program.provider;
|
|
193
|
+
let signAllTransactions;
|
|
194
|
+
if (provider instanceof AnchorProvider) {
|
|
195
|
+
signAllTransactions = async (txs) => {
|
|
196
|
+
const signed = provider.wallet.signAllTransactions(txs);
|
|
197
|
+
return signed;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return MultiTransactionPayload.create(program.provider.connection, errorMap, transactionData.map((data) => ({
|
|
201
|
+
...data,
|
|
202
|
+
feePayer,
|
|
203
|
+
})), signAllTransactions);
|
|
204
|
+
}
|
|
188
205
|
export async function createPayroll(payrollProgram, configProgram, params, payrollFeeBaseUrl) {
|
|
189
206
|
const receiver = translateAddress(params.receiver);
|
|
190
207
|
const sender = translateAddress(params.sender);
|
|
@@ -276,7 +293,9 @@ export async function createPayroll(payrollProgram, configProgram, params, payro
|
|
|
276
293
|
senderId: Array.from(params.senderId),
|
|
277
294
|
});
|
|
278
295
|
ixs.push(createpayrollIx);
|
|
279
|
-
return
|
|
296
|
+
return createTransactionPayload(payrollProgram, feePayer, ixs, [
|
|
297
|
+
payrollMetadataKeypair,
|
|
298
|
+
]);
|
|
280
299
|
}
|
|
281
300
|
export async function createMultiplePayroll(payrollProgram, configProgram, params, payrollFeeBaseUrl) {
|
|
282
301
|
const sender = translateAddress(params.sender);
|
|
@@ -372,21 +391,11 @@ export async function createMultiplePayroll(payrollProgram, configProgram, param
|
|
|
372
391
|
});
|
|
373
392
|
instructions.push(createpayrollIx);
|
|
374
393
|
return {
|
|
375
|
-
feePayer,
|
|
376
394
|
instructions,
|
|
377
395
|
signers: [payrollMetadataKeypair],
|
|
378
396
|
};
|
|
379
397
|
}));
|
|
380
|
-
|
|
381
|
-
payrollProgram.idl.errors.map((error) => errorMap.set(error.code, error.msg));
|
|
382
|
-
const provider = payrollProgram.provider;
|
|
383
|
-
let signAllTransactions;
|
|
384
|
-
if (provider instanceof AnchorProvider) {
|
|
385
|
-
signAllTransactions = async (txns) => {
|
|
386
|
-
return provider.wallet.signAllTransactions(txns);
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
return MultiTransactionPayload.create(payrollProgram.provider.connection, errorMap, transactionData, signAllTransactions);
|
|
398
|
+
return createMultiTransactionPayload(payrollProgram, feePayer, transactionData);
|
|
390
399
|
}
|
|
391
400
|
export async function cancelPayroll(program, params) {
|
|
392
401
|
const user = translateAddress(params.user);
|
|
@@ -421,7 +430,47 @@ export async function cancelPayroll(program, params) {
|
|
|
421
430
|
payrollVault,
|
|
422
431
|
payrollVaultAta,
|
|
423
432
|
});
|
|
424
|
-
return
|
|
433
|
+
return createTransactionPayload(program, feePayer, [ix]);
|
|
434
|
+
}
|
|
435
|
+
export async function cancelMultiplePayroll(program, params) {
|
|
436
|
+
const user = translateAddress(params.user);
|
|
437
|
+
const feePayer = params.feePayer ? translateAddress(params.feePayer) : user;
|
|
438
|
+
const transactionData = await Promise.all(params.payrollMetadataList.map(async (address) => {
|
|
439
|
+
const payrollMetadata = translateAddress(address);
|
|
440
|
+
const payrollMetadataAccount = await program.account.paymentStream.fetch(payrollMetadata);
|
|
441
|
+
const payrollToken = payrollMetadataAccount.financials.streamToken;
|
|
442
|
+
const payroller = payrollMetadataAccount.parties.sender;
|
|
443
|
+
const receiver = payrollMetadataAccount.parties.receiver;
|
|
444
|
+
let otherParty;
|
|
445
|
+
if (user.equals(payroller)) {
|
|
446
|
+
otherParty = receiver;
|
|
447
|
+
}
|
|
448
|
+
else if (user.equals(receiver)) {
|
|
449
|
+
otherParty = payroller;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
throw new Error("User must be either payroller or receiver");
|
|
453
|
+
}
|
|
454
|
+
const userAta = getAssociatedTokenAddressSync(payrollToken, user, true);
|
|
455
|
+
const otherPartyAta = getAssociatedTokenAddressSync(payrollToken, otherParty, true);
|
|
456
|
+
const [payrollVault] = derivePayrollVaultPda(payrollMetadata, program.programId);
|
|
457
|
+
const payrollVaultAta = getAssociatedTokenAddressSync(payrollToken, payrollVault, true);
|
|
458
|
+
const ix = await createCancelPayrollInstruction(program, {
|
|
459
|
+
feePayer,
|
|
460
|
+
otherParty,
|
|
461
|
+
otherPartyAta,
|
|
462
|
+
signer: user,
|
|
463
|
+
signerAta: userAta,
|
|
464
|
+
payrollMetadata,
|
|
465
|
+
payrollToken,
|
|
466
|
+
payrollVault,
|
|
467
|
+
payrollVaultAta,
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
instructions: [ix],
|
|
471
|
+
};
|
|
472
|
+
}));
|
|
473
|
+
return createMultiTransactionPayload(program, feePayer, transactionData);
|
|
425
474
|
}
|
|
426
475
|
export async function pauseResumePayroll(program, params) {
|
|
427
476
|
const payrollMetadata = translateAddress(params.payrollMetadata);
|
|
@@ -431,7 +480,28 @@ export async function pauseResumePayroll(program, params) {
|
|
|
431
480
|
payrollMetadata,
|
|
432
481
|
user,
|
|
433
482
|
});
|
|
434
|
-
return
|
|
483
|
+
return createTransactionPayload(program, user, [ix]);
|
|
484
|
+
}
|
|
485
|
+
export async function pauseResumeMultiplePayroll(program, params) {
|
|
486
|
+
const transactionData = await Promise.all(params.payrollMetadataList.map(async (address) => {
|
|
487
|
+
const payrollMetadata = translateAddress(address);
|
|
488
|
+
const payrollMetadataAccount = await program.account.paymentStream.fetch(payrollMetadata);
|
|
489
|
+
const user = payrollMetadataAccount.parties.sender;
|
|
490
|
+
const ix = await createPauseResumePayrollInstruction(program, {
|
|
491
|
+
payrollMetadata,
|
|
492
|
+
user,
|
|
493
|
+
});
|
|
494
|
+
return {
|
|
495
|
+
user,
|
|
496
|
+
instructions: [ix],
|
|
497
|
+
};
|
|
498
|
+
}));
|
|
499
|
+
if (transactionData.length === 0) {
|
|
500
|
+
throw new Error("There should be at least one item in transaction data.");
|
|
501
|
+
}
|
|
502
|
+
// biome-ignore lint/style/noNonNullAssertion: there is at least one item in the list so 0 index will not be empty
|
|
503
|
+
const feePayer = transactionData[0].user;
|
|
504
|
+
return createMultiTransactionPayload(program, feePayer, transactionData);
|
|
435
505
|
}
|
|
436
506
|
export async function withdrawPayroll(payrollProgram, configProgram, params) {
|
|
437
507
|
const [payrollConfig] = derivePayrollConfigPda(params.payrollConfigName, configProgram.programId);
|
|
@@ -461,7 +531,43 @@ export async function withdrawPayroll(payrollProgram, configProgram, params) {
|
|
|
461
531
|
withdrawer,
|
|
462
532
|
feePayer,
|
|
463
533
|
});
|
|
464
|
-
return
|
|
534
|
+
return createTransactionPayload(payrollProgram, withdrawer, [ix]);
|
|
535
|
+
}
|
|
536
|
+
export async function withdrawMultiplePayroll(payrollProgram, configProgram, params) {
|
|
537
|
+
const [payrollConfig] = derivePayrollConfigPda(params.payrollConfigName, configProgram.programId);
|
|
538
|
+
const receiver = translateAddress(params.receiver);
|
|
539
|
+
const withdrawer = params.withdrawer
|
|
540
|
+
? translateAddress(params.withdrawer)
|
|
541
|
+
: receiver;
|
|
542
|
+
const feePayer = params.feePayer
|
|
543
|
+
? translateAddress(params.feePayer)
|
|
544
|
+
: params.withdrawer
|
|
545
|
+
? withdrawer
|
|
546
|
+
: receiver;
|
|
547
|
+
const transactionData = await Promise.all(params.payrollMetadataList.map(async (address) => {
|
|
548
|
+
const payrollMetadata = translateAddress(address);
|
|
549
|
+
const payrollMetadataAccount = await payrollProgram.account.paymentStream.fetch(payrollMetadata);
|
|
550
|
+
const payrollToken = payrollMetadataAccount.financials.streamToken;
|
|
551
|
+
const receiverAta = getAssociatedTokenAddressSync(payrollToken, receiver, true);
|
|
552
|
+
const [payrollVault] = derivePayrollVaultPda(payrollMetadata, payrollProgram.programId);
|
|
553
|
+
const payrollVaultAta = getAssociatedTokenAddressSync(payrollToken, payrollVault, true);
|
|
554
|
+
const ix = await createWithdrawPayrollInstruction(payrollProgram, {
|
|
555
|
+
receiver,
|
|
556
|
+
receiverAta,
|
|
557
|
+
payrollConfig,
|
|
558
|
+
payrollMetadata,
|
|
559
|
+
payrollToken,
|
|
560
|
+
payrollVault,
|
|
561
|
+
payrollVaultAta,
|
|
562
|
+
withdrawer,
|
|
563
|
+
feePayer,
|
|
564
|
+
});
|
|
565
|
+
return {
|
|
566
|
+
feePayer: withdrawer,
|
|
567
|
+
instructions: [ix],
|
|
568
|
+
};
|
|
569
|
+
}));
|
|
570
|
+
return createMultiTransactionPayload(payrollProgram, withdrawer, transactionData);
|
|
465
571
|
}
|
|
466
572
|
export async function changePayrollReceiver(program, params) {
|
|
467
573
|
const payrollMetadata = translateAddress(params.payrollMetadata);
|
|
@@ -472,7 +578,7 @@ export async function changePayrollReceiver(program, params) {
|
|
|
472
578
|
newRecipient,
|
|
473
579
|
signer,
|
|
474
580
|
});
|
|
475
|
-
return
|
|
581
|
+
return createTransactionPayload(program, signer, [ix]);
|
|
476
582
|
}
|
|
477
583
|
export async function setTopupDelegate(payrollProgram, configProgram, params) {
|
|
478
584
|
const sender = translateAddress(params.sender);
|
|
@@ -496,12 +602,39 @@ export async function setTopupDelegate(payrollProgram, configProgram, params) {
|
|
|
496
602
|
}, {
|
|
497
603
|
amount,
|
|
498
604
|
});
|
|
499
|
-
return
|
|
605
|
+
return createTransactionPayload(payrollProgram, sender, [ix]);
|
|
606
|
+
}
|
|
607
|
+
export async function setMultipleTopupDelegate(payrollProgram, configProgram, params) {
|
|
608
|
+
const sender = translateAddress(params.sender);
|
|
609
|
+
const [payrollConfig] = derivePayrollConfigPda(params.payrollConfigName, configProgram.programId);
|
|
610
|
+
const transactionData = await Promise.all(params.delegateInfoList.map(async (delegateInfo) => {
|
|
611
|
+
const payrollMetadata = translateAddress(delegateInfo.payrollMetadata);
|
|
612
|
+
const payrollMetadataAccount = await payrollProgram.account.paymentStream.fetch(payrollMetadata);
|
|
613
|
+
const payrollToken = payrollMetadataAccount.financials.streamToken;
|
|
614
|
+
const senderAta = getAssociatedTokenAddressSync(payrollToken, sender, true);
|
|
615
|
+
const [payrollVault] = derivePayrollVaultPda(payrollMetadata, payrollProgram.programId);
|
|
616
|
+
const payrollTokenDecimals = await getMintDecimals(payrollProgram.provider.connection, payrollToken);
|
|
617
|
+
const amount = new BN(BigNumber(delegateInfo.amount)
|
|
618
|
+
.multipliedBy(BigNumber(10).pow(payrollTokenDecimals))
|
|
619
|
+
.toFixed(0));
|
|
620
|
+
const ix = await createSetTopupDelegateInstruction(payrollProgram, {
|
|
621
|
+
sender,
|
|
622
|
+
senderAta,
|
|
623
|
+
payrollConfig,
|
|
624
|
+
payrollMetadata,
|
|
625
|
+
payrollToken,
|
|
626
|
+
payrollVault,
|
|
627
|
+
}, { amount });
|
|
628
|
+
return {
|
|
629
|
+
instructions: [ix],
|
|
630
|
+
};
|
|
631
|
+
}));
|
|
632
|
+
return createMultiTransactionPayload(payrollProgram, sender, transactionData);
|
|
500
633
|
}
|
|
501
634
|
export async function topupPayroll(payrollProgram, configProgram, params) {
|
|
502
635
|
const sender = translateAddress(params.sender);
|
|
503
636
|
const payrollMetadata = translateAddress(params.payrollMetadata);
|
|
504
|
-
const caller =
|
|
637
|
+
const caller = translateAddress(params.caller);
|
|
505
638
|
const payrollMetadataAccount = await payrollProgram.account.paymentStream.fetch(payrollMetadata);
|
|
506
639
|
const payrollToken = payrollMetadataAccount.financials.streamToken;
|
|
507
640
|
const senderAta = getAssociatedTokenAddressSync(payrollToken, sender, true);
|
|
@@ -524,75 +657,229 @@ export async function topupPayroll(payrollProgram, configProgram, params) {
|
|
|
524
657
|
}, {
|
|
525
658
|
extra: amount,
|
|
526
659
|
});
|
|
527
|
-
return
|
|
660
|
+
return createTransactionPayload(payrollProgram, caller, [ix]);
|
|
528
661
|
}
|
|
529
|
-
export async function
|
|
530
|
-
const
|
|
531
|
-
const
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
662
|
+
export async function topupMultiplePayroll(payrollProgram, configProgram, params) {
|
|
663
|
+
const caller = translateAddress(params.caller);
|
|
664
|
+
const [payrollConfig] = derivePayrollConfigPda(params.payrollConfigName, configProgram.programId);
|
|
665
|
+
const transactionData = await Promise.all(params.topupInfoList.map(async (topupInfo) => {
|
|
666
|
+
const sender = translateAddress(topupInfo.sender);
|
|
667
|
+
const payrollMetadata = translateAddress(topupInfo.payrollMetadata);
|
|
668
|
+
const payrollMetadataAccount = await payrollProgram.account.paymentStream.fetch(payrollMetadata);
|
|
669
|
+
const payrollToken = payrollMetadataAccount.financials.streamToken;
|
|
670
|
+
const senderAta = getAssociatedTokenAddressSync(payrollToken, sender, true);
|
|
671
|
+
const [payrollVault] = derivePayrollVaultPda(payrollMetadata, payrollProgram.programId);
|
|
672
|
+
const payrollVaultAta = getAssociatedTokenAddressSync(payrollToken, payrollVault, true);
|
|
673
|
+
const payrollTokenDecimals = await getMintDecimals(payrollProgram.provider.connection, payrollToken);
|
|
674
|
+
const amount = new BN(BigNumber(topupInfo.extra)
|
|
675
|
+
.multipliedBy(BigNumber(10).pow(payrollTokenDecimals))
|
|
676
|
+
.toFixed(0));
|
|
677
|
+
const ix = await createTopupPayrollInstruction(payrollProgram, {
|
|
678
|
+
caller,
|
|
679
|
+
sender,
|
|
680
|
+
senderAta,
|
|
681
|
+
payrollConfig,
|
|
682
|
+
payrollMetadata,
|
|
683
|
+
payrollToken,
|
|
684
|
+
payrollVault,
|
|
685
|
+
payrollVaultAta,
|
|
686
|
+
}, { extra: amount });
|
|
687
|
+
return {
|
|
688
|
+
instructions: [ix],
|
|
689
|
+
};
|
|
690
|
+
}));
|
|
691
|
+
return createMultiTransactionPayload(payrollProgram, caller, transactionData);
|
|
692
|
+
}
|
|
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,
|
|
542
724
|
yieldConfig,
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
725
|
+
centralVault,
|
|
726
|
+
centralVaultTokenAta,
|
|
727
|
+
companyNonce,
|
|
728
|
+
companyTokenAta,
|
|
729
|
+
depositMint,
|
|
547
730
|
}, {
|
|
548
|
-
|
|
549
|
-
|
|
731
|
+
amount,
|
|
732
|
+
companyId: Array.from(params.companyId),
|
|
733
|
+
nonce: new BN(params.nonce),
|
|
550
734
|
});
|
|
551
|
-
return
|
|
735
|
+
return createTransactionPayload(payrollProgram, company, [ix]);
|
|
552
736
|
}
|
|
553
|
-
export async function
|
|
737
|
+
export async function unlockNow(payrollProgram, configsProgram, params, commitment) {
|
|
738
|
+
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
554
739
|
const company = translateAddress(params.company);
|
|
555
|
-
const
|
|
556
|
-
const [
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
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);
|
|
756
|
+
const ix = await createUnlockNowInstruction(payrollProgram, {
|
|
757
|
+
feePayer,
|
|
564
758
|
company,
|
|
565
759
|
companyDeposit,
|
|
566
760
|
yieldConfig,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}, {
|
|
572
|
-
|
|
761
|
+
admin,
|
|
762
|
+
centralVaultTokenAta: adminTokenAta,
|
|
763
|
+
companyTokenAta,
|
|
764
|
+
depositMint,
|
|
765
|
+
}, {
|
|
766
|
+
companyId: Array.from(params.companyId),
|
|
767
|
+
nonce: new BN(params.nonce),
|
|
768
|
+
});
|
|
769
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
573
770
|
}
|
|
574
|
-
export async function
|
|
771
|
+
export async function requestUnlock(payrollProgram, configsProgram, params) {
|
|
575
772
|
const company = translateAddress(params.company);
|
|
576
|
-
const
|
|
577
|
-
const
|
|
578
|
-
const [companyDeposit] = deriveCompanyDepositPda(
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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,
|
|
584
820
|
feePayer,
|
|
585
821
|
company,
|
|
586
822
|
companyDeposit,
|
|
587
823
|
yieldConfig,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
824
|
+
centralVaultTokenAta,
|
|
825
|
+
companyTokenAta,
|
|
826
|
+
depositMint,
|
|
827
|
+
}, {
|
|
828
|
+
companyId: Array.from(params.companyId),
|
|
829
|
+
nonce: new BN(params.nonce.toString()),
|
|
592
830
|
});
|
|
593
|
-
return
|
|
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]);
|
|
594
854
|
}
|
|
595
855
|
export async function getCompanyDeposit(payrollProgram, company) {
|
|
596
|
-
const
|
|
597
|
-
|
|
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
|
+
};
|
|
598
885
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -138,9 +138,17 @@ export type CancelPayrollParams = {
|
|
|
138
138
|
payrollMetadata: Address;
|
|
139
139
|
user: Address;
|
|
140
140
|
};
|
|
141
|
+
export type CancelMultiplePayrollParams = {
|
|
142
|
+
feePayer?: Address;
|
|
143
|
+
user: Address;
|
|
144
|
+
payrollMetadataList: Address[];
|
|
145
|
+
};
|
|
141
146
|
export type PauseResumePayrollParams = {
|
|
142
147
|
payrollMetadata: Address;
|
|
143
148
|
};
|
|
149
|
+
export type PauseResumeMultiplePayrollParams = {
|
|
150
|
+
payrollMetadataList: Address[];
|
|
151
|
+
};
|
|
144
152
|
export type WithdrawPayrollParams = {
|
|
145
153
|
payrollConfigName: string;
|
|
146
154
|
payrollMetadata: Address;
|
|
@@ -148,6 +156,13 @@ export type WithdrawPayrollParams = {
|
|
|
148
156
|
feePayer?: Address;
|
|
149
157
|
receiver: Address;
|
|
150
158
|
};
|
|
159
|
+
export type WithdrawMultiplePayrollParams = {
|
|
160
|
+
payrollConfigName: string;
|
|
161
|
+
payrollMetadataList: Address[];
|
|
162
|
+
withdrawer?: Address;
|
|
163
|
+
feePayer?: Address;
|
|
164
|
+
receiver: Address;
|
|
165
|
+
};
|
|
151
166
|
export type ChangePayrollReceiverParams = {
|
|
152
167
|
payrollMetadata: Address;
|
|
153
168
|
newRecipient: Address;
|
|
@@ -155,33 +170,73 @@ export type ChangePayrollReceiverParams = {
|
|
|
155
170
|
};
|
|
156
171
|
export type TopupPayrollParams = {
|
|
157
172
|
payrollConfigName: string;
|
|
158
|
-
caller
|
|
173
|
+
caller: Address;
|
|
159
174
|
sender: Address;
|
|
160
175
|
payrollMetadata: Address;
|
|
161
176
|
extra: Numeric;
|
|
162
177
|
};
|
|
178
|
+
export type TopupMultiplePayrollParams = {
|
|
179
|
+
payrollConfigName: string;
|
|
180
|
+
caller: Address;
|
|
181
|
+
topupInfoList: {
|
|
182
|
+
sender: Address;
|
|
183
|
+
payrollMetadata: Address;
|
|
184
|
+
extra: Numeric;
|
|
185
|
+
}[];
|
|
186
|
+
};
|
|
163
187
|
export type SetTopupDelegateParams = {
|
|
164
188
|
payrollConfigName: string;
|
|
165
189
|
sender: Address;
|
|
166
190
|
payrollMetadata: Address;
|
|
167
191
|
amount: Numeric;
|
|
168
192
|
};
|
|
169
|
-
export type
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
193
|
+
export type SetMultipleTopupDelegateParams = {
|
|
194
|
+
payrollConfigName: string;
|
|
195
|
+
sender: Address;
|
|
196
|
+
delegateInfoList: {
|
|
197
|
+
payrollMetadata: Address;
|
|
198
|
+
amount: Numeric;
|
|
199
|
+
}[];
|
|
175
200
|
};
|
|
176
201
|
export type YieldDepositParams = {
|
|
202
|
+
companyId: Buffer | Uint8Array;
|
|
177
203
|
company: Address;
|
|
178
|
-
|
|
204
|
+
nonce: bigint;
|
|
205
|
+
depoistMint: Address;
|
|
179
206
|
amount: Numeric;
|
|
180
207
|
};
|
|
181
208
|
export type UnlockNowParams = {
|
|
182
|
-
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;
|
|
183
228
|
company: Address;
|
|
184
|
-
|
|
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
|
+
}[];
|
|
185
240
|
};
|
|
186
241
|
export type PayrollFeeInfo = {
|
|
187
242
|
symbol: string;
|
|
@@ -205,3 +260,21 @@ export type PayrollFeeInfo = {
|
|
|
205
260
|
feeAmount: number;
|
|
206
261
|
feeAmountRaw: string;
|
|
207
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.
|
|
46
|
+
"version": "2.3.0"
|
|
47
47
|
}
|