@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.mjs CHANGED
@@ -2760,7 +2760,7 @@ import * as anchor3 from "@coral-xyz/anchor";
2760
2760
  import { Program } from "@coral-xyz/anchor";
2761
2761
  import * as anchor from "@coral-xyz/anchor";
2762
2762
  import { PublicKey } from "@solana/web3.js";
2763
- import { getMint } from "@solana/spl-token";
2763
+ import { getMint, TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
2764
2764
  import { encode as encodeBase58 } from "micro-base58";
2765
2765
  import * as borsh from "borsh";
2766
2766
  var { deserialize } = borsh;
@@ -2775,10 +2775,35 @@ var toTokenAmount = (amount, decimals) => {
2775
2775
  const cleaned = raw.replace(/^0+/, "") || "0";
2776
2776
  return new BN2(cleaned);
2777
2777
  };
2778
+ var getTokenProgramType = async (mintAddress, connection) => {
2779
+ if (!connection) {
2780
+ return "";
2781
+ }
2782
+ const mintPubkey = new PublicKey(mintAddress);
2783
+ const accountInfo = await connection.getAccountInfo(mintPubkey);
2784
+ if (!accountInfo) {
2785
+ throw new Error("Mint account not found");
2786
+ }
2787
+ const TOKEN_PROGRAM_ID2 = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
2788
+ const TOKEN_2022_PROGRAM_ID3 = new PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
2789
+ if (accountInfo.owner.equals(TOKEN_PROGRAM_ID2)) {
2790
+ return "Token";
2791
+ } else if (accountInfo.owner.equals(TOKEN_2022_PROGRAM_ID3)) {
2792
+ return "Token-2022";
2793
+ } else {
2794
+ return `Unknown Program: ${accountInfo.owner.toBase58()}`;
2795
+ }
2796
+ };
2778
2797
  async function getTokenDecimals(mintAddress, connection) {
2779
2798
  const mintPubkey = new PublicKey(mintAddress);
2780
- const mintInfo = await getMint(connection, mintPubkey);
2781
- return mintInfo.decimals;
2799
+ const tokenProgramType = await getTokenProgramType(mintAddress, connection);
2800
+ if (tokenProgramType === "Token-2022") {
2801
+ const mintInfo = await getMint(connection, mintPubkey, "confirmed", TOKEN_2022_PROGRAM_ID);
2802
+ return mintInfo.decimals;
2803
+ } else if (tokenProgramType === "Token") {
2804
+ const mintInfo = await getMint(connection, mintPubkey);
2805
+ return mintInfo.decimals;
2806
+ }
2782
2807
  }
2783
2808
  var hexToUint8Array = (hex) => {
2784
2809
  let hexStr = hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -3111,41 +3136,8 @@ var redPacketIdl_default = {
3111
3136
  path: "state"
3112
3137
  },
3113
3138
  {
3114
- kind: "const",
3115
- value: [
3116
- 6,
3117
- 221,
3118
- 246,
3119
- 225,
3120
- 215,
3121
- 101,
3122
- 161,
3123
- 147,
3124
- 217,
3125
- 203,
3126
- 225,
3127
- 70,
3128
- 206,
3129
- 235,
3130
- 121,
3131
- 172,
3132
- 28,
3133
- 180,
3134
- 133,
3135
- 237,
3136
- 95,
3137
- 91,
3138
- 55,
3139
- 145,
3140
- 58,
3141
- 140,
3142
- 245,
3143
- 133,
3144
- 126,
3145
- 255,
3146
- 0,
3147
- 169
3148
- ]
3139
+ kind: "account",
3140
+ path: "token_program"
3149
3141
  },
3150
3142
  {
3151
3143
  kind: "account",
@@ -3202,41 +3194,8 @@ var redPacketIdl_default = {
3202
3194
  path: "att_recipient"
3203
3195
  },
3204
3196
  {
3205
- kind: "const",
3206
- value: [
3207
- 6,
3208
- 221,
3209
- 246,
3210
- 225,
3211
- 215,
3212
- 101,
3213
- 161,
3214
- 147,
3215
- 217,
3216
- 203,
3217
- 225,
3218
- 70,
3219
- 206,
3220
- 235,
3221
- 121,
3222
- 172,
3223
- 28,
3224
- 180,
3225
- 133,
3226
- 237,
3227
- 95,
3228
- 91,
3229
- 55,
3230
- 145,
3231
- 58,
3232
- 140,
3233
- 245,
3234
- 133,
3235
- 126,
3236
- 255,
3237
- 0,
3238
- 169
3239
- ]
3197
+ kind: "account",
3198
+ path: "token_program"
3240
3199
  },
3241
3200
  {
3242
3201
  kind: "account",
@@ -3287,8 +3246,7 @@ var redPacketIdl_default = {
3287
3246
  optional: true
3288
3247
  },
3289
3248
  {
3290
- name: "token_program",
3291
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
3249
+ name: "token_program"
3292
3250
  },
3293
3251
  {
3294
3252
  name: "associated_token_program",
@@ -3434,41 +3392,8 @@ var redPacketIdl_default = {
3434
3392
  path: "sender"
3435
3393
  },
3436
3394
  {
3437
- kind: "const",
3438
- value: [
3439
- 6,
3440
- 221,
3441
- 246,
3442
- 225,
3443
- 215,
3444
- 101,
3445
- 161,
3446
- 147,
3447
- 217,
3448
- 203,
3449
- 225,
3450
- 70,
3451
- 206,
3452
- 235,
3453
- 121,
3454
- 172,
3455
- 28,
3456
- 180,
3457
- 133,
3458
- 237,
3459
- 95,
3460
- 91,
3461
- 55,
3462
- 145,
3463
- 58,
3464
- 140,
3465
- 245,
3466
- 133,
3467
- 126,
3468
- 255,
3469
- 0,
3470
- 169
3471
- ]
3395
+ kind: "account",
3396
+ path: "token_program"
3472
3397
  },
3473
3398
  {
3474
3399
  kind: "account",
@@ -3525,41 +3450,8 @@ var redPacketIdl_default = {
3525
3450
  path: "state"
3526
3451
  },
3527
3452
  {
3528
- kind: "const",
3529
- value: [
3530
- 6,
3531
- 221,
3532
- 246,
3533
- 225,
3534
- 215,
3535
- 101,
3536
- 161,
3537
- 147,
3538
- 217,
3539
- 203,
3540
- 225,
3541
- 70,
3542
- 206,
3543
- 235,
3544
- 121,
3545
- 172,
3546
- 28,
3547
- 180,
3548
- 133,
3549
- 237,
3550
- 95,
3551
- 91,
3552
- 55,
3553
- 145,
3554
- 58,
3555
- 140,
3556
- 245,
3557
- 133,
3558
- 126,
3559
- 255,
3560
- 0,
3561
- 169
3562
- ]
3453
+ kind: "account",
3454
+ path: "token_program"
3563
3455
  },
3564
3456
  {
3565
3457
  kind: "account",
@@ -3610,8 +3502,7 @@ var redPacketIdl_default = {
3610
3502
  optional: true
3611
3503
  },
3612
3504
  {
3613
- name: "token_program",
3614
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
3505
+ name: "token_program"
3615
3506
  },
3616
3507
  {
3617
3508
  name: "associated_token_program",
@@ -3712,41 +3603,8 @@ var redPacketIdl_default = {
3712
3603
  path: "state"
3713
3604
  },
3714
3605
  {
3715
- kind: "const",
3716
- value: [
3717
- 6,
3718
- 221,
3719
- 246,
3720
- 225,
3721
- 215,
3722
- 101,
3723
- 161,
3724
- 147,
3725
- 217,
3726
- 203,
3727
- 225,
3728
- 70,
3729
- 206,
3730
- 235,
3731
- 121,
3732
- 172,
3733
- 28,
3734
- 180,
3735
- 133,
3736
- 237,
3737
- 95,
3738
- 91,
3739
- 55,
3740
- 145,
3741
- 58,
3742
- 140,
3743
- 245,
3744
- 133,
3745
- 126,
3746
- 255,
3747
- 0,
3748
- 169
3749
- ]
3606
+ kind: "account",
3607
+ path: "token_program"
3750
3608
  },
3751
3609
  {
3752
3610
  kind: "account",
@@ -3803,41 +3661,8 @@ var redPacketIdl_default = {
3803
3661
  path: "re_sender"
3804
3662
  },
3805
3663
  {
3806
- kind: "const",
3807
- value: [
3808
- 6,
3809
- 221,
3810
- 246,
3811
- 225,
3812
- 215,
3813
- 101,
3814
- 161,
3815
- 147,
3816
- 217,
3817
- 203,
3818
- 225,
3819
- 70,
3820
- 206,
3821
- 235,
3822
- 121,
3823
- 172,
3824
- 28,
3825
- 180,
3826
- 133,
3827
- 237,
3828
- 95,
3829
- 91,
3830
- 55,
3831
- 145,
3832
- 58,
3833
- 140,
3834
- 245,
3835
- 133,
3836
- 126,
3837
- 255,
3838
- 0,
3839
- 169
3840
- ]
3664
+ kind: "account",
3665
+ path: "token_program"
3841
3666
  },
3842
3667
  {
3843
3668
  kind: "account",
@@ -3888,8 +3713,7 @@ var redPacketIdl_default = {
3888
3713
  optional: true
3889
3714
  },
3890
3715
  {
3891
- name: "token_program",
3892
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
3716
+ name: "token_program"
3893
3717
  },
3894
3718
  {
3895
3719
  name: "associated_token_program",
@@ -4257,236 +4081,246 @@ var redPacketIdl_default = {
4257
4081
  },
4258
4082
  {
4259
4083
  code: 6001,
4084
+ name: "InvalidTokenProgram",
4085
+ msg: "Invalid token program"
4086
+ },
4087
+ {
4088
+ code: 6002,
4260
4089
  name: "InvalidTokenType",
4261
4090
  msg: "Invalid token type"
4262
4091
  },
4263
4092
  {
4264
- code: 6002,
4093
+ code: 6003,
4265
4094
  name: "InvalidREType",
4266
4095
  msg: "Invalid red envelope type"
4267
4096
  },
4268
4097
  {
4269
- code: 6003,
4098
+ code: 6004,
4270
4099
  name: "InvalidNumber",
4271
4100
  msg: "Invalid number"
4272
4101
  },
4273
4102
  {
4274
- code: 6004,
4103
+ code: 6005,
4275
4104
  name: "InvalidEmptyRatio",
4276
4105
  msg: "Invalid empty ratio"
4277
4106
  },
4278
4107
  {
4279
- code: 6005,
4108
+ code: 6006,
4109
+ name: "InvalidRedId",
4110
+ msg: "Invalid red id"
4111
+ },
4112
+ {
4113
+ code: 6007,
4280
4114
  name: "AmountTooLow",
4281
4115
  msg: "Amount too low"
4282
4116
  },
4283
4117
  {
4284
- code: 6006,
4118
+ code: 6008,
4285
4119
  name: "WrongAmount",
4286
4120
  msg: "Wrong amount"
4287
4121
  },
4288
4122
  {
4289
- code: 6007,
4123
+ code: 6009,
4290
4124
  name: "NoReId",
4291
4125
  msg: "Red envelope ID does not exist"
4292
4126
  },
4293
4127
  {
4294
- code: 6008,
4128
+ code: 6010,
4295
4129
  name: "AllClaimed",
4296
4130
  msg: "All envelopes claimed"
4297
4131
  },
4298
4132
  {
4299
- code: 6009,
4133
+ code: 6011,
4300
4134
  name: "UserIdEmpty",
4301
4135
  msg: "User ID empty"
4302
4136
  },
4303
4137
  {
4304
- code: 6010,
4138
+ code: 6012,
4305
4139
  name: "InvalidUserAddress",
4306
4140
  msg: "Invalid User Address"
4307
4141
  },
4308
4142
  {
4309
- code: 6011,
4143
+ code: 6013,
4310
4144
  name: "AlreadyClaimed",
4311
4145
  msg: "Already claimed"
4312
4146
  },
4313
4147
  {
4314
- code: 6012,
4148
+ code: 6014,
4315
4149
  name: "AmountUnderflow",
4316
4150
  msg: "Amount underflow"
4317
4151
  },
4318
4152
  {
4319
- code: 6013,
4153
+ code: 6015,
4320
4154
  name: "InvalidFeeRecipient",
4321
4155
  msg: "Invalid fee recipient"
4322
4156
  },
4323
4157
  {
4324
- code: 6014,
4158
+ code: 6016,
4325
4159
  name: "InvalidStateAccount",
4326
4160
  msg: "Invalid state account"
4327
4161
  },
4328
4162
  {
4329
- code: 6015,
4163
+ code: 6017,
4330
4164
  name: "RecipientIsZero",
4331
4165
  msg: "Recipient cannot be zero"
4332
4166
  },
4333
4167
  {
4334
- code: 6016,
4168
+ code: 6018,
4335
4169
  name: "InvalidCheckType",
4336
4170
  msg: "Invalid checkType"
4337
4171
  },
4338
4172
  {
4339
- code: 6017,
4173
+ code: 6019,
4340
4174
  name: "InvalidCheckParams",
4341
4175
  msg: "CheckParams decode failed"
4342
4176
  },
4343
4177
  {
4344
- code: 6018,
4178
+ code: 6020,
4345
4179
  name: "NoFund",
4346
4180
  msg: "No fund"
4347
4181
  },
4348
4182
  {
4349
- code: 6019,
4183
+ code: 6021,
4350
4184
  name: "NotOwner",
4351
4185
  msg: "Not owner"
4352
4186
  },
4353
4187
  {
4354
- code: 6020,
4188
+ code: 6022,
4355
4189
  name: "NotExpired",
4356
4190
  msg: "Not expired"
4357
4191
  },
4358
4192
  {
4359
- code: 6021,
4193
+ code: 6023,
4360
4194
  name: "UnsupportedTokenType",
4361
4195
  msg: "Unsupported Token Type"
4362
4196
  },
4363
4197
  {
4364
- code: 6022,
4198
+ code: 6024,
4365
4199
  name: "InsufficientSOL",
4366
4200
  msg: "Insufficient SOL"
4367
4201
  },
4368
4202
  {
4369
- code: 6023,
4203
+ code: 6025,
4370
4204
  name: "WrongTokenMint",
4371
4205
  msg: "Wrong token mint"
4372
4206
  },
4373
4207
  {
4374
- code: 6024,
4208
+ code: 6026,
4375
4209
  name: "DeserializationFailed",
4376
4210
  msg: "Deserialization Failed"
4377
4211
  },
4378
4212
  {
4379
- code: 6025,
4213
+ code: 6027,
4380
4214
  name: "JsonParseError",
4381
4215
  msg: "JSON Parse Error"
4382
4216
  },
4383
4217
  {
4384
- code: 6026,
4218
+ code: 6028,
4385
4219
  name: "ResponseLengthError",
4386
4220
  msg: "response length error"
4387
4221
  },
4388
4222
  {
4389
- code: 6027,
4223
+ code: 6029,
4390
4224
  name: "AttUrlError",
4391
4225
  msg: "att url error"
4392
4226
  },
4393
4227
  {
4394
- code: 6028,
4228
+ code: 6030,
4395
4229
  name: "AttSuffixUrlError",
4396
4230
  msg: "att suffix url error"
4397
4231
  },
4398
4232
  {
4399
- code: 6029,
4233
+ code: 6031,
4400
4234
  name: "JsonPathError",
4401
4235
  msg: "json path error"
4402
4236
  },
4403
4237
  {
4404
- code: 6030,
4238
+ code: 6032,
4405
4239
  name: "UsernameKeyError",
4406
4240
  msg: "username key error"
4407
4241
  },
4408
4242
  {
4409
- code: 6031,
4243
+ code: 6033,
4410
4244
  name: "FollowingError",
4411
4245
  msg: "following error"
4412
4246
  },
4413
4247
  {
4414
- code: 6032,
4248
+ code: 6034,
4415
4249
  name: "FollowingNameError",
4416
4250
  msg: "following name error"
4417
4251
  },
4418
4252
  {
4419
- code: 6033,
4253
+ code: 6035,
4420
4254
  name: "NameOpError",
4421
4255
  msg: "name op error"
4422
4256
  },
4423
4257
  {
4424
- code: 6034,
4258
+ code: 6036,
4425
4259
  name: "AttConditionsError",
4426
4260
  msg: "att conditions error"
4427
4261
  },
4428
4262
  {
4429
- code: 6035,
4263
+ code: 6037,
4430
4264
  name: "TooManyUrls",
4431
4265
  msg: "too many urls"
4432
4266
  },
4433
4267
  {
4434
- code: 6036,
4268
+ code: 6038,
4435
4269
  name: "TooManyResponseresolve",
4436
4270
  msg: "too many responseResolve"
4437
4271
  },
4438
4272
  {
4439
- code: 6037,
4273
+ code: 6039,
4440
4274
  name: "UserNameEmpty",
4441
4275
  msg: "user name empty"
4442
4276
  },
4443
4277
  {
4444
- code: 6038,
4278
+ code: 6040,
4445
4279
  name: "SourceError",
4446
4280
  msg: "source error"
4447
4281
  },
4448
4282
  {
4449
- code: 6039,
4283
+ code: 6041,
4450
4284
  name: "AccountResponseLengthError",
4451
4285
  msg: "account response length error"
4452
4286
  },
4453
4287
  {
4454
- code: 6040,
4288
+ code: 6042,
4455
4289
  name: "TiktokAttUrlError",
4456
4290
  msg: "tiktok att url error"
4457
4291
  },
4458
4292
  {
4459
- code: 6041,
4293
+ code: 6043,
4460
4294
  name: "TiktokJsonPathError",
4461
4295
  msg: "tiktok json path error"
4462
4296
  },
4463
4297
  {
4464
- code: 6042,
4298
+ code: 6044,
4465
4299
  name: "XAttUrlError",
4466
4300
  msg: "x att url error"
4467
4301
  },
4468
4302
  {
4469
- code: 6043,
4303
+ code: 6045,
4470
4304
  name: "XJsonPathError",
4471
4305
  msg: "x json path error"
4472
4306
  },
4473
4307
  {
4474
- code: 6044,
4308
+ code: 6046,
4475
4309
  name: "GoogleAttUrlError",
4476
4310
  msg: "google att url error"
4477
4311
  },
4478
4312
  {
4479
- code: 6045,
4313
+ code: 6047,
4480
4314
  name: "GoogleJsonPathError",
4481
4315
  msg: "google json path error"
4482
4316
  },
4483
4317
  {
4484
- code: 6046,
4318
+ code: 6048,
4485
4319
  name: "XiaohongshuAttUrlError",
4486
4320
  msg: "xiaohongshu att url error"
4487
4321
  },
4488
4322
  {
4489
- code: 6047,
4323
+ code: 6049,
4490
4324
  name: "XiaohongshuJsonPathError",
4491
4325
  msg: "xiaohongshu json path error"
4492
4326
  }
@@ -5864,13 +5698,37 @@ function getPrimusRERecordPda({
5864
5698
 
5865
5699
  // src/classes/solana/sdk.ts
5866
5700
  import { utils } from "ethers";
5867
- import { getAssociatedTokenAddress } from "@solana/spl-token";
5701
+ import { getAssociatedTokenAddress, TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2, TOKEN_PROGRAM_ID } from "@solana/spl-token";
5868
5702
  var ERC20_TYPE = 0;
5869
5703
  var CHUNK_SIZE = 960;
5870
5704
  var VERBOSE = 0;
5871
5705
  var RE_USERID_LEN = 8;
5872
5706
  var NATIVETOKENATTBUFFERMAXLEN = 718;
5873
5707
  var ERC20TOKENATTBUFFERMAXLEN = 622;
5708
+ async function getATAAndProgramId(connection, mint, owner, allowOwnerOffCurve = false) {
5709
+ const accountInfo = await connection.getAccountInfo(mint);
5710
+ if (!accountInfo) {
5711
+ throw new Error("Mint account does not exist");
5712
+ }
5713
+ const mintOwner = accountInfo.owner;
5714
+ let tokenProgramId;
5715
+ if (mintOwner.equals(TOKEN_PROGRAM_ID)) {
5716
+ tokenProgramId = TOKEN_PROGRAM_ID;
5717
+ } else if (mintOwner.equals(TOKEN_2022_PROGRAM_ID2)) {
5718
+ tokenProgramId = TOKEN_2022_PROGRAM_ID2;
5719
+ } else {
5720
+ throw new Error(
5721
+ `Unknown mint owner: ${mintOwner.toBase58()}. Not SPL or Token-2022`
5722
+ );
5723
+ }
5724
+ const ata = await getAssociatedTokenAddress(
5725
+ mint,
5726
+ owner,
5727
+ allowOwnerOffCurve,
5728
+ tokenProgramId
5729
+ );
5730
+ return { ata, tokenProgramId };
5731
+ }
5874
5732
  async function waitForTransactionConfirmation(provider, tx, retries = 5, delayMs = 1e3) {
5875
5733
  for (let i = 0; i < retries; i++) {
5876
5734
  const txDetails = await provider.connection.getTransaction(tx, {
@@ -5894,8 +5752,7 @@ async function reSend({
5894
5752
  userKey,
5895
5753
  provider,
5896
5754
  tipToken,
5897
- reSendParam,
5898
- payer = null
5755
+ reSendParam
5899
5756
  }) {
5900
5757
  return new Promise(async (resolve, reject) => {
5901
5758
  let signatureStr;
@@ -5928,10 +5785,19 @@ async function reSend({
5928
5785
  let mint = null;
5929
5786
  let fromTokenAccount = null;
5930
5787
  let toTokenAccount = null;
5788
+ let tokenProgram = TOKEN_PROGRAM_ID;
5931
5789
  if (tipToken.tokenType == ERC20_TYPE) {
5932
5790
  mint = tipToken.tokenAddress;
5933
- fromTokenAccount = await getAssociatedTokenAddress(mint, userKey);
5934
- toTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
5791
+ const from = await getATAAndProgramId(provider.connection, mint, userKey, false);
5792
+ const to = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5793
+ if (from.tokenProgramId != to.tokenProgramId) {
5794
+ throw new Error(
5795
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5796
+ );
5797
+ }
5798
+ fromTokenAccount = from.ata;
5799
+ toTokenAccount = to.ata;
5800
+ tokenProgram = from.tokenProgramId;
5935
5801
  }
5936
5802
  const reSendIx = await redEnvelopeProgram.methods.reSend(Array.from(reId), tipToken, reSendParam).accounts({
5937
5803
  state: redEnvelopePda,
@@ -5941,7 +5807,8 @@ async function reSend({
5941
5807
  // SPL
5942
5808
  fromTokenAccount,
5943
5809
  toTokenAccount,
5944
- mint
5810
+ mint,
5811
+ tokenProgram
5945
5812
  }).instruction();
5946
5813
  const tx = new Transaction().add(createIx).add(reRecordDataInitIx).add(reSendIx);
5947
5814
  tx.feePayer = userKey;
@@ -6024,11 +5891,20 @@ async function reClaim({
6024
5891
  let mint = null;
6025
5892
  let fromTokenAccount = null;
6026
5893
  let toTokenAccount = null;
5894
+ let tokenProgram = TOKEN_PROGRAM_ID;
6027
5895
  if (reRecord.tokenType == ERC20_TYPE) {
6028
5896
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6029
5897
  mint = reRecord.tokenAddress;
6030
- fromTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
6031
- toTokenAccount = await getAssociatedTokenAddress(mint, attRecipient);
5898
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5899
+ const to = await getATAAndProgramId(provider.connection, mint, attRecipient, false);
5900
+ if (from.tokenProgramId != to.tokenProgramId) {
5901
+ throw new Error(
5902
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5903
+ );
5904
+ }
5905
+ fromTokenAccount = from.ata;
5906
+ toTokenAccount = to.ata;
5907
+ tokenProgram = from.tokenProgramId;
6032
5908
  }
6033
5909
  let _att = attObj;
6034
5910
  let _dataBufferKey = null;
@@ -6049,10 +5925,12 @@ async function reClaim({
6049
5925
  // SPL
6050
5926
  fromTokenAccount,
6051
5927
  toTokenAccount,
6052
- mint
5928
+ mint,
5929
+ tokenProgram
6053
5930
  }).transaction();
6054
5931
  tx.feePayer = userKey;
6055
5932
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
5933
+ console.log("UnSigned tx size:", tx.serialize({ requireAllSignatures: false, verifySignatures: false }).length, "bytes");
6056
5934
  const signedTx = await provider.wallet.signTransaction(tx);
6057
5935
  signatureStr = getTxSigStrFromTx(signedTx);
6058
5936
  const isOnChain = await getTxIsOnChain(signatureStr, provider.connection);
@@ -6061,6 +5939,7 @@ async function reClaim({
6061
5939
  return resolve(signatureStr);
6062
5940
  } else {
6063
5941
  const serializeSignedTx = signedTx.serialize();
5942
+ console.log("Signed tx size:", serializeSignedTx.length, "bytes");
6064
5943
  signatureStr = await provider.connection.sendRawTransaction(serializeSignedTx);
6065
5944
  console.log("reClaim done ", signatureStr);
6066
5945
  return resolve(signatureStr);
@@ -6106,11 +5985,20 @@ async function reSenderWithdraw({
6106
5985
  let mint = null;
6107
5986
  let fromTokenAccount = null;
6108
5987
  let toTokenAccount = null;
5988
+ let tokenProgram = TOKEN_PROGRAM_ID;
6109
5989
  if (reRecord.tokenType == ERC20_TYPE) {
6110
5990
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6111
5991
  mint = reRecord.tokenAddress;
6112
- fromTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
6113
- toTokenAccount = await getAssociatedTokenAddress(mint, userKey);
5992
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5993
+ const to = await getATAAndProgramId(provider.connection, mint, userKey, false);
5994
+ if (from.tokenProgramId != to.tokenProgramId) {
5995
+ throw new Error(
5996
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5997
+ );
5998
+ }
5999
+ fromTokenAccount = from.ata;
6000
+ toTokenAccount = to.ata;
6001
+ tokenProgram = from.tokenProgramId;
6114
6002
  }
6115
6003
  tx = await redEnvelopeProgram.methods.reSenderWithdraw(reId).accounts({
6116
6004
  state: redEnvelopePda,
@@ -6119,7 +6007,8 @@ async function reSenderWithdraw({
6119
6007
  // SPL
6120
6008
  fromTokenAccount,
6121
6009
  toTokenAccount,
6122
- mint
6010
+ mint,
6011
+ tokenProgram
6123
6012
  }).transaction();
6124
6013
  tx.feePayer = userKey;
6125
6014
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
@@ -6393,7 +6282,6 @@ var ZktlsSdk = class {
6393
6282
  };
6394
6283
 
6395
6284
  // src/index.ts
6396
- console.log("SUPPORTEDCHAINIDS444", SUPPORTEDCHAINIDS);
6397
6285
  var PrimusFund = class {
6398
6286
  supportedChainIds = SUPPORTEDCHAINIDS;
6399
6287
  supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
@@ -6438,7 +6326,7 @@ var PrimusFund = class {
6438
6326
  } else if (SUPPORTEDSOLANACHAINIDS.includes(chainId)) {
6439
6327
  this.provider = provider;
6440
6328
  this._fundOnSolanaForRedPacket = new FundOnSolanaForRedPacket();
6441
- this._fundOnSolanaForRedPacket.init(provider, chainId);
6329
+ await this._fundOnSolanaForRedPacket.init(provider, chainId);
6442
6330
  }
6443
6331
  if (appId) {
6444
6332
  this._zkTlsSdk = new ZktlsSdk();