@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.
Files changed (3) hide show
  1. package/dist/index.js +161 -275
  2. package/dist/index.mjs +163 -277
  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,241 @@ 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,
4280
4109
  name: "AmountTooLow",
4281
4110
  msg: "Amount too low"
4282
4111
  },
4283
4112
  {
4284
- code: 6006,
4113
+ code: 6007,
4285
4114
  name: "WrongAmount",
4286
4115
  msg: "Wrong amount"
4287
4116
  },
4288
4117
  {
4289
- code: 6007,
4118
+ code: 6008,
4290
4119
  name: "NoReId",
4291
4120
  msg: "Red envelope ID does not exist"
4292
4121
  },
4293
4122
  {
4294
- code: 6008,
4123
+ code: 6009,
4295
4124
  name: "AllClaimed",
4296
4125
  msg: "All envelopes claimed"
4297
4126
  },
4298
4127
  {
4299
- code: 6009,
4128
+ code: 6010,
4300
4129
  name: "UserIdEmpty",
4301
4130
  msg: "User ID empty"
4302
4131
  },
4303
4132
  {
4304
- code: 6010,
4133
+ code: 6011,
4305
4134
  name: "InvalidUserAddress",
4306
4135
  msg: "Invalid User Address"
4307
4136
  },
4308
4137
  {
4309
- code: 6011,
4138
+ code: 6012,
4310
4139
  name: "AlreadyClaimed",
4311
4140
  msg: "Already claimed"
4312
4141
  },
4313
4142
  {
4314
- code: 6012,
4143
+ code: 6013,
4315
4144
  name: "AmountUnderflow",
4316
4145
  msg: "Amount underflow"
4317
4146
  },
4318
4147
  {
4319
- code: 6013,
4148
+ code: 6014,
4320
4149
  name: "InvalidFeeRecipient",
4321
4150
  msg: "Invalid fee recipient"
4322
4151
  },
4323
4152
  {
4324
- code: 6014,
4153
+ code: 6015,
4325
4154
  name: "InvalidStateAccount",
4326
4155
  msg: "Invalid state account"
4327
4156
  },
4328
4157
  {
4329
- code: 6015,
4158
+ code: 6016,
4330
4159
  name: "RecipientIsZero",
4331
4160
  msg: "Recipient cannot be zero"
4332
4161
  },
4333
4162
  {
4334
- code: 6016,
4163
+ code: 6017,
4335
4164
  name: "InvalidCheckType",
4336
4165
  msg: "Invalid checkType"
4337
4166
  },
4338
4167
  {
4339
- code: 6017,
4168
+ code: 6018,
4340
4169
  name: "InvalidCheckParams",
4341
4170
  msg: "CheckParams decode failed"
4342
4171
  },
4343
4172
  {
4344
- code: 6018,
4173
+ code: 6019,
4345
4174
  name: "NoFund",
4346
4175
  msg: "No fund"
4347
4176
  },
4348
4177
  {
4349
- code: 6019,
4178
+ code: 6020,
4350
4179
  name: "NotOwner",
4351
4180
  msg: "Not owner"
4352
4181
  },
4353
4182
  {
4354
- code: 6020,
4183
+ code: 6021,
4355
4184
  name: "NotExpired",
4356
4185
  msg: "Not expired"
4357
4186
  },
4358
4187
  {
4359
- code: 6021,
4188
+ code: 6022,
4360
4189
  name: "UnsupportedTokenType",
4361
4190
  msg: "Unsupported Token Type"
4362
4191
  },
4363
4192
  {
4364
- code: 6022,
4193
+ code: 6023,
4365
4194
  name: "InsufficientSOL",
4366
4195
  msg: "Insufficient SOL"
4367
4196
  },
4368
4197
  {
4369
- code: 6023,
4198
+ code: 6024,
4370
4199
  name: "WrongTokenMint",
4371
4200
  msg: "Wrong token mint"
4372
4201
  },
4373
4202
  {
4374
- code: 6024,
4203
+ code: 6025,
4375
4204
  name: "DeserializationFailed",
4376
4205
  msg: "Deserialization Failed"
4377
4206
  },
4378
4207
  {
4379
- code: 6025,
4208
+ code: 6026,
4380
4209
  name: "JsonParseError",
4381
4210
  msg: "JSON Parse Error"
4382
4211
  },
4383
4212
  {
4384
- code: 6026,
4213
+ code: 6027,
4385
4214
  name: "ResponseLengthError",
4386
4215
  msg: "response length error"
4387
4216
  },
