@zebec-network/solana-payroll-sdk 2.3.1 → 2.5.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/instructions.d.ts +6 -0
- package/dist/instructions.js +6 -1
- package/dist/pda.d.ts +1 -0
- package/dist/pda.js +3 -0
- package/dist/services.js +28 -9
- package/dist/types.d.ts +3 -1
- package/package.json +47 -47
package/dist/instructions.d.ts
CHANGED
|
@@ -136,6 +136,10 @@ export declare function createCompleteUnlockInstruction(program: Program<ZebecPa
|
|
|
136
136
|
centralVaultTokenAta: PublicKey;
|
|
137
137
|
companyTokenAta: PublicKey;
|
|
138
138
|
depositMint: PublicKey;
|
|
139
|
+
centralVault: PublicKey;
|
|
140
|
+
centralVaultUsxAta: PublicKey;
|
|
141
|
+
usxMint: PublicKey;
|
|
142
|
+
companyUsxAta: PublicKey;
|
|
139
143
|
}, data: {
|
|
140
144
|
companyId: number[];
|
|
141
145
|
nonce: BN;
|
|
@@ -143,10 +147,12 @@ export declare function createCompleteUnlockInstruction(program: Program<ZebecPa
|
|
|
143
147
|
export declare function createDistributeRewardsInstruction(program: Program<ZebecPayrollIdl>, accounts: {
|
|
144
148
|
admin: PublicKey;
|
|
145
149
|
yieldConfig: PublicKey;
|
|
150
|
+
checkAccount: PublicKey;
|
|
146
151
|
}, data: {
|
|
147
152
|
distributions: {
|
|
148
153
|
companyId: number[];
|
|
149
154
|
nonce: BN;
|
|
150
155
|
amount: BN;
|
|
151
156
|
}[];
|
|
157
|
+
checkId: number[];
|
|
152
158
|
}, remainingAccounts: AccountMeta[]): Promise<TransactionInstruction>;
|
package/dist/instructions.js
CHANGED
|
@@ -177,15 +177,20 @@ export async function createCompleteUnlockInstruction(program, accounts, data) {
|
|
|
177
177
|
centralVaultTokenAta: accounts.centralVaultTokenAta,
|
|
178
178
|
companyTokenAta: accounts.companyTokenAta,
|
|
179
179
|
depositMint: accounts.depositMint,
|
|
180
|
+
centralVault: accounts.centralVault,
|
|
181
|
+
centralVaultUsxAta: accounts.centralVaultUsxAta,
|
|
182
|
+
usxMint: accounts.usxMint,
|
|
183
|
+
companyUsxAta: accounts.companyUsxAta,
|
|
180
184
|
})
|
|
181
185
|
.instruction();
|
|
182
186
|
}
|
|
183
187
|
export async function createDistributeRewardsInstruction(program, accounts, data, remainingAccounts) {
|
|
184
188
|
return program.methods
|
|
185
|
-
.distributeRewards(data.distributions)
|
|
189
|
+
.distributeRewards(data.checkId, data.distributions)
|
|
186
190
|
.accountsPartial({
|
|
187
191
|
admin: accounts.admin,
|
|
188
192
|
yieldConfig: accounts.yieldConfig,
|
|
193
|
+
checkAccount: accounts.checkAccount,
|
|
189
194
|
})
|
|
190
195
|
.remainingAccounts(remainingAccounts)
|
|
191
196
|
.instruction();
|
package/dist/pda.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare function derivePayrollVaultPda(metatadata: Address, payrollProgra
|
|
|
5
5
|
export declare function deriveYieldConfigPda(configProgramId: Address): [PublicKey, number];
|
|
6
6
|
export declare function deriveCompanyDepositPda(companyId: Buffer, nonce: bigint, payrollProgramId: Address): [PublicKey, number];
|
|
7
7
|
export declare function deriveCompanyNoncePda(companyId: Buffer, payrollProgramId: Address): [PublicKey, number];
|
|
8
|
+
export declare function deriveCheckAccountPda(checkId: Buffer | Uint8Array, payrollProgramId: Address): [PublicKey, number];
|
package/dist/pda.js
CHANGED
|
@@ -30,3 +30,6 @@ export function deriveCompanyDepositPda(companyId, nonce, payrollProgramId) {
|
|
|
30
30
|
export function deriveCompanyNoncePda(companyId, payrollProgramId) {
|
|
31
31
|
return PublicKey.findProgramAddressSync([companyId], translateAddress(payrollProgramId));
|
|
32
32
|
}
|
|
33
|
+
export function deriveCheckAccountPda(checkId, payrollProgramId) {
|
|
34
|
+
return PublicKey.findProgramAddressSync([checkId], translateAddress(payrollProgramId));
|
|
35
|
+
}
|
package/dist/services.js
CHANGED
|
@@ -9,7 +9,7 @@ import { BigNumber } from "bignumber.js";
|
|
|
9
9
|
import { BN } from "bn.js";
|
|
10
10
|
import { PAYROLL_NAME_BUFFER_SIZE, USX_DECIMALS } from "./constants.js";
|
|
11
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";
|
|
12
|
+
import { deriveCheckAccountPda, 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);
|
|
@@ -751,16 +751,15 @@ export async function requestUnlock(payrollProgram, configsProgram, params) {
|
|
|
751
751
|
}
|
|
752
752
|
export async function cancelUnlock(payrollProgram, params) {
|
|
753
753
|
const company = translateAddress(params.company);
|
|
754
|
-
const feePayer = translateAddress(params.feePayer);
|
|
755
754
|
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
756
755
|
const ix = await createCancelUnlockInstruction(payrollProgram, {
|
|
757
756
|
company,
|
|
758
757
|
companyDeposit,
|
|
759
758
|
}, {
|
|
760
759
|
companyId: Array.from(params.companyId),
|
|
761
|
-
nonce: new BN(params.nonce
|
|
760
|
+
nonce: new BN(params.nonce),
|
|
762
761
|
});
|
|
763
|
-
return createTransactionPayload(payrollProgram,
|
|
762
|
+
return createTransactionPayload(payrollProgram, company, [ix]);
|
|
764
763
|
}
|
|
765
764
|
export async function completeUnlock(payrollProgram, configsProgram, params, commitment) {
|
|
766
765
|
commitment = commitment ?? payrollProgram.provider.connection.commitment;
|
|
@@ -771,35 +770,51 @@ export async function completeUnlock(payrollProgram, configsProgram, params, com
|
|
|
771
770
|
if (!configData) {
|
|
772
771
|
throw new Error("YieldConfigNotFound: Yield config is not initialized in Zebec Configs Program");
|
|
773
772
|
}
|
|
774
|
-
|
|
775
|
-
const
|
|
773
|
+
const admin = configData.admin;
|
|
774
|
+
const centralVault = configData.centralVault;
|
|
775
|
+
const usxMint = configData.usxMint;
|
|
776
|
+
if (params.companyVaultKeypair &&
|
|
777
|
+
!centralVault.equals(params.companyVaultKeypair.publicKey)) {
|
|
778
|
+
throw new Error("Given keypair is not of companyVault");
|
|
779
|
+
}
|
|
776
780
|
const [companyDeposit] = deriveCompanyDepositPda(Buffer.from(params.companyId), params.nonce, payrollProgram.programId);
|
|
777
781
|
const companyDepositData = await payrollProgram.account.companyDeposit.fetchNullable(companyDeposit, commitment);
|
|
778
782
|
if (!companyDepositData) {
|
|
779
783
|
throw new Error(`CompanyDepositNotFound: Company Deposit does not exists for nonce: ${params.nonce.toString()}n and companyId: [${Array.from(params.companyId).toString()}]`);
|
|
780
784
|
}
|
|
781
785
|
const depositMint = companyDepositData.depositMint;
|
|
782
|
-
const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint,
|
|
786
|
+
const centralVaultTokenAta = getAssociatedTokenAddressSync(depositMint, centralVault, true);
|
|
787
|
+
const centralVaultUsxAta = getAssociatedTokenAddressSync(usxMint, centralVault, true);
|
|
783
788
|
const companyTokenAta = getAssociatedTokenAddressSync(depositMint, company, true);
|
|
789
|
+
const companyUsxAta = getAssociatedTokenAddressSync(usxMint, company, true);
|
|
784
790
|
const ix = await createCompleteUnlockInstruction(payrollProgram, {
|
|
785
791
|
admin,
|
|
786
792
|
feePayer,
|
|
787
793
|
company,
|
|
788
794
|
companyDeposit,
|
|
789
795
|
yieldConfig,
|
|
796
|
+
centralVault,
|
|
790
797
|
centralVaultTokenAta,
|
|
798
|
+
centralVaultUsxAta,
|
|
791
799
|
companyTokenAta,
|
|
800
|
+
companyUsxAta,
|
|
792
801
|
depositMint,
|
|
802
|
+
usxMint,
|
|
793
803
|
}, {
|
|
794
804
|
companyId: Array.from(params.companyId),
|
|
795
805
|
nonce: new BN(params.nonce.toString()),
|
|
796
806
|
});
|
|
797
|
-
|
|
807
|
+
const partialSigners = [];
|
|
808
|
+
if (params.companyVaultKeypair) {
|
|
809
|
+
partialSigners.push(params.companyVaultKeypair);
|
|
810
|
+
}
|
|
811
|
+
return createTransactionPayload(payrollProgram, feePayer, [ix], partialSigners);
|
|
798
812
|
}
|
|
799
813
|
export async function distributeRewards(payrollProgram, configsProgram, params) {
|
|
800
814
|
const admin = translateAddress(params.admin);
|
|
801
815
|
const feePayer = translateAddress(params.feePayer);
|
|
802
816
|
const [yieldConfig] = deriveYieldConfigPda(configsProgram.programId);
|
|
817
|
+
const [checkAccount] = deriveCheckAccountPda(params.checkId, payrollProgram.programId);
|
|
803
818
|
const distributions = params.distributions.map((d) => ({
|
|
804
819
|
companyId: Array.from(d.companyId),
|
|
805
820
|
nonce: new BN(d.nonce.toString()),
|
|
@@ -815,7 +830,11 @@ export async function distributeRewards(payrollProgram, configsProgram, params)
|
|
|
815
830
|
const ix = await createDistributeRewardsInstruction(payrollProgram, {
|
|
816
831
|
admin,
|
|
817
832
|
yieldConfig,
|
|
818
|
-
|
|
833
|
+
checkAccount,
|
|
834
|
+
}, {
|
|
835
|
+
distributions,
|
|
836
|
+
checkId: Array.from(params.checkId),
|
|
837
|
+
}, remainingAccounts);
|
|
819
838
|
return createTransactionPayload(payrollProgram, feePayer, [ix]);
|
|
820
839
|
}
|
|
821
840
|
export async function getCompanyDeposit(payrollProgram, company) {
|
package/dist/types.d.ts
CHANGED
|
@@ -212,7 +212,6 @@ export type RequestUnlockParams = {
|
|
|
212
212
|
nonce: bigint;
|
|
213
213
|
};
|
|
214
214
|
export type CancelUnlockParams = {
|
|
215
|
-
feePayer: Address;
|
|
216
215
|
company: Address;
|
|
217
216
|
companyId: Buffer | Uint8Array;
|
|
218
217
|
nonce: bigint;
|
|
@@ -222,10 +221,13 @@ export type CompleteUnlockParams = {
|
|
|
222
221
|
company: Address;
|
|
223
222
|
companyId: Buffer | Uint8Array;
|
|
224
223
|
nonce: bigint;
|
|
224
|
+
companyVaultKeypair?: Keypair;
|
|
225
225
|
};
|
|
226
226
|
export type DistributeRewardsParams = {
|
|
227
227
|
admin: Address;
|
|
228
228
|
feePayer: Address;
|
|
229
|
+
/** Check id used to derive the check account that prevents duplicate distributions. */
|
|
230
|
+
checkId: Buffer | Uint8Array;
|
|
229
231
|
distributions: {
|
|
230
232
|
companyId: Buffer | Uint8Array;
|
|
231
233
|
nonce: bigint;
|
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.3.
|
|
12
|
-
"@zebec-network/solana-common": "^2.6.0",
|
|
13
|
-
"@zebec-network/zebec_configs": "^1.2.
|
|
14
|
-
"@zebec-network/zebec_payroll": "^1.
|
|
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.
|
|
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.1",
|
|
12
|
+
"@zebec-network/solana-common": "^2.6.0",
|
|
13
|
+
"@zebec-network/zebec_configs": "^1.2.3",
|
|
14
|
+
"@zebec-network/zebec_payroll": "^1.5.0",
|
|
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 format && 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.5.0"
|
|
47
|
+
}
|