@primuslabs/fund-js-sdk 0.1.16 → 0.1.17
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 +161 -275
- package/dist/index.mjs +163 -277
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2809,10 +2809,35 @@ var toTokenAmount = (amount, decimals) => {
|
|
|
2809
2809
|
const cleaned = raw.replace(/^0+/, "") || "0";
|
|
2810
2810
|
return new BN2(cleaned);
|
|
2811
2811
|
};
|
|
2812
|
+
var getTokenProgramType = async (mintAddress, connection) => {
|
|
2813
|
+
if (!connection) {
|
|
2814
|
+
return "";
|
|
2815
|
+
}
|
|
2816
|
+
const mintPubkey = new import_web3.PublicKey(mintAddress);
|
|
2817
|
+
const accountInfo = await connection.getAccountInfo(mintPubkey);
|
|
2818
|
+
if (!accountInfo) {
|
|
2819
|
+
throw new Error("Mint account not found");
|
|
2820
|
+
}
|
|
2821
|
+
const TOKEN_PROGRAM_ID2 = new import_web3.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
2822
|
+
const TOKEN_2022_PROGRAM_ID3 = new import_web3.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
2823
|
+
if (accountInfo.owner.equals(TOKEN_PROGRAM_ID2)) {
|
|
2824
|
+
return "Token";
|
|
2825
|
+
} else if (accountInfo.owner.equals(TOKEN_2022_PROGRAM_ID3)) {
|
|
2826
|
+
return "Token-2022";
|
|
2827
|
+
} else {
|
|
2828
|
+
return `Unknown Program: ${accountInfo.owner.toBase58()}`;
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2812
2831
|
async function getTokenDecimals(mintAddress, connection) {
|
|
2813
2832
|
const mintPubkey = new import_web3.PublicKey(mintAddress);
|
|
2814
|
-
const
|
|
2815
|
-
|
|
2833
|
+
const tokenProgramType = await getTokenProgramType(mintAddress, connection);
|
|
2834
|
+
if (tokenProgramType === "Token-2022") {
|
|
2835
|
+
const mintInfo = await (0, import_spl_token.getMint)(connection, mintPubkey, "confirmed", import_spl_token.TOKEN_2022_PROGRAM_ID);
|
|
2836
|
+
return mintInfo.decimals;
|
|
2837
|
+
} else if (tokenProgramType === "Token") {
|
|
2838
|
+
const mintInfo = await (0, import_spl_token.getMint)(connection, mintPubkey);
|
|
2839
|
+
return mintInfo.decimals;
|
|
2840
|
+
}
|
|
2816
2841
|
}
|
|
2817
2842
|
var hexToUint8Array = (hex) => {
|
|
2818
2843
|
let hexStr = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
@@ -3145,41 +3170,8 @@ var redPacketIdl_default = {
|
|
|
3145
3170
|
path: "state"
|
|
3146
3171
|
},
|
|
3147
3172
|
{
|
|
3148
|
-
kind: "
|
|
3149
|
-
|
|
3150
|
-
6,
|
|
3151
|
-
221,
|
|
3152
|
-
246,
|
|
3153
|
-
225,
|
|
3154
|
-
215,
|
|
3155
|
-
101,
|
|
3156
|
-
161,
|
|
3157
|
-
147,
|
|
3158
|
-
217,
|
|
3159
|
-
203,
|
|
3160
|
-
225,
|
|
3161
|
-
70,
|
|
3162
|
-
206,
|
|
3163
|
-
235,
|
|
3164
|
-
121,
|
|
3165
|
-
172,
|
|
3166
|
-
28,
|
|
3167
|
-
180,
|
|
3168
|
-
133,
|
|
3169
|
-
237,
|
|
3170
|
-
95,
|
|
3171
|
-
91,
|
|
3172
|
-
55,
|
|
3173
|
-
145,
|
|
3174
|
-
58,
|
|
3175
|
-
140,
|
|
3176
|
-
245,
|
|
3177
|
-
133,
|
|
3178
|
-
126,
|
|
3179
|
-
255,
|
|
3180
|
-
0,
|
|
3181
|
-
169
|
|
3182
|
-
]
|
|
3173
|
+
kind: "account",
|
|
3174
|
+
path: "token_program"
|
|
3183
3175
|
},
|
|
3184
3176
|
{
|
|
3185
3177
|
kind: "account",
|
|
@@ -3236,41 +3228,8 @@ var redPacketIdl_default = {
|
|
|
3236
3228
|
path: "att_recipient"
|
|
3237
3229
|
},
|
|
3238
3230
|
{
|
|
3239
|
-
kind: "
|
|
3240
|
-
|
|
3241
|
-
6,
|
|
3242
|
-
221,
|
|
3243
|
-
246,
|
|
3244
|
-
225,
|
|
3245
|
-
215,
|
|
3246
|
-
101,
|
|
3247
|
-
161,
|
|
3248
|
-
147,
|
|
3249
|
-
217,
|
|
3250
|
-
203,
|
|
3251
|
-
225,
|
|
3252
|
-
70,
|
|
3253
|
-
206,
|
|
3254
|
-
235,
|
|
3255
|
-
121,
|
|
3256
|
-
172,
|
|
3257
|
-
28,
|
|
3258
|
-
180,
|
|
3259
|
-
133,
|
|
3260
|
-
237,
|
|
3261
|
-
95,
|
|
3262
|
-
91,
|
|
3263
|
-
55,
|
|
3264
|
-
145,
|
|
3265
|
-
58,
|
|
3266
|
-
140,
|
|
3267
|
-
245,
|
|
3268
|
-
133,
|
|
3269
|
-
126,
|
|
3270
|
-
255,
|
|
3271
|
-
0,
|
|
3272
|
-
169
|
|
3273
|
-
]
|
|
3231
|
+
kind: "account",
|
|
3232
|
+
path: "token_program"
|
|
3274
3233
|
},
|
|
3275
3234
|
{
|
|
3276
3235
|
kind: "account",
|
|
@@ -3321,8 +3280,7 @@ var redPacketIdl_default = {
|
|
|
3321
3280
|
optional: true
|
|
3322
3281
|
},
|
|
3323
3282
|
{
|
|
3324
|
-
name: "token_program"
|
|
3325
|
-
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
3283
|
+
name: "token_program"
|
|
3326
3284
|
},
|
|
3327
3285
|
{
|
|
3328
3286
|
name: "associated_token_program",
|
|
@@ -3468,41 +3426,8 @@ var redPacketIdl_default = {
|
|
|
3468
3426
|
path: "sender"
|
|
3469
3427
|
},
|
|
3470
3428
|
{
|
|
3471
|
-
kind: "
|
|
3472
|
-
|
|
3473
|
-
6,
|
|
3474
|
-
221,
|
|
3475
|
-
246,
|
|
3476
|
-
225,
|
|
3477
|
-
215,
|
|
3478
|
-
101,
|
|
3479
|
-
161,
|
|
3480
|
-
147,
|
|
3481
|
-
217,
|
|
3482
|
-
203,
|
|
3483
|
-
225,
|
|
3484
|
-
70,
|
|
3485
|
-
206,
|
|
3486
|
-
235,
|
|
3487
|
-
121,
|
|
3488
|
-
172,
|
|
3489
|
-
28,
|
|
3490
|
-
180,
|
|
3491
|
-
133,
|
|
3492
|
-
237,
|
|
3493
|
-
95,
|
|
3494
|
-
91,
|
|
3495
|
-
55,
|
|
3496
|
-
145,
|
|
3497
|
-
58,
|
|
3498
|
-
140,
|
|
3499
|
-
245,
|
|
3500
|
-
133,
|
|
3501
|
-
126,
|
|
3502
|
-
255,
|
|
3503
|
-
0,
|
|
3504
|
-
169
|
|
3505
|
-
]
|
|
3429
|
+
kind: "account",
|
|
3430
|
+
path: "token_program"
|
|
3506
3431
|
},
|
|
3507
3432
|
{
|
|
3508
3433
|
kind: "account",
|
|
@@ -3559,41 +3484,8 @@ var redPacketIdl_default = {
|
|
|
3559
3484
|
path: "state"
|
|
3560
3485
|
},
|
|
3561
3486
|
{
|
|
3562
|
-
kind: "
|
|
3563
|
-
|
|
3564
|
-
6,
|
|
3565
|
-
221,
|
|
3566
|
-
246,
|
|
3567
|
-
225,
|
|
3568
|
-
215,
|
|
3569
|
-
101,
|
|
3570
|
-
161,
|
|
3571
|
-
147,
|
|
3572
|
-
217,
|
|
3573
|
-
203,
|
|
3574
|
-
225,
|
|
3575
|
-
70,
|
|
3576
|
-
206,
|
|
3577
|
-
235,
|
|
3578
|
-
121,
|
|
3579
|
-
172,
|
|
3580
|
-
28,
|
|
3581
|
-
180,
|
|
3582
|
-
133,
|
|
3583
|
-
237,
|
|
3584
|
-
95,
|
|
3585
|
-
91,
|
|
3586
|
-
55,
|
|
3587
|
-
145,
|
|
3588
|
-
58,
|
|
3589
|
-
140,
|
|
3590
|
-
245,
|
|
3591
|
-
133,
|
|
3592
|
-
126,
|
|
3593
|
-
255,
|
|
3594
|
-
0,
|
|
3595
|
-
169
|
|
3596
|
-
]
|
|
3487
|
+
kind: "account",
|
|
3488
|
+
path: "token_program"
|
|
3597
3489
|
},
|
|
3598
3490
|
{
|
|
3599
3491
|
kind: "account",
|
|
@@ -3644,8 +3536,7 @@ var redPacketIdl_default = {
|
|
|
3644
3536
|
optional: true
|
|
3645
3537
|
},
|
|
3646
3538
|
{
|
|
3647
|
-
name: "token_program"
|
|
3648
|
-
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
3539
|
+
name: "token_program"
|
|
3649
3540
|
},
|
|
3650
3541
|
{
|
|
3651
3542
|
name: "associated_token_program",
|
|
@@ -3746,41 +3637,8 @@ var redPacketIdl_default = {
|
|
|
3746
3637
|
path: "state"
|
|
3747
3638
|
},
|
|
3748
3639
|
{
|
|
3749
|
-
kind: "
|
|
3750
|
-
|
|
3751
|
-
6,
|
|
3752
|
-
221,
|
|
3753
|
-
246,
|
|
3754
|
-
225,
|
|
3755
|
-
215,
|
|
3756
|
-
101,
|
|
3757
|
-
161,
|
|
3758
|
-
147,
|
|
3759
|
-
217,
|
|
3760
|
-
203,
|
|
3761
|
-
225,
|
|
3762
|
-
70,
|
|
3763
|
-
206,
|
|
3764
|
-
235,
|
|
3765
|
-
121,
|
|
3766
|
-
172,
|
|
3767
|
-
28,
|
|
3768
|
-
180,
|
|
3769
|
-
133,
|
|
3770
|
-
237,
|
|
3771
|
-
95,
|
|
3772
|
-
91,
|
|
3773
|
-
55,
|
|
3774
|
-
145,
|
|
3775
|
-
58,
|
|
3776
|
-
140,
|
|
3777
|
-
245,
|
|
3778
|
-
133,
|
|
3779
|
-
126,
|
|
3780
|
-
255,
|
|
3781
|
-
0,
|
|
3782
|
-
169
|
|
3783
|
-
]
|
|
3640
|
+
kind: "account",
|
|
3641
|
+
path: "token_program"
|
|
3784
3642
|
},
|
|
3785
3643
|
{
|
|
3786
3644
|
kind: "account",
|
|
@@ -3837,41 +3695,8 @@ var redPacketIdl_default = {
|
|
|
3837
3695
|
path: "re_sender"
|
|
3838
3696
|
},
|
|
3839
3697
|
{
|
|
3840
|
-
kind: "
|
|
3841
|
-
|
|
3842
|
-
6,
|
|
3843
|
-
221,
|
|
3844
|
-
246,
|
|
3845
|
-
225,
|
|
3846
|
-
215,
|
|
3847
|
-
101,
|
|
3848
|
-
161,
|
|
3849
|
-
147,
|
|
3850
|
-
217,
|
|
3851
|
-
203,
|
|
3852
|
-
225,
|
|
3853
|
-
70,
|
|
3854
|
-
206,
|
|
3855
|
-
235,
|
|
3856
|
-
121,
|
|
3857
|
-
172,
|
|
3858
|
-
28,
|
|
3859
|
-
180,
|
|
3860
|
-
133,
|
|
3861
|
-
237,
|
|
3862
|
-
95,
|
|
3863
|
-
91,
|
|
3864
|
-
55,
|
|
3865
|
-
145,
|
|
3866
|
-
58,
|
|
3867
|
-
140,
|
|
3868
|
-
245,
|
|
3869
|
-
133,
|
|
3870
|
-
126,
|
|
3871
|
-
255,
|
|
3872
|
-
0,
|
|
3873
|
-
169
|
|
3874
|
-
]
|
|
3698
|
+
kind: "account",
|
|
3699
|
+
path: "token_program"
|
|
3875
3700
|
},
|
|
3876
3701
|
{
|
|
3877
3702
|
kind: "account",
|
|
@@ -3922,8 +3747,7 @@ var redPacketIdl_default = {
|
|
|
3922
3747
|
optional: true
|
|
3923
3748
|
},
|
|
3924
3749
|
{
|
|
3925
|
-
name: "token_program"
|
|
3926
|
-
address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
3750
|
+
name: "token_program"
|
|
3927
3751
|
},
|
|
3928
3752
|
{
|
|
3929
3753
|
name: "associated_token_program",
|
|
@@ -4291,236 +4115,241 @@ var redPacketIdl_default = {
|
|
|
4291
4115
|
},
|
|
4292
4116
|
{
|
|
4293
4117
|
code: 6001,
|
|
4118
|
+
name: "InvalidTokenProgram",
|
|
4119
|
+
msg: "Invalid token program"
|
|
4120
|
+
},
|
|
4121
|
+
{
|
|
4122
|
+
code: 6002,
|
|
4294
4123
|
name: "InvalidTokenType",
|
|
4295
4124
|
msg: "Invalid token type"
|
|
4296
4125
|
},
|
|
4297
4126
|
{
|
|
4298
|
-
code:
|
|
4127
|
+
code: 6003,
|
|
4299
4128
|
name: "InvalidREType",
|
|
4300
4129
|
msg: "Invalid red envelope type"
|
|
4301
4130
|
},
|
|
4302
4131
|
{
|
|
4303
|
-
code:
|
|
4132
|
+
code: 6004,
|
|
4304
4133
|
name: "InvalidNumber",
|
|
4305
4134
|
msg: "Invalid number"
|
|
4306
4135
|
},
|
|
4307
4136
|
{
|
|
4308
|
-
code:
|
|
4137
|
+
code: 6005,
|
|
4309
4138
|
name: "InvalidEmptyRatio",
|
|
4310
4139
|
msg: "Invalid empty ratio"
|
|
4311
4140
|
},
|
|
4312
4141
|
{
|
|
4313
|
-
code:
|
|
4142
|
+
code: 6006,
|
|
4314
4143
|
name: "AmountTooLow",
|
|
4315
4144
|
msg: "Amount too low"
|
|
4316
4145
|
},
|
|
4317
4146
|
{
|
|
4318
|
-
code:
|
|
4147
|
+
code: 6007,
|
|
4319
4148
|
name: "WrongAmount",
|
|
4320
4149
|
msg: "Wrong amount"
|
|
4321
4150
|
},
|
|
4322
4151
|
{
|
|
4323
|
-
code:
|
|
4152
|
+
code: 6008,
|
|
4324
4153
|
name: "NoReId",
|
|
4325
4154
|
msg: "Red envelope ID does not exist"
|
|
4326
4155
|
},
|
|
4327
4156
|
{
|
|
4328
|
-
code:
|
|
4157
|
+
code: 6009,
|
|
4329
4158
|
name: "AllClaimed",
|
|
4330
4159
|
msg: "All envelopes claimed"
|
|
4331
4160
|
},
|
|
4332
4161
|
{
|
|
4333
|
-
code:
|
|
4162
|
+
code: 6010,
|
|
4334
4163
|
name: "UserIdEmpty",
|
|
4335
4164
|
msg: "User ID empty"
|
|
4336
4165
|
},
|
|
4337
4166
|
{
|
|
4338
|
-
code:
|
|
4167
|
+
code: 6011,
|
|
4339
4168
|
name: "InvalidUserAddress",
|
|
4340
4169
|
msg: "Invalid User Address"
|
|
4341
4170
|
},
|
|
4342
4171
|
{
|
|
4343
|
-
code:
|
|
4172
|
+
code: 6012,
|
|
4344
4173
|
name: "AlreadyClaimed",
|
|
4345
4174
|
msg: "Already claimed"
|
|
4346
4175
|
},
|
|
4347
4176
|
{
|
|
4348
|
-
code:
|
|
4177
|
+
code: 6013,
|
|
4349
4178
|
name: "AmountUnderflow",
|
|
4350
4179
|
msg: "Amount underflow"
|
|
4351
4180
|
},
|
|
4352
4181
|
{
|
|
4353
|
-
code:
|
|
4182
|
+
code: 6014,
|
|
4354
4183
|
name: "InvalidFeeRecipient",
|
|
4355
4184
|
msg: "Invalid fee recipient"
|
|
4356
4185
|
},
|
|
4357
4186
|
{
|
|
4358
|
-
code:
|
|
4187
|
+
code: 6015,
|
|
4359
4188
|
name: "InvalidStateAccount",
|
|
4360
4189
|
msg: "Invalid state account"
|
|
4361
4190
|
},
|
|
4362
4191
|
{
|
|
4363
|
-
code:
|
|
4192
|
+
code: 6016,
|
|
4364
4193
|
name: "RecipientIsZero",
|
|
4365
4194
|
msg: "Recipient cannot be zero"
|
|
4366
4195
|
},
|
|
4367
4196
|
{
|
|
4368
|
-
code:
|
|
4197
|
+
code: 6017,
|
|
4369
4198
|
name: "InvalidCheckType",
|
|
4370
4199
|
msg: "Invalid checkType"
|
|
4371
4200
|
},
|
|
4372
4201
|
{
|
|
4373
|
-
code:
|
|
4202
|
+
code: 6018,
|
|
4374
4203
|
name: "InvalidCheckParams",
|
|
4375
4204
|
msg: "CheckParams decode failed"
|
|
4376
4205
|
},
|
|
4377
4206
|
{
|
|
4378
|
-
code:
|
|
4207
|
+
code: 6019,
|
|
4379
4208
|
name: "NoFund",
|
|
4380
4209
|
msg: "No fund"
|
|
4381
4210
|
},
|
|
4382
4211
|
{
|
|
4383
|
-
code:
|
|
4212
|
+
code: 6020,
|
|
4384
4213
|
name: "NotOwner",
|
|
4385
4214
|
msg: "Not owner"
|
|
4386
4215
|
},
|
|
4387
4216
|
{
|
|
4388
|
-
code:
|
|
4217
|
+
code: 6021,
|
|
4389
4218
|
name: "NotExpired",
|
|
4390
4219
|
msg: "Not expired"
|
|
4391
4220
|
},
|
|
4392
4221
|
{
|
|
4393
|
-
code:
|
|
4222
|
+
code: 6022,
|
|
4394
4223
|
name: "UnsupportedTokenType",
|
|
4395
4224
|
msg: "Unsupported Token Type"
|
|
4396
4225
|
},
|
|
4397
4226
|
{
|
|
4398
|
-
code:
|
|
4227
|
+
code: 6023,
|
|
4399
4228
|
name: "InsufficientSOL",
|
|
4400
4229
|
msg: "Insufficient SOL"
|
|
4401
4230
|
},
|
|
4402
4231
|
{
|
|
4403
|
-
code:
|
|
4232
|
+
code: 6024,
|
|
4404
4233
|
name: "WrongTokenMint",
|
|
4405
4234
|
msg: "Wrong token mint"
|
|
4406
4235
|
},
|
|
4407
4236
|
{
|
|
4408
|
-
code:
|
|
4237
|
+
code: 6025,
|
|
4409
4238
|
name: "DeserializationFailed",
|
|
4410
4239
|
msg: "Deserialization Failed"
|
|
4411
4240
|
},
|
|
4412
4241
|
{
|
|
4413
|
-
code:
|
|
4242
|
+
code: 6026,
|
|
4414
4243
|
name: "JsonParseError",
|
|
4415
4244
|
msg: "JSON Parse Error"
|
|
4416
4245
|
},
|
|
4417
4246
|
{
|
|
4418
|
-
code:
|
|
4247
|
+
code: 6027,
|
|
4419
4248
|
name: "ResponseLengthError",
|
|
4420
4249
|
msg: "response length error"
|
|
4421
4250
|
},
|
|
4422
4251
|
{
|
|
4423
|
-
code:
|
|
4252
|
+
code: 6028,
|
|
4424
4253
|
name: "AttUrlError",
|
|
4425
4254
|
msg: "att url error"
|
|
4426
4255
|
},
|
|
4427
4256
|
{
|
|
4428
|
-
code:
|
|
4257
|
+
code: 6029,
|
|
4429
4258
|
name: "AttSuffixUrlError",
|
|
4430
4259
|
msg: "att suffix url error"
|
|
4431
4260
|
},
|
|
4432
4261
|
{
|
|
4433
|
-
code:
|
|
4262
|
+
code: 6030,
|
|
4434
4263
|
name: "JsonPathError",
|
|
4435
4264
|
msg: "json path error"
|
|
4436
4265
|
},
|
|
4437
4266
|
{
|
|
4438
|
-
code:
|
|
4267
|
+
code: 6031,
|
|
4439
4268
|
name: "UsernameKeyError",
|
|
4440
4269
|
msg: "username key error"
|
|
4441
4270
|
},
|
|
4442
4271
|
{
|
|
4443
|
-
code:
|
|
4272
|
+
code: 6032,
|
|
4444
4273
|
name: "FollowingError",
|
|
4445
4274
|
msg: "following error"
|
|
4446
4275
|
},
|
|
4447
4276
|
{
|
|
4448
|
-
code:
|
|
4277
|
+
code: 6033,
|
|
4449
4278
|
name: "FollowingNameError",
|
|
4450
4279
|
msg: "following name error"
|
|
4451
4280
|
},
|
|
4452
4281
|
{
|
|
4453
|
-
code:
|
|
4282
|
+
code: 6034,
|
|
4454
4283
|
name: "NameOpError",
|
|
4455
4284
|
msg: "name op error"
|
|
4456
4285
|
},
|
|
4457
4286
|
{
|
|
4458
|
-
code:
|
|
4287
|
+
code: 6035,
|
|
4459
4288
|
name: "AttConditionsError",
|
|
4460
4289
|
msg: "att conditions error"
|
|
4461
4290
|
},
|
|
4462
4291
|
{
|
|
4463
|
-
code:
|
|
4292
|
+
code: 6036,
|
|
4464
4293
|
name: "TooManyUrls",
|
|
4465
4294
|
msg: "too many urls"
|
|
4466
4295
|
},
|
|
4467
4296
|
{
|
|
4468
|
-
code:
|
|
4297
|
+
code: 6037,
|
|
4469
4298
|
name: "TooManyResponseresolve",
|
|
4470
4299
|
msg: "too many responseResolve"
|
|
4471
4300
|
},
|
|
4472
4301
|
{
|
|
4473
|
-
code:
|
|
4302
|
+
code: 6038,
|
|
4474
4303
|
name: "UserNameEmpty",
|
|
4475
4304
|
msg: "user name empty"
|
|
4476
4305
|
},
|
|
4477
4306
|
{
|
|
4478
|
-
code:
|
|
4307
|
+
code: 6039,
|
|
4479
4308
|
name: "SourceError",
|
|
4480
4309
|
msg: "source error"
|
|
4481
4310
|
},
|
|
4482
4311
|
{
|
|
4483
|
-
code:
|
|
4312
|
+
code: 6040,
|
|
4484
4313
|
name: "AccountResponseLengthError",
|
|
4485
4314
|
msg: "account response length error"
|
|
4486
4315
|
},
|
|
4487
4316
|
{
|
|
4488
|
-
code:
|
|
4317
|
+
code: 6041,
|
|
4489
4318
|
name: "TiktokAttUrlError",
|
|
4490
4319
|
msg: "tiktok att url error"
|
|
4491
4320
|
},
|
|
4492
4321
|
{
|
|
4493
|
-
code:
|
|
4322
|
+
code: 6042,
|
|
4494
4323
|
name: "TiktokJsonPathError",
|
|
4495
4324
|
msg: "tiktok json path error"
|
|
4496
4325
|
},
|
|
4497
4326
|
{
|
|
4498
|
-
code:
|
|
4327
|
+
code: 6043,
|
|
4499
4328
|
name: "XAttUrlError",
|
|
4500
4329
|
msg: "x att url error"
|
|
4501
4330
|
},
|
|
4502
4331
|
{
|
|
4503
|
-
code:
|
|
4332
|
+
code: 6044,
|
|
4504
4333
|
name: "XJsonPathError",
|
|
4505
4334
|
msg: "x json path error"
|
|
4506
4335
|
},
|
|
4507
4336
|
{
|
|
4508
|
-
code:
|
|
4337
|
+
code: 6045,
|
|
4509
4338
|
name: "GoogleAttUrlError",
|
|
4510
4339
|
msg: "google att url error"
|
|
4511
4340
|
},
|
|
4512
4341
|
{
|
|
4513
|
-
code:
|
|
4342
|
+
code: 6046,
|
|
4514
4343
|
name: "GoogleJsonPathError",
|
|
4515
4344
|
msg: "google json path error"
|
|
4516
4345
|
},
|
|
4517
4346
|
{
|
|
4518
|
-
code:
|
|
4347
|
+
code: 6047,
|
|
4519
4348
|
name: "XiaohongshuAttUrlError",
|
|
4520
4349
|
msg: "xiaohongshu att url error"
|
|
4521
4350
|
},
|
|
4522
4351
|
{
|
|
4523
|
-
code:
|
|
4352
|
+
code: 6048,
|
|
4524
4353
|
name: "XiaohongshuJsonPathError",
|
|
4525
4354
|
msg: "xiaohongshu json path error"
|
|
4526
4355
|
}
|
|
@@ -5898,6 +5727,30 @@ var VERBOSE = 0;
|
|
|
5898
5727
|
var RE_USERID_LEN = 8;
|
|
5899
5728
|
var NATIVETOKENATTBUFFERMAXLEN = 718;
|
|
5900
5729
|
var ERC20TOKENATTBUFFERMAXLEN = 622;
|
|
5730
|
+
async function getATAAndProgramId(connection, mint, owner, allowOwnerOffCurve = false) {
|
|
5731
|
+
const accountInfo = await connection.getAccountInfo(mint);
|
|
5732
|
+
if (!accountInfo) {
|
|
5733
|
+
throw new Error("Mint account does not exist");
|
|
5734
|
+
}
|
|
5735
|
+
const mintOwner = accountInfo.owner;
|
|
5736
|
+
let tokenProgramId;
|
|
5737
|
+
if (mintOwner.equals(import_spl_token2.TOKEN_PROGRAM_ID)) {
|
|
5738
|
+
tokenProgramId = import_spl_token2.TOKEN_PROGRAM_ID;
|
|
5739
|
+
} else if (mintOwner.equals(import_spl_token2.TOKEN_2022_PROGRAM_ID)) {
|
|
5740
|
+
tokenProgramId = import_spl_token2.TOKEN_2022_PROGRAM_ID;
|
|
5741
|
+
} else {
|
|
5742
|
+
throw new Error(
|
|
5743
|
+
`Unknown mint owner: ${mintOwner.toBase58()}. Not SPL or Token-2022`
|
|
5744
|
+
);
|
|
5745
|
+
}
|
|
5746
|
+
const ata = await (0, import_spl_token2.getAssociatedTokenAddress)(
|
|
5747
|
+
mint,
|
|
5748
|
+
owner,
|
|
5749
|
+
allowOwnerOffCurve,
|
|
5750
|
+
tokenProgramId
|
|
5751
|
+
);
|
|
5752
|
+
return { ata, tokenProgramId };
|
|
5753
|
+
}
|
|
5901
5754
|
async function waitForTransactionConfirmation(provider, tx, retries = 5, delayMs = 1e3) {
|
|
5902
5755
|
for (let i = 0; i < retries; i++) {
|
|
5903
5756
|
const txDetails = await provider.connection.getTransaction(tx, {
|
|
@@ -5921,8 +5774,7 @@ async function reSend({
|
|
|
5921
5774
|
userKey,
|
|
5922
5775
|
provider,
|
|
5923
5776
|
tipToken,
|
|
5924
|
-
reSendParam
|
|
5925
|
-
payer = null
|
|
5777
|
+
reSendParam
|
|
5926
5778
|
}) {
|
|
5927
5779
|
return new Promise(async (resolve, reject) => {
|
|
5928
5780
|
let signatureStr;
|
|
@@ -5941,10 +5793,12 @@ async function reSend({
|
|
|
5941
5793
|
space,
|
|
5942
5794
|
programId: redEnvelopeProgram.programId
|
|
5943
5795
|
});
|
|
5796
|
+
debugger;
|
|
5944
5797
|
const reRecordDataInitIx = await redEnvelopeProgram.methods.reRecordDataInit().accounts({
|
|
5945
5798
|
reRecordData: spaceAccount.publicKey,
|
|
5946
5799
|
sender: userKey
|
|
5947
5800
|
}).signers([spaceAccount]).instruction();
|
|
5801
|
+
debugger;
|
|
5948
5802
|
const [redEnvelopePda] = getPrimusRedEnvelopePda({ programId: redEnvelopeProgram.programId });
|
|
5949
5803
|
const redEnvelopeState = await redEnvelopeProgram.account.redEnvelopeState.fetch(redEnvelopePda);
|
|
5950
5804
|
console.log("idCounter", redEnvelopeState.idCounter.toString());
|
|
@@ -5955,11 +5809,21 @@ async function reSend({
|
|
|
5955
5809
|
let mint = null;
|
|
5956
5810
|
let fromTokenAccount = null;
|
|
5957
5811
|
let toTokenAccount = null;
|
|
5812
|
+
let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
|
|
5958
5813
|
if (tipToken.tokenType == ERC20_TYPE) {
|
|
5959
5814
|
mint = tipToken.tokenAddress;
|
|
5960
|
-
|
|
5961
|
-
|
|
5815
|
+
const from = await getATAAndProgramId(provider.connection, mint, userKey, false);
|
|
5816
|
+
const to = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
|
|
5817
|
+
if (from.tokenProgramId != to.tokenProgramId) {
|
|
5818
|
+
throw new Error(
|
|
5819
|
+
`from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
|
|
5820
|
+
);
|
|
5821
|
+
}
|
|
5822
|
+
fromTokenAccount = from.ata;
|
|
5823
|
+
toTokenAccount = to.ata;
|
|
5824
|
+
tokenProgram = from.tokenProgramId;
|
|
5962
5825
|
}
|
|
5826
|
+
debugger;
|
|
5963
5827
|
const reSendIx = await redEnvelopeProgram.methods.reSend(Array.from(reId), tipToken, reSendParam).accounts({
|
|
5964
5828
|
state: redEnvelopePda,
|
|
5965
5829
|
reRecord: reRecordPda,
|
|
@@ -5968,7 +5832,8 @@ async function reSend({
|
|
|
5968
5832
|
// SPL
|
|
5969
5833
|
fromTokenAccount,
|
|
5970
5834
|
toTokenAccount,
|
|
5971
|
-
mint
|
|
5835
|
+
mint,
|
|
5836
|
+
tokenProgram
|
|
5972
5837
|
}).instruction();
|
|
5973
5838
|
const tx = new import_web33.Transaction().add(createIx).add(reRecordDataInitIx).add(reSendIx);
|
|
5974
5839
|
tx.feePayer = userKey;
|
|
@@ -6027,6 +5892,7 @@ async function reClaim({
|
|
|
6027
5892
|
console.log(`attBuffer.length=${attBuffer.length}`);
|
|
6028
5893
|
let storeInitialized = false;
|
|
6029
5894
|
let useStoreVersion = false;
|
|
5895
|
+
debugger;
|
|
6030
5896
|
if (reRecord.tokenType == ERC20_TYPE && attBuffer.length > ERC20TOKENATTBUFFERMAXLEN || reRecord.tokenType != ERC20_TYPE && attBuffer.length > NATIVETOKENATTBUFFERMAXLEN) {
|
|
6031
5897
|
useStoreVersion = true;
|
|
6032
5898
|
}
|
|
@@ -6051,11 +5917,20 @@ async function reClaim({
|
|
|
6051
5917
|
let mint = null;
|
|
6052
5918
|
let fromTokenAccount = null;
|
|
6053
5919
|
let toTokenAccount = null;
|
|
5920
|
+
let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
|
|
6054
5921
|
if (reRecord.tokenType == ERC20_TYPE) {
|
|
6055
5922
|
console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
|
|
6056
5923
|
mint = reRecord.tokenAddress;
|
|
6057
|
-
|
|
6058
|
-
|
|
5924
|
+
const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
|
|
5925
|
+
const to = await getATAAndProgramId(provider.connection, mint, attRecipient, false);
|
|
5926
|
+
if (from.tokenProgramId != to.tokenProgramId) {
|
|
5927
|
+
throw new Error(
|
|
5928
|
+
`from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
|
|
5929
|
+
);
|
|
5930
|
+
}
|
|
5931
|
+
fromTokenAccount = from.ata;
|
|
5932
|
+
toTokenAccount = to.ata;
|
|
5933
|
+
tokenProgram = from.tokenProgramId;
|
|
6059
5934
|
}
|
|
6060
5935
|
let _att = attObj;
|
|
6061
5936
|
let _dataBufferKey = null;
|
|
@@ -6076,7 +5951,8 @@ async function reClaim({
|
|
|
6076
5951
|
// SPL
|
|
6077
5952
|
fromTokenAccount,
|
|
6078
5953
|
toTokenAccount,
|
|
6079
|
-
mint
|
|
5954
|
+
mint,
|
|
5955
|
+
tokenProgram
|
|
6080
5956
|
}).transaction();
|
|
6081
5957
|
tx.feePayer = userKey;
|
|
6082
5958
|
tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
|
|
@@ -6133,11 +6009,20 @@ async function reSenderWithdraw({
|
|
|
6133
6009
|
let mint = null;
|
|
6134
6010
|
let fromTokenAccount = null;
|
|
6135
6011
|
let toTokenAccount = null;
|
|
6012
|
+
let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
|
|
6136
6013
|
if (reRecord.tokenType == ERC20_TYPE) {
|
|
6137
6014
|
console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
|
|
6138
6015
|
mint = reRecord.tokenAddress;
|
|
6139
|
-
|
|
6140
|
-
|
|
6016
|
+
const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
|
|
6017
|
+
const to = await getATAAndProgramId(provider.connection, mint, userKey, false);
|
|
6018
|
+
if (from.tokenProgramId != to.tokenProgramId) {
|
|
6019
|
+
throw new Error(
|
|
6020
|
+
`from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
|
|
6021
|
+
);
|
|
6022
|
+
}
|
|
6023
|
+
fromTokenAccount = from.ata;
|
|
6024
|
+
toTokenAccount = to.ata;
|
|
6025
|
+
tokenProgram = from.tokenProgramId;
|
|
6141
6026
|
}
|
|
6142
6027
|
tx = await redEnvelopeProgram.methods.reSenderWithdraw(reId).accounts({
|
|
6143
6028
|
state: redEnvelopePda,
|
|
@@ -6146,7 +6031,8 @@ async function reSenderWithdraw({
|
|
|
6146
6031
|
// SPL
|
|
6147
6032
|
fromTokenAccount,
|
|
6148
6033
|
toTokenAccount,
|
|
6149
|
-
mint
|
|
6034
|
+
mint,
|
|
6035
|
+
tokenProgram
|
|
6150
6036
|
}).transaction();
|
|
6151
6037
|
tx.feePayer = userKey;
|
|
6152
6038
|
tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
|