4388
4217
  {
4389
- code: 6027,
4218
+ code: 6028,
4390
4219
  name: "AttUrlError",
4391
4220
  msg: "att url error"
4392
4221
  },
4393
4222
  {
4394
- code: 6028,
4223
+ code: 6029,
4395
4224
  name: "AttSuffixUrlError",
4396
4225
  msg: "att suffix url error"
4397
4226
  },
4398
4227
  {
4399
- code: 6029,
4228
+ code: 6030,
4400
4229
  name: "JsonPathError",
4401
4230
  msg: "json path error"
4402
4231
  },
4403
4232
  {
4404
- code: 6030,
4233
+ code: 6031,
4405
4234
  name: "UsernameKeyError",
4406
4235
  msg: "username key error"
4407
4236
  },
4408
4237
  {
4409
- code: 6031,
4238
+ code: 6032,
4410
4239
  name: "FollowingError",
4411
4240
  msg: "following error"
4412
4241
  },
4413
4242
  {
4414
- code: 6032,
4243
+ code: 6033,
4415
4244
  name: "FollowingNameError",
4416
4245
  msg: "following name error"
4417
4246
  },
4418
4247
  {
4419
- code: 6033,
4248
+ code: 6034,
4420
4249
  name: "NameOpError",
4421
4250
  msg: "name op error"
4422
4251
  },
4423
4252
  {
4424
- code: 6034,
4253
+ code: 6035,
4425
4254
  name: "AttConditionsError",
4426
4255
  msg: "att conditions error"
4427
4256
  },
4428
4257
  {
4429
- code: 6035,
4258
+ code: 6036,
4430
4259
  name: "TooManyUrls",
4431
4260
  msg: "too many urls"
4432
4261
  },
4433
4262
  {
4434
- code: 6036,
4263
+ code: 6037,
4435
4264
  name: "TooManyResponseresolve",
4436
4265
  msg: "too many responseResolve"
4437
4266
  },
4438
4267
  {
4439
- code: 6037,
4268
+ code: 6038,
4440
4269
  name: "UserNameEmpty",
4441
4270
  msg: "user name empty"
4442
4271
  },
4443
4272
  {
4444
- code: 6038,
4273
+ code: 6039,
4445
4274
  name: "SourceError",
4446
4275
  msg: "source error"
4447
4276
  },
4448
4277
  {
4449
- code: 6039,
4278
+ code: 6040,
4450
4279
  name: "AccountResponseLengthError",
4451
4280
  msg: "account response length error"
4452
4281
  },
4453
4282
  {
4454
- code: 6040,
4283
+ code: 6041,
4455
4284
  name: "TiktokAttUrlError",
4456
4285
  msg: "tiktok att url error"
4457
4286
  },
4458
4287
  {
4459
- code: 6041,
4288
+ code: 6042,
4460
4289
  name: "TiktokJsonPathError",
4461
4290
  msg: "tiktok json path error"
4462
4291
  },
4463
4292
  {
4464
- code: 6042,
4293
+ code: 6043,
4465
4294
  name: "XAttUrlError",
4466
4295
  msg: "x att url error"
4467
4296
  },
4468
4297
  {
4469
- code: 6043,
4298
+ code: 6044,
4470
4299
  name: "XJsonPathError",
4471
4300
  msg: "x json path error"
4472
4301
  },
4473
4302
  {
4474
- code: 6044,
4303
+ code: 6045,
4475
4304
  name: "GoogleAttUrlError",
4476
4305
  msg: "google att url error"
4477
4306
  },
4478
4307
  {
4479
- code: 6045,
4308
+ code: 6046,
4480
4309
  name: "GoogleJsonPathError",
4481
4310
  msg: "google json path error"
4482
4311
  },
4483
4312
  {
4484
- code: 6046,
4313
+ code: 6047,
4485
4314
  name: "XiaohongshuAttUrlError",
4486
4315
  msg: "xiaohongshu att url error"
4487
4316
  },
4488
4317
  {
4489
- code: 6047,
4318
+ code: 6048,
4490
4319
  name: "XiaohongshuJsonPathError",
4491
4320
  msg: "xiaohongshu json path error"
4492
4321
  }
