@primuslabs/fund-js-sdk 0.1.27 → 0.1.28
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/index.js +21 -30
- package/dist/index.mjs +21 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -187,11 +187,16 @@ var formatErrFn = (error) => {
|
|
|
187
187
|
if (isNoPendingWithdrawals) {
|
|
188
188
|
formatError = "no pending withdrawals";
|
|
189
189
|
}
|
|
190
|
-
const insufficientBalanceErrStrArr = ["insufficient
|
|
190
|
+
const insufficientBalanceErrStrArr = ["insufficient", "The caller does not have enough funds for value transfer.", "insufficient lamports", "Attempt to debit an account but found no record of a prior credit"];
|
|
191
191
|
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
192
192
|
if (isInsufficientBalance) {
|
|
193
193
|
formatError = "insufficient balance";
|
|
194
194
|
}
|
|
195
|
+
const mayInsufficientBalanceErrStrArr = ["unpredictable_gas_limit"];
|
|
196
|
+
const isMayInsufficientBalance = hasErrorFlagFn(curErrorStrArr, mayInsufficientBalanceErrStrArr);
|
|
197
|
+
if (isMayInsufficientBalance) {
|
|
198
|
+
formatError = "may insufficient balance";
|
|
199
|
+
}
|
|
195
200
|
const alreadyClaimedErrStrArr = ["Already claimed"];
|
|
196
201
|
const isAlreadyClaimed = hasErrorFlagFn(curErrorStrArr, alreadyClaimedErrStrArr);
|
|
197
202
|
if (isAlreadyClaimed) {
|
|
@@ -248,35 +253,8 @@ var Contract = class {
|
|
|
248
253
|
resolve(tx.hash);
|
|
249
254
|
} catch (error) {
|
|
250
255
|
console.log("sendTransaction error:", error);
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
const errorMsg2 = typeof error === "object" ? JSON.stringify(error) : error?.toString();
|
|
254
|
-
const curErrorStrArr = [errorMsg1, errorMsg2];
|
|
255
|
-
const userRejectErrStrArr = ["user rejected", "approval denied"];
|
|
256
|
-
const isUserRejected = hasErrorFlagFn(curErrorStrArr, userRejectErrStrArr);
|
|
257
|
-
if (error?.code === "ACTION_REJECTED" || isUserRejected) {
|
|
258
|
-
return reject("user rejected transaction");
|
|
259
|
-
}
|
|
260
|
-
const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
|
|
261
|
-
if (isNoPendingWithdrawals) {
|
|
262
|
-
return reject("no pending withdrawals");
|
|
263
|
-
}
|
|
264
|
-
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS", "The caller does not have enough funds for value transfer.", "insufficient lamports", "Attempt to debit an account but found no record of a prior credit"];
|
|
265
|
-
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
266
|
-
if (isInsufficientBalance) {
|
|
267
|
-
return reject("insufficient balance");
|
|
268
|
-
}
|
|
269
|
-
const alreadyClaimedErrStrArr = ["Already claimed"];
|
|
270
|
-
const isAlreadyClaimed = hasErrorFlagFn(curErrorStrArr, alreadyClaimedErrStrArr);
|
|
271
|
-
if (isAlreadyClaimed) {
|
|
272
|
-
return reject("already claimed");
|
|
273
|
-
}
|
|
274
|
-
const allClaimedErrStrArr = ["All claimed"];
|
|
275
|
-
const isAllClaimed = hasErrorFlagFn(curErrorStrArr, allClaimedErrStrArr);
|
|
276
|
-
if (isAllClaimed) {
|
|
277
|
-
return reject("all claimed");
|
|
278
|
-
}
|
|
279
|
-
return reject(error);
|
|
256
|
+
const formatErr = formatErrFn(error);
|
|
257
|
+
return reject(formatErr);
|
|
280
258
|
}
|
|
281
259
|
});
|
|
282
260
|
}
|
|
@@ -3008,6 +2986,12 @@ var getTxIsOnProcess = (err) => {
|
|
|
3008
2986
|
const isOnProcess = hasErrorFlagFn(curErrorStrArr, strArr);
|
|
3009
2987
|
return isOnProcess;
|
|
3010
2988
|
};
|
|
2989
|
+
async function isSolanaBalanceZero(connection, userPK) {
|
|
2990
|
+
const balanceLamports = await connection.getBalance(userPK);
|
|
2991
|
+
const balanceSOL = balanceLamports / 1e9;
|
|
2992
|
+
console.log(`Account balance: ${balanceSOL} SOL`);
|
|
2993
|
+
return balanceSOL <= 0;
|
|
2994
|
+
}
|
|
3011
2995
|
|
|
3012
2996
|
// src/config/redPacketIdl.json
|
|
3013
2997
|
var redPacketIdl_default = {
|
|
@@ -5882,6 +5866,13 @@ async function reClaim({
|
|
|
5882
5866
|
console.log("primusZktlsPda:", primusZktlsPda.toBase58());
|
|
5883
5867
|
console.log("reRecordPda:", reRecordPda.toBase58());
|
|
5884
5868
|
const attRecipient = new import_web33.PublicKey(attObj.recipient);
|
|
5869
|
+
const isEmptyWallet = await isSolanaBalanceZero(provider.connection, attRecipient);
|
|
5870
|
+
if (isEmptyWallet) {
|
|
5871
|
+
const err = "insufficient";
|
|
5872
|
+
const formatErr = formatErrFn(err);
|
|
5873
|
+
reject(formatErr);
|
|
5874
|
+
return;
|
|
5875
|
+
}
|
|
5885
5876
|
const redEnvelopeState = await redEnvelopeProgram.account.redEnvelopeState.fetch(redEnvelopePda);
|
|
5886
5877
|
console.log("redEnvelopeState.feeRecipient", redEnvelopeState.feeRecipient.toBase58());
|
|
5887
5878
|
const feeRecipient = redEnvelopeState.feeRecipient;
|
package/dist/index.mjs
CHANGED
|
@@ -153,11 +153,16 @@ var formatErrFn = (error) => {
|
|
|
153
153
|
if (isNoPendingWithdrawals) {
|
|
154
154
|
formatError = "no pending withdrawals";
|
|
155
155
|
}
|
|
156
|
-
const insufficientBalanceErrStrArr = ["insufficient
|
|
156
|
+
const insufficientBalanceErrStrArr = ["insufficient", "The caller does not have enough funds for value transfer.", "insufficient lamports", "Attempt to debit an account but found no record of a prior credit"];
|
|
157
157
|
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
158
158
|
if (isInsufficientBalance) {
|
|
159
159
|
formatError = "insufficient balance";
|
|
160
160
|
}
|
|
161
|
+
const mayInsufficientBalanceErrStrArr = ["unpredictable_gas_limit"];
|
|
162
|
+
const isMayInsufficientBalance = hasErrorFlagFn(curErrorStrArr, mayInsufficientBalanceErrStrArr);
|
|
163
|
+
if (isMayInsufficientBalance) {
|
|
164
|
+
formatError = "may insufficient balance";
|
|
165
|
+
}
|
|
161
166
|
const alreadyClaimedErrStrArr = ["Already claimed"];
|
|
162
167
|
const isAlreadyClaimed = hasErrorFlagFn(curErrorStrArr, alreadyClaimedErrStrArr);
|
|
163
168
|
if (isAlreadyClaimed) {
|
|
@@ -214,35 +219,8 @@ var Contract = class {
|
|
|
214
219
|
resolve(tx.hash);
|
|
215
220
|
} catch (error) {
|
|
216
221
|
console.log("sendTransaction error:", error);
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
const errorMsg2 = typeof error === "object" ? JSON.stringify(error) : error?.toString();
|
|
220
|
-
const curErrorStrArr = [errorMsg1, errorMsg2];
|
|
221
|
-
const userRejectErrStrArr = ["user rejected", "approval denied"];
|
|
222
|
-
const isUserRejected = hasErrorFlagFn(curErrorStrArr, userRejectErrStrArr);
|
|
223
|
-
if (error?.code === "ACTION_REJECTED" || isUserRejected) {
|
|
224
|
-
return reject("user rejected transaction");
|
|
225
|
-
}
|
|
226
|
-
const isNoPendingWithdrawals = hasErrorFlagFn(curErrorStrArr, ["no pending withdrawals"]);
|
|
227
|
-
if (isNoPendingWithdrawals) {
|
|
228
|
-
return reject("no pending withdrawals");
|
|
229
|
-
}
|
|
230
|
-
const insufficientBalanceErrStrArr = ["insufficient balance", "INSUFFICIENT_FUNDS", "The caller does not have enough funds for value transfer.", "insufficient lamports", "Attempt to debit an account but found no record of a prior credit"];
|
|
231
|
-
const isInsufficientBalance = hasErrorFlagFn(curErrorStrArr, insufficientBalanceErrStrArr);
|
|
232
|
-
if (isInsufficientBalance) {
|
|
233
|
-
return reject("insufficient balance");
|
|
234
|
-
}
|
|
235
|
-
const alreadyClaimedErrStrArr = ["Already claimed"];
|
|
236
|
-
const isAlreadyClaimed = hasErrorFlagFn(curErrorStrArr, alreadyClaimedErrStrArr);
|
|
237
|
-
if (isAlreadyClaimed) {
|
|
238
|
-
return reject("already claimed");
|
|
239
|
-
}
|
|
240
|
-
const allClaimedErrStrArr = ["All claimed"];
|
|
241
|
-
const isAllClaimed = hasErrorFlagFn(curErrorStrArr, allClaimedErrStrArr);
|
|
242
|
-
if (isAllClaimed) {
|
|
243
|
-
return reject("all claimed");
|
|
244
|
-
}
|
|
245
|
-
return reject(error);
|
|
222
|
+
const formatErr = formatErrFn(error);
|
|
223
|
+
return reject(formatErr);
|
|
246
224
|
}
|
|
247
225
|
});
|
|
248
226
|
}
|
|
@@ -2974,6 +2952,12 @@ var getTxIsOnProcess = (err) => {
|
|
|
2974
2952
|
const isOnProcess = hasErrorFlagFn(curErrorStrArr, strArr);
|
|
2975
2953
|
return isOnProcess;
|
|
2976
2954
|
};
|
|
2955
|
+
async function isSolanaBalanceZero(connection, userPK) {
|
|
2956
|
+
const balanceLamports = await connection.getBalance(userPK);
|
|
2957
|
+
const balanceSOL = balanceLamports / 1e9;
|
|
2958
|
+
console.log(`Account balance: ${balanceSOL} SOL`);
|
|
2959
|
+
return balanceSOL <= 0;
|
|
2960
|
+
}
|
|
2977
2961
|
|
|
2978
2962
|
// src/config/redPacketIdl.json
|
|
2979
2963
|
var redPacketIdl_default = {
|
|
@@ -5856,6 +5840,13 @@ async function reClaim({
|
|
|
5856
5840
|
console.log("primusZktlsPda:", primusZktlsPda.toBase58());
|
|
5857
5841
|
console.log("reRecordPda:", reRecordPda.toBase58());
|
|
5858
5842
|
const attRecipient = new PublicKey3(attObj.recipient);
|
|
5843
|
+
const isEmptyWallet = await isSolanaBalanceZero(provider.connection, attRecipient);
|
|
5844
|
+
if (isEmptyWallet) {
|
|
5845
|
+
const err = "insufficient";
|
|
5846
|
+
const formatErr = formatErrFn(err);
|
|
5847
|
+
reject(formatErr);
|
|
5848
|
+
return;
|
|
5849
|
+
}
|
|
5859
5850
|
const redEnvelopeState = await redEnvelopeProgram.account.redEnvelopeState.fetch(redEnvelopePda);
|
|
5860
5851
|
console.log("redEnvelopeState.feeRecipient", redEnvelopeState.feeRecipient.toBase58());
|
|
5861
5852
|
const feeRecipient = redEnvelopeState.feeRecipient;
|