@zebec-network/solana-payroll-sdk 1.0.0-dev.1 → 1.0.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 +0 -2
- package/dist/constants.js +0 -9
- package/dist/instructions.d.ts +43 -75
- package/dist/instructions.js +48 -93
- package/dist/pda.d.ts +2 -2
- package/dist/pda.js +9 -6
- package/dist/program.d.ts +2 -0
- package/dist/program.js +4 -0
- package/dist/services.d.ts +13 -15
- package/dist/services.js +174 -228
- package/dist/types.d.ts +34 -67
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +37 -16
- package/package.json +4 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Address } from "@coral-xyz/anchor";
|
|
2
2
|
import type { Keypair, PublicKey } from "@solana/web3.js";
|
|
3
|
-
import type BN from "bn.js";
|
|
4
3
|
export type RpcNetwork = "mainnet-beta" | "devnet";
|
|
5
4
|
export type Numeric = string | number;
|
|
6
5
|
export type PayrollConfigInfo = {
|
|
7
6
|
configName: string;
|
|
8
7
|
address: PublicKey;
|
|
9
8
|
admin: PublicKey;
|
|
9
|
+
feeToken: PublicKey;
|
|
10
10
|
withdrawerAccount: PublicKey;
|
|
11
11
|
whitelistedTokens: PublicKey[];
|
|
12
12
|
platformFee: number;
|
|
@@ -19,13 +19,16 @@ export type PayrollMetadataInfo = {
|
|
|
19
19
|
address: PublicKey;
|
|
20
20
|
parties: {
|
|
21
21
|
sender: PublicKey;
|
|
22
|
+
senderId: Buffer;
|
|
22
23
|
receiver: PublicKey;
|
|
24
|
+
receiverId: Buffer;
|
|
23
25
|
};
|
|
24
26
|
financials: {
|
|
25
|
-
|
|
27
|
+
payrollToken: PublicKey;
|
|
26
28
|
cliffPercentage: number;
|
|
27
29
|
depositedAmount: string;
|
|
28
30
|
withdrawnAmount: string;
|
|
31
|
+
fullAmount: string;
|
|
29
32
|
};
|
|
30
33
|
schedule: {
|
|
31
34
|
startTime: number;
|
|
@@ -49,10 +52,10 @@ export type PayrollMetadataInfo = {
|
|
|
49
52
|
};
|
|
50
53
|
topupState: {
|
|
51
54
|
coveredUntill: number;
|
|
52
|
-
|
|
55
|
+
initialBufferAmount: string;
|
|
53
56
|
topupCount: number;
|
|
54
57
|
};
|
|
55
|
-
|
|
58
|
+
payrollName: string;
|
|
56
59
|
};
|
|
57
60
|
export type TokenMetadata = {
|
|
58
61
|
mint: PublicKey;
|
|
@@ -69,12 +72,12 @@ export type TokenMetadata = {
|
|
|
69
72
|
uri: string;
|
|
70
73
|
} | null;
|
|
71
74
|
};
|
|
72
|
-
export type
|
|
73
|
-
|
|
75
|
+
export type CreatePayrollParams = {
|
|
76
|
+
payrollConfigName: string;
|
|
74
77
|
feePayer?: Address;
|
|
75
78
|
receiver: Address;
|
|
76
79
|
sender: Address;
|
|
77
|
-
|
|
80
|
+
payrollToken: Address;
|
|
78
81
|
amount: Numeric;
|
|
79
82
|
automaticWithdrawal: boolean;
|
|
80
83
|
cancelableByRecipient: boolean;
|
|
@@ -85,110 +88,74 @@ export type CreateStreamParams = {
|
|
|
85
88
|
startNow: boolean;
|
|
86
89
|
startTime: number;
|
|
87
90
|
autoWithdrawFrequency: number;
|
|
88
|
-
|
|
91
|
+
payrollName: string;
|
|
89
92
|
transferableByRecipient: boolean;
|
|
90
93
|
transferableBySender: boolean;
|
|
91
94
|
canTopup: boolean;
|
|
92
95
|
rateUpdatable: boolean;
|
|
93
96
|
delegateAutoTopup: boolean;
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
initialBufferAmount: number;
|
|
98
|
+
payrollMetadataKeypair?: Keypair;
|
|
96
99
|
senderId: number[] | Uint8Array | Buffer;
|
|
97
100
|
receiverId: number[] | Uint8Array | Buffer;
|
|
98
101
|
};
|
|
99
|
-
export type InitializeStreamConfigParams = {
|
|
100
|
-
admin?: Address;
|
|
101
|
-
config: {
|
|
102
|
-
streamConfigName: string;
|
|
103
|
-
baseFeePercent: Numeric;
|
|
104
|
-
frequencies: number[];
|
|
105
|
-
platformFeePercent: Numeric;
|
|
106
|
-
withdrawAccount: Address;
|
|
107
|
-
feeTiers: FeeTier[];
|
|
108
|
-
feeVault: Address;
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
102
|
export type FeeTier = {
|
|
112
103
|
minThreshold: Numeric;
|
|
113
104
|
maxThreshold: Numeric;
|
|
114
105
|
feeRateInPercent: Numeric;
|
|
115
106
|
};
|
|
116
|
-
export type
|
|
117
|
-
admin?: Address;
|
|
118
|
-
config: {
|
|
119
|
-
streamConfigName: string;
|
|
120
|
-
baseFeePercent: Numeric;
|
|
121
|
-
frequencies: number[];
|
|
122
|
-
platformFeePercent: Numeric;
|
|
123
|
-
withdrawAccount: Address;
|
|
124
|
-
feeTiers: FeeTier[];
|
|
125
|
-
feeVault: Address;
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
export type CancelStreamParams = {
|
|
107
|
+
export type CancelPayrollParams = {
|
|
129
108
|
feePayer?: Address;
|
|
130
|
-
|
|
109
|
+
payrollMetadata: Address;
|
|
131
110
|
user: Address;
|
|
132
111
|
};
|
|
133
|
-
export type
|
|
134
|
-
|
|
112
|
+
export type PauseResumePayrollParams = {
|
|
113
|
+
payrollMetadata: Address;
|
|
135
114
|
};
|
|
136
|
-
export type
|
|
137
|
-
|
|
138
|
-
|
|
115
|
+
export type WithdrawPayrollParams = {
|
|
116
|
+
payrollConfigName: string;
|
|
117
|
+
payrollMetadata: Address;
|
|
139
118
|
withdrawer?: Address;
|
|
140
119
|
feePayer?: Address;
|
|
141
120
|
receiver: Address;
|
|
142
121
|
};
|
|
143
|
-
export type
|
|
144
|
-
|
|
145
|
-
admin: Address;
|
|
146
|
-
tokens: Address[];
|
|
147
|
-
};
|
|
148
|
-
export type ChangeStreamReceiverParams = {
|
|
149
|
-
streamMetadata: Address;
|
|
122
|
+
export type ChangePayrollReceiverParams = {
|
|
123
|
+
payrollMetadata: Address;
|
|
150
124
|
newRecipient: Address;
|
|
151
125
|
signer: Address;
|
|
152
126
|
};
|
|
153
|
-
export type
|
|
154
|
-
|
|
127
|
+
export type TopupPayrollParams = {
|
|
128
|
+
payrollConfigName: string;
|
|
155
129
|
caller?: Address;
|
|
156
130
|
sender: Address;
|
|
157
|
-
|
|
131
|
+
payrollMetadata: Address;
|
|
158
132
|
extra: Numeric;
|
|
159
133
|
};
|
|
160
134
|
export type SetTopupDelegateParams = {
|
|
161
|
-
|
|
135
|
+
payrollConfigName: string;
|
|
162
136
|
sender: Address;
|
|
163
|
-
|
|
137
|
+
payrollMetadata: Address;
|
|
164
138
|
amount: Numeric;
|
|
165
139
|
};
|
|
166
|
-
export type
|
|
167
|
-
|
|
168
|
-
mintAddress: string;
|
|
140
|
+
export type PayrollFeeInfo = {
|
|
141
|
+
symbol: string;
|
|
169
142
|
chain: string;
|
|
170
|
-
|
|
171
|
-
|
|
143
|
+
amount: string;
|
|
144
|
+
amountUi: string;
|
|
145
|
+
amountUsd: number;
|
|
172
146
|
tokenPriceUsd: number;
|
|
173
|
-
streamAmountUsd: number;
|
|
174
147
|
feeTier: {
|
|
175
148
|
tier: number;
|
|
176
|
-
|
|
149
|
+
label: string;
|
|
177
150
|
feeRatePercent: number;
|
|
178
151
|
};
|
|
179
|
-
feeRatePercent: number;
|
|
180
152
|
feeAmountUsd: number;
|
|
181
153
|
feeToken: {
|
|
182
154
|
symbol: string;
|
|
183
155
|
decimals: number;
|
|
184
156
|
priceUsd: number;
|
|
185
|
-
|
|
157
|
+
contractAddress: string;
|
|
186
158
|
};
|
|
187
159
|
feeAmount: number;
|
|
188
160
|
feeAmountRaw: string;
|
|
189
161
|
};
|
|
190
|
-
export type ParsedFeeTier = {
|
|
191
|
-
minAmount: BN;
|
|
192
|
-
maxAmount: BN;
|
|
193
|
-
fee: BN;
|
|
194
|
-
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Address } from "@coral-xyz/anchor";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
|
-
import type { FeeTier,
|
|
4
|
-
export declare function
|
|
3
|
+
import type { FeeTier, PayrollFeeInfo } from "./types.js";
|
|
4
|
+
export declare function getFeeInfoForPayroll(baseUrl: string, payrollToken: Address, parsedStreamTokenAmount: BigNumber.Value): Promise<PayrollFeeInfo>;
|
|
5
5
|
export declare function getFeeRateForUsdAmount(amount: BigNumber.Value, feeTiers: FeeTier[]): string;
|
|
6
|
-
export declare function getNetworkFromConnection(connection: Connection): RpcNetwork;
|
package/dist/utils.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { percentToBps } from "@zebec-network/core-utils";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
|
-
|
|
4
|
-
export async function getFeeInfoForStream(streamToken, parsedStreamTokenAmount, streamTokenDecimals, network) {
|
|
3
|
+
export async function getFeeInfoForPayroll(baseUrl, payrollToken, parsedStreamTokenAmount) {
|
|
5
4
|
const urlsParams = new URLSearchParams({
|
|
6
|
-
|
|
5
|
+
tokenMint: payrollToken.toString(),
|
|
7
6
|
chain: "SOLANA",
|
|
8
7
|
amount: BigNumber(parsedStreamTokenAmount).toFixed(0),
|
|
9
|
-
decimals: streamTokenDecimals.toString(),
|
|
10
8
|
});
|
|
11
|
-
const url = `${
|
|
9
|
+
const url = `${baseUrl}/payroll/fees/quote?${urlsParams}`;
|
|
12
10
|
const response = await fetch(url);
|
|
13
11
|
if (!response.ok) {
|
|
14
12
|
const body = await response.json().catch(() => null);
|
|
@@ -17,7 +15,40 @@ export async function getFeeInfoForStream(streamToken, parsedStreamTokenAmount,
|
|
|
17
15
|
}
|
|
18
16
|
throw new Error(`Failed to fetch fee token amount: ${response.status} ${response.statusText} ${body}`.trim());
|
|
19
17
|
}
|
|
20
|
-
const data = await response.json();
|
|
18
|
+
const data = (await response.json());
|
|
19
|
+
return parsePayrollFeeInfo(data);
|
|
20
|
+
}
|
|
21
|
+
function parsePayrollFeeInfo(data) {
|
|
22
|
+
if (typeof data !== "object" ||
|
|
23
|
+
data === null ||
|
|
24
|
+
typeof data.symbol !== "string" ||
|
|
25
|
+
typeof data.chain !== "string" ||
|
|
26
|
+
typeof data.amount !== "string" ||
|
|
27
|
+
typeof data.amountUi !== "string" ||
|
|
28
|
+
typeof data.amountUsd !== "number" ||
|
|
29
|
+
typeof data.tokenPriceUsd !== "number" ||
|
|
30
|
+
typeof data.feeAmountUsd !== "number" ||
|
|
31
|
+
typeof data.feeAmount !== "number" ||
|
|
32
|
+
typeof data.feeAmountRaw !== "string") {
|
|
33
|
+
throw new Error(`Invalid fee info response shape: ${JSON.stringify(data)}`);
|
|
34
|
+
}
|
|
35
|
+
const feeTier = data.feeTier;
|
|
36
|
+
if (typeof feeTier !== "object" ||
|
|
37
|
+
feeTier === null ||
|
|
38
|
+
typeof feeTier.tier !== "number" ||
|
|
39
|
+
typeof feeTier.label !== "string" ||
|
|
40
|
+
typeof feeTier.feeRatePercent !== "number") {
|
|
41
|
+
throw new Error(`Invalid fee info response shape (feeTier): ${JSON.stringify(data)}`);
|
|
42
|
+
}
|
|
43
|
+
const feeToken = data.feeToken;
|
|
44
|
+
if (typeof feeToken !== "object" ||
|
|
45
|
+
feeToken === null ||
|
|
46
|
+
typeof feeToken.symbol !== "string" ||
|
|
47
|
+
typeof feeToken.decimals !== "number" ||
|
|
48
|
+
typeof feeToken.priceUsd !== "number" ||
|
|
49
|
+
typeof feeToken.contractAddress !== "string") {
|
|
50
|
+
throw new Error(`Invalid fee info response shape (feeToken): ${JSON.stringify(data)}`);
|
|
51
|
+
}
|
|
21
52
|
return data;
|
|
22
53
|
}
|
|
23
54
|
export function getFeeRateForUsdAmount(amount, feeTiers) {
|
|
@@ -29,13 +60,3 @@ export function getFeeRateForUsdAmount(amount, feeTiers) {
|
|
|
29
60
|
}
|
|
30
61
|
return percentToBps(tier.feeRateInPercent);
|
|
31
62
|
}
|
|
32
|
-
export function getNetworkFromConnection(connection) {
|
|
33
|
-
const rpcEndpoint = connection.rpcEndpoint;
|
|
34
|
-
if (rpcEndpoint.includes("devnet")) {
|
|
35
|
-
return "devnet";
|
|
36
|
-
}
|
|
37
|
-
if (rpcEndpoint.includes("testnet")) {
|
|
38
|
-
throw new Error("Testnet is not supported");
|
|
39
|
-
}
|
|
40
|
-
return "mainnet-beta";
|
|
41
|
-
}
|
package/package.json
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"@solana/spl-token": "^0.4.14",
|
|
10
10
|
"@solana/web3.js": "^1.98.2",
|
|
11
11
|
"@zebec-network/core-utils": "^1.1.1",
|
|
12
|
-
"@zebec-network/solana-common": "^2.
|
|
13
|
-
"@zebec-network/
|
|
12
|
+
"@zebec-network/solana-common": "^2.4.0",
|
|
13
|
+
"@zebec-network/zebec_configs": "1.1.0",
|
|
14
|
+
"@zebec-network/zebec_payroll": "^1.3.0",
|
|
14
15
|
"bignumber.js": "^11.0.0"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
},
|
|
42
43
|
"type": "module",
|
|
43
44
|
"types": "dist/index.d.ts",
|
|
44
|
-
"version": "1.0.0
|
|
45
|
+
"version": "1.0.0"
|
|
45
46
|
}
|