@@ -5864,13 +5693,37 @@ function getPrimusRERecordPda({
5864
5693
 
5865
5694
  // src/classes/solana/sdk.ts
5866
5695
  import { utils } from "ethers";
5867
- import { getAssociatedTokenAddress } from "@solana/spl-token";
5696
+ import { getAssociatedTokenAddress, TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2, TOKEN_PROGRAM_ID } from "@solana/spl-token";
5868
5697
  var ERC20_TYPE = 0;
5869
5698
  var CHUNK_SIZE = 960;
5870
5699
  var VERBOSE = 0;
5871
5700
  var RE_USERID_LEN = 8;
5872
5701
  var NATIVETOKENATTBUFFERMAXLEN = 718;
5873
5702
  var ERC20TOKENATTBUFFERMAXLEN = 622;
5703
+ async function getATAAndProgramId(connection, mint, owner, allowOwnerOffCurve = false) {
5704
+ const accountInfo = await connection.getAccountInfo(mint);
5705
+ if (!accountInfo) {
5706
+ throw new Error("Mint account does not exist");
5707
+ }
5708
+ const mintOwner = accountInfo.owner;
5709
+ let tokenProgramId;
5710
+ if (mintOwner.equals(TOKEN_PROGRAM_ID)) {
5711
+ tokenProgramId = TOKEN_PROGRAM_ID;
5712
+ } else if (mintOwner.equals(TOKEN_2022_PROGRAM_ID2)) {
5713
+ tokenProgramId = TOKEN_2022_PROGRAM_ID2;
5714
+ } else {
5715
+ throw new Error(
5716
+ `Unknown mint owner: ${mintOwner.toBase58()}. Not SPL or Token-2022`
5717
+ );
5718
+ }
5719
+ const ata = await getAssociatedTokenAddress(
5720
+ mint,
5721
+ owner,
5722
+ allowOwnerOffCurve,
5723
+ tokenProgramId
5724
+ );
5725
+ return { ata, tokenProgramId };
5726
+ }
5874
5727
  async function waitForTransactionConfirmation(provider, tx, retries = 5, delayMs = 1e3) {
5875
5728
  for (let i = 0; i < retries; i++) {
5876
5729
  const txDetails = await provider.connection.getTransaction(tx, {
@@ -5894,8 +5747,7 @@ async function reSend({
5894
5747
  userKey,
5895
5748
  provider,
5896
5749
  tipToken,
5897
- reSendParam,
5898
- payer = null
5750
+ reSendParam
5899
5751
  }) {
5900
5752
  return new Promise(async (resolve, reject) => {
5901
5753
  let signatureStr;
@@ -5914,10 +5766,12 @@ async function reSend({
5914
5766
  space,
5915
5767
  programId: redEnvelopeProgram.programId
5916
5768
  });
5769
+ debugger;
5917
5770
  const reRecordDataInitIx = await redEnvelopeProgram.methods.reRecordDataInit().accounts({
5918
5771
  reRecordData: spaceAccount.publicKey,
5919
5772
  sender: userKey
5920
5773
  }).signers([spaceAccount]).instruction();
5774
+ debugger;
5921
5775
  const [redEnvelopePda] = getPrimusRedEnvelopePda({ programId: redEnvelopeProgram.programId });
5922
5776
  const redEnvelopeState = await redEnvelopeProgram.account.redEnvelopeState.fetch(redEnvelopePda);
5923
5777
  console.log("idCounter", redEnvelopeState.idCounter.toString());
@@ -5928,11 +5782,21 @@ async function reSend({
5928
5782
  let mint = null;
5929
5783
  let fromTokenAccount = null;
5930
5784
  let toTokenAccount = null;
5785
+ let tokenProgram = TOKEN_PROGRAM_ID;
5931
5786
  if (tipToken.tokenType == ERC20_TYPE) {
5932
5787
  mint = tipToken.tokenAddress;
5933
- fromTokenAccount = await getAssociatedTokenAddress(mint, userKey);
5934
- toTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
5788
+ const from = await getATAAndProgramId(provider.connection, mint, userKey, false);
5789
+ const to = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5790
+ if (from.tokenProgramId != to.tokenProgramId) {
5791
+ throw new Error(
5792
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5793
+ );
5794
+ }
5795
+ fromTokenAccount = from.ata;
5796
+ toTokenAccount = to.ata;
5797
+ tokenProgram = from.tokenProgramId;
5935
5798
  }
5799
+ debugger;
5936
5800
  const reSendIx = await redEnvelopeProgram.methods.reSend(Array.from(reId), tipToken, reSendParam).accounts({
5937
5801
  state: redEnvelopePda,
5938
5802
  reRecord: reRecordPda,
@@ -5941,7 +5805,8 @@ async function reSend({
5941
5805
  // SPL
5942
5806
  fromTokenAccount,
5943
5807
  toTokenAccount,
5944
- mint
5808
+ mint,
5809
+ tokenProgram
5945
5810
  }).instruction();
5946
5811
  const tx = new Transaction().add(createIx).add(reRecordDataInitIx).add(reSendIx);
5947
5812
  tx.feePayer = userKey;
@@ -6000,6 +5865,7 @@ async function reClaim({
6000
5865
  console.log(`attBuffer.length=${attBuffer.length}`);
6001
5866
  let storeInitialized = false;
6002
5867
  let useStoreVersion = false;
5868
+ debugger;
6003
5869
  if (reRecord.tokenType == ERC20_TYPE && attBuffer.length > ERC20TOKENATTBUFFERMAXLEN || reRecord.tokenType != ERC20_TYPE && attBuffer.length > NATIVETOKENATTBUFFERMAXLEN) {
6004
5870
  useStoreVersion = true;
6005
5871
  }
@@ -6024,11 +5890,20 @@ async function reClaim({
6024
5890
  let mint = null;
6025
5891
  let fromTokenAccount = null;
6026
5892
  let toTokenAccount = null;
5893
+ let tokenProgram = TOKEN_PROGRAM_ID;
6027
5894
  if (reRecord.tokenType == ERC20_TYPE) {
6028
5895
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6029
5896
  mint = reRecord.tokenAddress;
6030
- fromTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
6031
- toTokenAccount = await getAssociatedTokenAddress(mint, attRecipient);
5897
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5898
+ const to = await getATAAndProgramId(provider.connection, mint, attRecipient, false);
5899
+ if (from.tokenProgramId != to.tokenProgramId) {
5900
+ throw new Error(
5901
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5902
+ );
5903
+ }
5904
+ fromTokenAccount = from.ata;
5905
+ toTokenAccount = to.ata;
5906
+ tokenProgram = from.tokenProgramId;
6032
5907
  }
6033
5908
  let _att = attObj;
6034
5909
  let _dataBufferKey = null;
@@ -6049,7 +5924,8 @@ async function reClaim({
6049
5924
  // SPL
6050
5925
  fromTokenAccount,
6051
5926
  toTokenAccount,
6052
- mint
5927
+ mint,
5928
+ tokenProgram
6053
5929
  }).transaction();
6054
5930
  tx.feePayer = userKey;
6055
5931
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;
@@ -6106,11 +5982,20 @@ async function reSenderWithdraw({
6106
5982
  let mint = null;
6107
5983
  let fromTokenAccount = null;
6108
5984
  let toTokenAccount = null;
5985
+ let tokenProgram = TOKEN_PROGRAM_ID;
6109
5986
  if (reRecord.tokenType == ERC20_TYPE) {
6110
5987
  console.log("reRecord.tokenAddress:", reRecord.tokenAddress);
6111
5988
  mint = reRecord.tokenAddress;
6112
- fromTokenAccount = await getAssociatedTokenAddress(mint, redEnvelopePda, true);
6113
- toTokenAccount = await getAssociatedTokenAddress(mint, userKey);
5989
+ const from = await getATAAndProgramId(provider.connection, mint, redEnvelopePda, true);
5990
+ const to = await getATAAndProgramId(provider.connection, mint, userKey, false);
5991
+ if (from.tokenProgramId != to.tokenProgramId) {
5992
+ throw new Error(
5993
+ `from.tokenProgramId ${from.tokenProgramId.toBase58()} not equal to.tokenProgramId ${to.tokenProgramId.toBase58()}`
5994
+ );
5995
+ }
5996
+ fromTokenAccount = from.ata;
5997
+ toTokenAccount = to.ata;
5998
+ tokenProgram = from.tokenProgramId;
6114
5999
  }
6115
6000
  tx = await redEnvelopeProgram.methods.reSenderWithdraw(reId).accounts({
6116
6001
  state: redEnvelopePda,
@@ -6119,7 +6004,8 @@ async function reSenderWithdraw({
6119
6004
  // SPL
6120
6005
  fromTokenAccount,
6121
6006
  toTokenAccount,
6122
- mint
6007
+ mint,
6008
+ tokenProgram
6123
6009
  }).transaction();
6124
6010
  tx.feePayer = userKey;
6125
6011
  tx.recentBlockhash = (await provider.connection.getLatestBlockhash()).blockhash;