@primuslabs/fund-js-sdk 0.1.16 → 0.1.18

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.
Files changed (3) hide show
  1. package/dist/index.js +165 -277
  2. package/dist/index.mjs +167 -279
  3. 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 mintInfo = await (0, import_spl_token.getMint)(connection, mintPubkey);
2815
- return mintInfo.decimals;
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: "const",
3149
- value: [
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: "const",
3240
- value: [
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: "const",
3472
- value: [
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: "const",
3563
- value: [
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: "const",
3750
- value: [
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: "const",
3841
- value: [
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,246 @@ 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: 6002,
4127
+ code: 6003,
4299
4128
  name: "InvalidREType",
4300
4129
  msg: "Invalid red envelope type"
4301
4130
  },
4302
4131
  {
4303
- code: 6003,
4132
+ code: 6004,
4304
4133
  name: "InvalidNumber",
4305
4134
  msg: "Invalid number"
4306
4135
  },
4307
4136
  {
4308
- code: 6004,
4137
+ code: 6005,
4309
4138
  name: "InvalidEmptyRatio",
4310
4139
  msg: "Invalid empty ratio"
4311
4140
  },
4312
4141
  {
4313
- code: 6005,
4142
+ code: 6006,
4143
+ name: "InvalidRedId",
4144
+ msg: "Invalid red id"
4145
+ },
4146
+ {
4147
+ code: 6007,
4314
4148
  name: "AmountTooLow",
4315
4149
  msg: "Amount too low"
4316
4150
  },
4317
4151
  {
4318
- code: 6006,
4152
+ code: 6008,
4319
4153
  name: "WrongAmount",
4320
4154
  msg: "Wrong amount"
4321
4155
  },
4322
4156
  {
4323
- code: 6007,
4157
+ code: 6009,
4324
4158
  name: "NoReId",
4325
4159
  msg: "Red envelope ID does not exist"
4326
4160
  },
4327
4161
  {
4328
- code: 6008,
4162
+ code: 6010,
4329
4163
  name: "AllClaimed",
4330
4164
  msg: "All envelopes claimed"
4331
4165
  },
4332
4166
  {
4333
- code: 6009,
4167
+ code: 6011,
4334
4168
  name: "UserIdEmpty",
4335
4169
  msg: "User ID empty"
4336
4170
  },
4337
4171
  {
4338
- code: 6010,
4172
+ code: 6012,
4339
4173
  name: "InvalidUserAddress",
4340
4174
  msg: "Invalid User Address"
4341
4175
  },
4342
4176
  {
4343
- code: 6011,
4177
+ code: 6013,
4344
4178
  name: "AlreadyClaimed",
4345
4179
  msg: "Already claimed"
4346
4180
  },
4347
4181
  {
4348
- code: 6012,
4182
+ code: 6014,
4349
4183
  name: "AmountUnderflow",
4350
4184
  msg: "Amount underflow"
4351
4185
  },
4352
4186
  {
4353
- code: 6013,
4187
+ code: 6015,
4354
4188
  name: "InvalidFeeRecipient",
4355
4189
  msg: "Invalid fee recipient"
4356
4190
  },
4357
4191
  {
4358
- code: 6014,
4192
+ code: 6016,
4359
4193
  name: "InvalidStateAccount",
4360
4194
  msg: "Invalid state account"
4361
4195
  },
4362
4196
  {
4363
- code: 6015,
4197
+ code: 6017,
4364
4198
  name: "RecipientIsZero",
4365
4199
  msg: "Recipient cannot be zero"
4366
4200
  },
4367
4201
  {
4368
- code: 6016,
4202
+ code: 6018,
4369
4203
  name: "InvalidCheckType",
4370
4204
  msg: "Invalid checkType"
4371
4205
  },
4372
4206
  {
4373
- code: 6017,
4207
+ code: 6019,
4374
4208
  name: "InvalidCheckParams",
4375
4209
  msg: "CheckParams decode failed"
4376
4210
  },
4377
4211
  {
4378
- code: 6018,
4212
+ code: 6020,
4379
4213
  name: "NoFund",
4380
4214
  msg: "No fund"
4381
4215
  },
4382
4216
  {
4383
- code: 6019,
4217
+ code: 6021,
4384
4218
  name: "NotOwner",
4385
4219
  msg: "Not owner"
4386
4220
  },
4387
4221
  {
4388
- code: 6020,
4222
+ code: 6022,
4389
4223
  name: "NotExpired",
4390
4224
  msg: "Not expired"
4391
4225
  },
4392
4226
  {
4393
- code: 6021,
4227
+ code: 6023,
4394
4228
  name: "UnsupportedTokenType",
4395
4229
  msg: "Unsupported Token Type"
4396
4230
  },
4397
4231
  {
4398
- code: 6022,
4232
+ code: 6024,
4399
4233
  name: "InsufficientSOL",
4400
4234
  msg: "Insufficient SOL"
4401
4235
  },
4402
4236
  {
4403
- code: 6023,
4237
+ code: 6025,
4404
4238
  name: "WrongTokenMint",
4405
4239
  msg: "Wrong token mint"
4406
4240
  },
4407
4241
  {
4408
- code: 6024,
4242
+ code: 6026,
4409
4243
  name: "DeserializationFailed",
4410
4244
  msg: "Deserialization Failed"
4411
4245
  },
4412
4246
  {
4413
- code: 6025,
4247
+ code: 6027,
4414
4248
  name: "JsonParseError",
4415
4249
  msg: "JSON Parse Error"
4416
4250
  },
4417
4251
  {
4418
- code: 6026,
4252
+ code: 6028,
4419
4253
  name: "ResponseLengthError",
4420
4254
  msg: "response length error"
4421
4255
  },
4422
4256
  {
4423
- code: 6027,
4257
+ code: 6029,
4424
4258
  name: "AttUrlError",
4425
4259
  msg: "att url error"
4426
4260
  },
4427
4261
  {
4428
- code: 6028,
4262
+ code: 6030,
4429
4263
  name: "AttSuffixUrlError",
4430
4264
  msg: "att suffix url error"
4431
4265
  },
4432
4266
  {
4433
- code: 6029,
4267
+ code: 6031,
4434
4268
  name: "JsonPathError",
4435
4269
  msg: "json path error"
4436
4270
  },
4437
4271
  {
4438
- code: 6030,
4272
+ code: 6032,
4439
4273
  name: "UsernameKeyError",
4440
4274
  msg: "username key error"
4441
4275
  },
4442
4276
  {
4443
- code: 6031,
4277
+ code: 6033,
4444
4278
  name: "FollowingError",
4445
4279
  msg: "following error"
4446
4280
  },
4447
4281
  {
4448
- code: 6032,
4282
+ code: 6034,
4449
4283
  name: "FollowingNameError",
4450
4284
  msg: "following name error"
4451
4285
  },
4452
4286
  {
4453
- code: 6033,
4287
+ code: 6035,
4454
4288
  name: "NameOpError",
4455
4289
  msg: "name op error"
4456
4290
  },
4457
4291
  {
4458
- code: 6034,
4292
+ code: 6036,
4459
4293
  name: "AttConditionsError",
4460
4294
  msg: "att conditions error"
4461
4295
  },
4462
4296
  {
4463
- code: 6035,
4297
+ code: 6037,
4464
4298
  name: "TooManyUrls",
4465
4299
  msg: "too many urls"
4466
4300
  },
4467
4301
  {
4468
- code: 6036,
4302
+ code: 6038,
4469
4303
  name: "TooManyResponseresolve",
4470
4304
  msg: "too many responseResolve"
4471
4305
  },
4472
4306
  {
4473
- code: 6037,
4307
+ code: 6039,
4474
4308
  name: "UserNameEmpty",
4475
4309
  msg: "user name empty"
4476
4310
  },
4477
4311
  {
4478
- code: 6038,
4312
+ code: 6040,
4479
4313
  name: "SourceError",
4480
4314
  msg: "source error"
4481
4315
  },
4482
4316
  {
4483
- code: 6039,
4317
+ code: 6041,
4484
4318
  name: "AccountResponseLengthError",
4485
4319
  msg: "account response length error"
4486
4320
  },
4487
4321
  {
4488
- code: 6040,
4322
+ code: 6042,
4489
4323
  name: "TiktokAttUrlError",
4490
4324
  msg: "tiktok att url error"
4491
4325
  },
4492
4326
  {
4493
- code: 6041,
4327
+ code: 6043,
4494
4328
  name: "TiktokJsonPathError",
4495
4329
  msg: "tiktok json path error"
4496
4330
  },
4497
4331
  {
4498
- code: 6042,
4332
+ code: 6044,
4499
4333
  name: "XAttUrlError",
4500
4334
  msg: "x att url error"
4501
4335
  },
4502
4336
  {
4503
- code: 6043,
4337
+ code: 6045,
4504
4338
  name: "XJsonPathError",
4505
4339
  msg: "x json path error"
4506
4340
  },
4507
4341
  {
4508
- code: 6044,
4342
+ code: 6046,
4509
4343
  name: "GoogleAttUrlError",
4510
4344
  msg: "google att url error"
4511
4345
  },
4512
4346
  {
4513
- code: 6045,
4347
+ code: 6047,
4514
4348
  name: "GoogleJsonPathError",
4515
4349
  msg: "google json path error"
4516
4350
  },
4517
4351
  {
4518
- code: 6046,
4352
+ code: 6048,
4519
4353
  name: "XiaohongshuAttUrlError",
4520
4354
  msg: "xiaohongshu att url error"
4521
4355
  },
4522
4356
  {
4523
- code: 6047,
4357
+ code: 6049,
4524
4358
  name: "XiaohongshuJsonPathError",
4525
4359
  msg: "xiaohongshu json path error"
4526
4360
  }
@@ -5898,6 +5732,30 @@ var VERBOSE = 0;
5898
5732
  var RE_USERID_LEN = 8;
5899
5733
  var NATIVETOKENATTBUFFERMAXLEN = 718;
5900
5734
  var ERC20TOKENATTBUFFERMAXLEN = 622;
5735
+ async function getATAAndProgramId(connection, mint, owner, allowOwnerOffCurve = false) {
5736
+ const accountInfo = await connection.getAccountInfo(mint);
5737
+ if (!accountInfo) {
5738
+ throw new Error("Mint account does not exist");
5739
+ }
5740
+ const mintOwner = accountInfo.owner;
5741
+ let tokenProgramId;
5742
+ if (mintOwner.equals(import_spl_token2.TOKEN_PROGRAM_ID)) {
5743
+ tokenProgramId = import_spl_token2.TOKEN_PROGRAM_ID;
5744
+ } else if (mintOwner.equals(import_spl_token2.TOKEN_2022_PROGRAM_ID)) {
5745
+ tokenProgramId = import_spl_token2.TOKEN_2022_PROGRAM_ID;
5746
+ } else {
5747
+ throw new Error(
5748
+ `Unknown mint owner: ${mintOwner.toBase58()}. Not SPL or Token-2022`
5749
+ );
5750
+ }
5751
+ const ata = await (0, import_spl_token2.getAssociatedTokenAddress)(
5752
+ mint,
5753
+ owner,
5754
+ allowOwnerOffCurve,
5755
+ tokenProgramId
5756
+ );
5757
+ return { ata, tokenProgramId };
5758
+ }
5901
5759
  async function waitForTransactionConfirmation(provider, tx, retries = 5, delayMs = 1e3) {
5902
5760
  for (let i = 0; i < retries; i++) {
5903
5761
  const txDetails = await provider.connection.getTransaction(tx, {
@@ -5921,8 +5779,7 @@ async function reSend({
5921
5779
  userKey,
5922
5780
  provider,
5923
5781
  tipToken,
5924
- reSendParam,
5925
- payer = null
5782
+ reSendParam
5926
5783
  }) {
5927
5784
  return new Promise(async (resolve, reject) => {
5928
5785
  let signatureStr;
@@ -5955,10 +5812,19 @@ async function reSend({
5955
5812
  let mint = null;
5956
5813
  let fromTokenAccount = null;
5957
5814
  let toTokenAccount = null;
5815
+ let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
5958
5816
  if (tipToken.tokenType == ERC20_TYPE) {
5959
5817
  mint = tipToken.tokenAddress;
5960
- fromTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, userKey);
5961
- toTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, redEnvelopePda, true);
5818
+ const from = await getATAAndProgramId(provider.connection, mint, userKey, false);
5819
+ const to = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5820
+ if (from.tokenProgramId != to.tokenProgramId) {
5821
+ throw new Error(
5822
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5823
+ );
5824
+ }
5825
+ fromTokenAccount = from.ata;
5826
+ toTokenAccount = to.ata;
5827
+ tokenProgram = from.tokenProgramId;
5962
5828
  }
5963
5829
  const reSendIx = await redEnvelopeProgram.methods.reSend(Array.from(reId), tipToken, reSendParam).accounts({
5964
5830
  state: redEnvelopePda,
@@ -5968,7 +5834,8 @@ async function reSend({
5968
5834
  // SPL
5969
5835
  fromTokenAccount,
5970
5836
  toTokenAccount,
5971
- mint
5837
+ mint,
5838
+ tokenProgram
5972
5839
  }).instruction();
5973
5840
  const tx = new import_web33.Transaction().add(createIx).add(reRecordDataInitIx).add(reSendIx);
5974
5841
  tx.feePayer = userKey;
@@ -6051,11 +5918,20 @@ async function reClaim({
6051
5918
  let mint = null;
6052
5919
  let fromTokenAccount = null;
6053
5920
  let toTokenAccount = null;
5921
+ let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
6054
5922
  if (reRecord.tokenType == ERC20_TYPE) {
6055
5923
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6056
5924
  mint = reRecord.tokenAddress;
6057
- fromTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, redEnvelopePda, true);
6058
- toTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, attRecipient);
5925
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5926
+ const to = await getATAAndProgramId(provider.connection, mint, attRecipient, false);
5927
+ if (from.tokenProgramId != to.tokenProgramId) {
5928
+ throw new Error(
5929
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5930
+ );
5931
+ }
5932
+ fromTokenAccount = from.ata;
5933
+ toTokenAccount = to.ata;
5934
+ tokenProgram = from.tokenProgramId;
6059
5935
  }
6060
5936
  let _att = attObj;
6061
5937
  let _dataBufferKey = null;
@@ -6076,10 +5952,12 @@ async function reClaim({
6076
5952
  // SPL
6077
5953
  fromTokenAccount,
6078
5954
  toTokenAccount,
6079
- mint
5955
+ mint,
5956
+ tokenProgram
6080
5957
  }).transaction();
6081
5958
  tx.feePayer = userKey;
6082
5959
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
5960
+ console.log("UnSigned tx size:", tx.serialize({ requireAllSignatures: false, verifySignatures: false }).length, "bytes");
6083
5961
  const signedTx = await provider.wallet.signTransaction(tx);
6084
5962
  signatureStr = getTxSigStrFromTx(signedTx);
6085
5963
  const isOnChain = await getTxIsOnChain(signatureStr, provider.connection);
@@ -6088,6 +5966,7 @@ async function reClaim({
6088
5966
  return resolve(signatureStr);
6089
5967
  } else {
6090
5968
  const serializeSignedTx = signedTx.serialize();
5969
+ console.log("Signed tx size:", serializeSignedTx.length, "bytes");
6091
5970
  signatureStr = await provider.connection.sendRawTransaction(serializeSignedTx);
6092
5971
  console.log("reClaim done ", signatureStr);
6093
5972
  return resolve(signatureStr);
@@ -6133,11 +6012,20 @@ async function reSenderWithdraw({
6133
6012
  let mint = null;
6134
6013
  let fromTokenAccount = null;
6135
6014
  let toTokenAccount = null;
6015
+ let tokenProgram = import_spl_token2.TOKEN_PROGRAM_ID;
6136
6016
  if (reRecord.tokenType == ERC20_TYPE) {
6137
6017
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6138
6018
  mint = reRecord.tokenAddress;
6139
- fromTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, redEnvelopePda, true);
6140
- toTokenAccount = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, userKey);
6019
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
6020
+ const to = await getATAAndProgramId(provider.connection, mint, userKey, false);
6021
+ if (from.tokenProgramId != to.tokenProgramId) {
6022
+ throw new Error(
6023
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
6024
+ );
6025
+ }
6026
+ fromTokenAccount = from.ata;
6027
+ toTokenAccount = to.ata;
6028
+ tokenProgram = from.tokenProgramId;
6141
6029
  }
6142
6030
  tx = await redEnvelopeProgram.methods.reSenderWithdraw(reId).accounts({
6143
6031
  state: redEnvelopePda,
@@ -6146,7 +6034,8 @@ async function reSenderWithdraw({
6146
6034
  // SPL
6147
6035
  fromTokenAccount,
6148
6036
  toTokenAccount,
6149
- mint
6037
+ mint,
6038
+ tokenProgram
6150
6039
  }).transaction();
6151
6040
  tx.feePayer = userKey;
6152
6041
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
@@ -6420,7 +6309,6 @@ var ZktlsSdk = class {
6420
6309
  };
6421
6310
 
6422
6311
  // src/index.ts
6423
- console.log("SUPPORTEDCHAINIDS444", SUPPORTEDCHAINIDS);
6424
6312
  var PrimusFund = class {
6425
6313
  supportedChainIds = SUPPORTEDCHAINIDS;
6426
6314
  supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
@@ -6465,7 +6353,7 @@ var PrimusFund = class {
6465
6353
  } else if (SUPPORTEDSOLANACHAINIDS.includes(chainId)) {
6466
6354
  this.provider = provider;
6467
6355
  this._fundOnSolanaForRedPacket = new FundOnSolanaForRedPacket();
6468
- this._fundOnSolanaForRedPacket.init(provider, chainId);
6356
+ await this._fundOnSolanaForRedPacket.init(provider, chainId);
6469
6357
  }
6470
6358
  if (appId) {
6471
6359
  this._zkTlsSdk = new ZktlsSdk();