@drift-labs/sdk 0.2.0-master.40 → 0.2.0-master.41
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/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +5 -11
- package/lib/config.js +1 -1
- package/lib/dlob/DLOB.js +6 -8
- package/lib/driftClient.d.ts +7 -6
- package/lib/driftClient.js +24 -12
- package/lib/events/types.d.ts +3 -1
- package/lib/events/types.js +2 -0
- package/lib/idl/drift.json +164 -28
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.d.ts +2 -0
- package/lib/math/orders.js +10 -3
- package/lib/types.d.ts +125 -46
- package/lib/types.js +61 -23
- package/lib/user.d.ts +2 -0
- package/lib/user.js +11 -1
- package/package.json +2 -2
- package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +5 -11
- package/src/assert/assert.js +9 -0
- package/src/config.ts +1 -1
- package/src/dlob/DLOB.ts +10 -13
- package/src/driftClient.ts +39 -9
- package/src/events/eventList.js +77 -0
- package/src/events/types.ts +6 -0
- package/src/examples/makeTradeExample.js +157 -0
- package/src/idl/drift.json +164 -28
- package/src/math/oracles.ts +1 -1
- package/src/math/orders.ts +9 -4
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/types.ts +104 -37
- package/src/user.ts +18 -1
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/dlob/helpers.ts +19 -10
- package/tests/dlob/test.ts +0 -2
- package/yarn-error.log +3160 -0
package/src/idl/drift.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"name": "state",
|
|
20
|
-
"isMut":
|
|
20
|
+
"isMut": true,
|
|
21
21
|
"isSigner": false
|
|
22
22
|
},
|
|
23
23
|
{
|
|
@@ -773,7 +773,7 @@
|
|
|
773
773
|
},
|
|
774
774
|
{
|
|
775
775
|
"name": "state",
|
|
776
|
-
"isMut":
|
|
776
|
+
"isMut": true,
|
|
777
777
|
"isSigner": false
|
|
778
778
|
},
|
|
779
779
|
{
|
|
@@ -1107,6 +1107,12 @@
|
|
|
1107
1107
|
{
|
|
1108
1108
|
"name": "liquidatorMaxLiabilityTransfer",
|
|
1109
1109
|
"type": "u128"
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
"name": "limitPrice",
|
|
1113
|
+
"type": {
|
|
1114
|
+
"option": "u64"
|
|
1115
|
+
}
|
|
1110
1116
|
}
|
|
1111
1117
|
]
|
|
1112
1118
|
},
|
|
@@ -1156,6 +1162,12 @@
|
|
|
1156
1162
|
{
|
|
1157
1163
|
"name": "liquidatorMaxLiabilityTransfer",
|
|
1158
1164
|
"type": "u128"
|
|
1165
|
+
},
|
|
1166
|
+
{
|
|
1167
|
+
"name": "limitPrice",
|
|
1168
|
+
"type": {
|
|
1169
|
+
"option": "u64"
|
|
1170
|
+
}
|
|
1159
1171
|
}
|
|
1160
1172
|
]
|
|
1161
1173
|
},
|
|
@@ -1205,6 +1217,12 @@
|
|
|
1205
1217
|
{
|
|
1206
1218
|
"name": "liquidatorMaxPnlTransfer",
|
|
1207
1219
|
"type": "u128"
|
|
1220
|
+
},
|
|
1221
|
+
{
|
|
1222
|
+
"name": "limitPrice",
|
|
1223
|
+
"type": {
|
|
1224
|
+
"option": "u64"
|
|
1225
|
+
}
|
|
1208
1226
|
}
|
|
1209
1227
|
]
|
|
1210
1228
|
},
|
|
@@ -3712,7 +3730,7 @@
|
|
|
3712
3730
|
"type": {
|
|
3713
3731
|
"array": [
|
|
3714
3732
|
"u8",
|
|
3715
|
-
|
|
3733
|
+
14
|
|
3716
3734
|
]
|
|
3717
3735
|
}
|
|
3718
3736
|
}
|
|
@@ -3846,7 +3864,7 @@
|
|
|
3846
3864
|
"type": {
|
|
3847
3865
|
"array": [
|
|
3848
3866
|
"u8",
|
|
3849
|
-
|
|
3867
|
+
51
|
|
3850
3868
|
]
|
|
3851
3869
|
}
|
|
3852
3870
|
}
|
|
@@ -3933,6 +3951,14 @@
|
|
|
3933
3951
|
"name": "cumulativeBorrowInterest",
|
|
3934
3952
|
"type": "u128"
|
|
3935
3953
|
},
|
|
3954
|
+
{
|
|
3955
|
+
"name": "totalSocialLoss",
|
|
3956
|
+
"type": "u128"
|
|
3957
|
+
},
|
|
3958
|
+
{
|
|
3959
|
+
"name": "totalQuoteSocialLoss",
|
|
3960
|
+
"type": "u128"
|
|
3961
|
+
},
|
|
3936
3962
|
{
|
|
3937
3963
|
"name": "withdrawGuardThreshold",
|
|
3938
3964
|
"type": "u64"
|
|
@@ -4064,7 +4090,7 @@
|
|
|
4064
4090
|
"type": {
|
|
4065
4091
|
"array": [
|
|
4066
4092
|
"u8",
|
|
4067
|
-
|
|
4093
|
+
86
|
|
4068
4094
|
]
|
|
4069
4095
|
}
|
|
4070
4096
|
}
|
|
@@ -4195,6 +4221,10 @@
|
|
|
4195
4221
|
"name": "numberOfAuthorities",
|
|
4196
4222
|
"type": "u64"
|
|
4197
4223
|
},
|
|
4224
|
+
{
|
|
4225
|
+
"name": "numberOfSubAccounts",
|
|
4226
|
+
"type": "u64"
|
|
4227
|
+
},
|
|
4198
4228
|
{
|
|
4199
4229
|
"name": "lpCooldownTime",
|
|
4200
4230
|
"type": "u64"
|
|
@@ -4242,7 +4272,7 @@
|
|
|
4242
4272
|
"type": {
|
|
4243
4273
|
"array": [
|
|
4244
4274
|
"u8",
|
|
4245
|
-
|
|
4275
|
+
17
|
|
4246
4276
|
]
|
|
4247
4277
|
}
|
|
4248
4278
|
}
|
|
@@ -4316,6 +4346,10 @@
|
|
|
4316
4346
|
"name": "totalWithdraws",
|
|
4317
4347
|
"type": "u64"
|
|
4318
4348
|
},
|
|
4349
|
+
{
|
|
4350
|
+
"name": "totalSocialLoss",
|
|
4351
|
+
"type": "u64"
|
|
4352
|
+
},
|
|
4319
4353
|
{
|
|
4320
4354
|
"name": "settledPerpPnl",
|
|
4321
4355
|
"type": "i64"
|
|
@@ -4328,6 +4362,14 @@
|
|
|
4328
4362
|
"name": "cumulativePerpFunding",
|
|
4329
4363
|
"type": "i64"
|
|
4330
4364
|
},
|
|
4365
|
+
{
|
|
4366
|
+
"name": "liquidationMarginFreed",
|
|
4367
|
+
"type": "u64"
|
|
4368
|
+
},
|
|
4369
|
+
{
|
|
4370
|
+
"name": "liquidationStartTs",
|
|
4371
|
+
"type": "i64"
|
|
4372
|
+
},
|
|
4331
4373
|
{
|
|
4332
4374
|
"name": "nextOrderId",
|
|
4333
4375
|
"type": "u32"
|
|
@@ -4345,12 +4387,10 @@
|
|
|
4345
4387
|
"type": "u16"
|
|
4346
4388
|
},
|
|
4347
4389
|
{
|
|
4348
|
-
"name": "
|
|
4349
|
-
"type":
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
"name": "isBankrupt",
|
|
4353
|
-
"type": "bool"
|
|
4390
|
+
"name": "status",
|
|
4391
|
+
"type": {
|
|
4392
|
+
"defined": "UserStatus"
|
|
4393
|
+
}
|
|
4354
4394
|
},
|
|
4355
4395
|
{
|
|
4356
4396
|
"name": "isMarginTradingEnabled",
|
|
@@ -4361,7 +4401,7 @@
|
|
|
4361
4401
|
"type": {
|
|
4362
4402
|
"array": [
|
|
4363
4403
|
"u8",
|
|
4364
|
-
|
|
4404
|
+
26
|
|
4365
4405
|
]
|
|
4366
4406
|
}
|
|
4367
4407
|
}
|
|
@@ -4424,7 +4464,7 @@
|
|
|
4424
4464
|
"type": "u16"
|
|
4425
4465
|
},
|
|
4426
4466
|
{
|
|
4427
|
-
"name": "
|
|
4467
|
+
"name": "numberOfSubAccountsCreated",
|
|
4428
4468
|
"type": "u16"
|
|
4429
4469
|
},
|
|
4430
4470
|
{
|
|
@@ -4436,7 +4476,7 @@
|
|
|
4436
4476
|
"type": {
|
|
4437
4477
|
"array": [
|
|
4438
4478
|
"u8",
|
|
4439
|
-
|
|
4479
|
+
51
|
|
4440
4480
|
]
|
|
4441
4481
|
}
|
|
4442
4482
|
}
|
|
@@ -4578,6 +4618,10 @@
|
|
|
4578
4618
|
"name": "liquidatorOrderId",
|
|
4579
4619
|
"type": "u32"
|
|
4580
4620
|
},
|
|
4621
|
+
{
|
|
4622
|
+
"name": "liquidatorFee",
|
|
4623
|
+
"type": "u64"
|
|
4624
|
+
},
|
|
4581
4625
|
{
|
|
4582
4626
|
"name": "ifFee",
|
|
4583
4627
|
"type": "u64"
|
|
@@ -5012,8 +5056,8 @@
|
|
|
5012
5056
|
"type": "i128"
|
|
5013
5057
|
},
|
|
5014
5058
|
{
|
|
5015
|
-
"name": "
|
|
5016
|
-
"type": "
|
|
5059
|
+
"name": "totalSocialLoss",
|
|
5060
|
+
"type": "u128"
|
|
5017
5061
|
},
|
|
5018
5062
|
{
|
|
5019
5063
|
"name": "askBaseAssetReserve",
|
|
@@ -5111,6 +5155,10 @@
|
|
|
5111
5155
|
"name": "markStd",
|
|
5112
5156
|
"type": "u64"
|
|
5113
5157
|
},
|
|
5158
|
+
{
|
|
5159
|
+
"name": "oracleStd",
|
|
5160
|
+
"type": "u64"
|
|
5161
|
+
},
|
|
5114
5162
|
{
|
|
5115
5163
|
"name": "lastMarkPriceTwapTs",
|
|
5116
5164
|
"type": "i64"
|
|
@@ -5164,6 +5212,15 @@
|
|
|
5164
5212
|
{
|
|
5165
5213
|
"name": "lastOracleValid",
|
|
5166
5214
|
"type": "bool"
|
|
5215
|
+
},
|
|
5216
|
+
{
|
|
5217
|
+
"name": "padding",
|
|
5218
|
+
"type": {
|
|
5219
|
+
"array": [
|
|
5220
|
+
"u8",
|
|
5221
|
+
48
|
|
5222
|
+
]
|
|
5223
|
+
}
|
|
5167
5224
|
}
|
|
5168
5225
|
]
|
|
5169
5226
|
}
|
|
@@ -5626,10 +5683,6 @@
|
|
|
5626
5683
|
"defined": "OrderTriggerCondition"
|
|
5627
5684
|
}
|
|
5628
5685
|
},
|
|
5629
|
-
{
|
|
5630
|
-
"name": "triggered",
|
|
5631
|
-
"type": "bool"
|
|
5632
|
-
},
|
|
5633
5686
|
{
|
|
5634
5687
|
"name": "auctionDuration",
|
|
5635
5688
|
"type": "u8"
|
|
@@ -5639,7 +5692,7 @@
|
|
|
5639
5692
|
"type": {
|
|
5640
5693
|
"array": [
|
|
5641
5694
|
"u8",
|
|
5642
|
-
|
|
5695
|
+
3
|
|
5643
5696
|
]
|
|
5644
5697
|
}
|
|
5645
5698
|
}
|
|
@@ -5817,16 +5870,30 @@
|
|
|
5817
5870
|
]
|
|
5818
5871
|
}
|
|
5819
5872
|
},
|
|
5873
|
+
{
|
|
5874
|
+
"name": "DepositExplanation",
|
|
5875
|
+
"type": {
|
|
5876
|
+
"kind": "enum",
|
|
5877
|
+
"variants": [
|
|
5878
|
+
{
|
|
5879
|
+
"name": "None"
|
|
5880
|
+
},
|
|
5881
|
+
{
|
|
5882
|
+
"name": "Transfer"
|
|
5883
|
+
}
|
|
5884
|
+
]
|
|
5885
|
+
}
|
|
5886
|
+
},
|
|
5820
5887
|
{
|
|
5821
5888
|
"name": "DepositDirection",
|
|
5822
5889
|
"type": {
|
|
5823
5890
|
"kind": "enum",
|
|
5824
5891
|
"variants": [
|
|
5825
5892
|
{
|
|
5826
|
-
"name": "
|
|
5893
|
+
"name": "Deposit"
|
|
5827
5894
|
},
|
|
5828
5895
|
{
|
|
5829
|
-
"name": "
|
|
5896
|
+
"name": "Withdraw"
|
|
5830
5897
|
}
|
|
5831
5898
|
]
|
|
5832
5899
|
}
|
|
@@ -5875,7 +5942,7 @@
|
|
|
5875
5942
|
"name": "OrderExpired"
|
|
5876
5943
|
},
|
|
5877
5944
|
{
|
|
5878
|
-
"name": "
|
|
5945
|
+
"name": "Liquidation"
|
|
5879
5946
|
},
|
|
5880
5947
|
{
|
|
5881
5948
|
"name": "OrderFilledWithAMM"
|
|
@@ -5891,6 +5958,9 @@
|
|
|
5891
5958
|
},
|
|
5892
5959
|
{
|
|
5893
5960
|
"name": "RiskingIncreasingOrder"
|
|
5961
|
+
},
|
|
5962
|
+
{
|
|
5963
|
+
"name": "OrderFillWithSerum"
|
|
5894
5964
|
}
|
|
5895
5965
|
]
|
|
5896
5966
|
}
|
|
@@ -5938,6 +6008,20 @@
|
|
|
5938
6008
|
]
|
|
5939
6009
|
}
|
|
5940
6010
|
},
|
|
6011
|
+
{
|
|
6012
|
+
"name": "SettlePnlExplanation",
|
|
6013
|
+
"type": {
|
|
6014
|
+
"kind": "enum",
|
|
6015
|
+
"variants": [
|
|
6016
|
+
{
|
|
6017
|
+
"name": "None"
|
|
6018
|
+
},
|
|
6019
|
+
{
|
|
6020
|
+
"name": "ExpiredPosition"
|
|
6021
|
+
}
|
|
6022
|
+
]
|
|
6023
|
+
}
|
|
6024
|
+
},
|
|
5941
6025
|
{
|
|
5942
6026
|
"name": "StakeAction",
|
|
5943
6027
|
"type": {
|
|
@@ -6160,6 +6244,23 @@
|
|
|
6160
6244
|
]
|
|
6161
6245
|
}
|
|
6162
6246
|
},
|
|
6247
|
+
{
|
|
6248
|
+
"name": "UserStatus",
|
|
6249
|
+
"type": {
|
|
6250
|
+
"kind": "enum",
|
|
6251
|
+
"variants": [
|
|
6252
|
+
{
|
|
6253
|
+
"name": "Active"
|
|
6254
|
+
},
|
|
6255
|
+
{
|
|
6256
|
+
"name": "BeingLiquidated"
|
|
6257
|
+
},
|
|
6258
|
+
{
|
|
6259
|
+
"name": "Bankrupt"
|
|
6260
|
+
}
|
|
6261
|
+
]
|
|
6262
|
+
}
|
|
6263
|
+
},
|
|
6163
6264
|
{
|
|
6164
6265
|
"name": "AssetType",
|
|
6165
6266
|
"type": {
|
|
@@ -6224,6 +6325,12 @@
|
|
|
6224
6325
|
},
|
|
6225
6326
|
{
|
|
6226
6327
|
"name": "Below"
|
|
6328
|
+
},
|
|
6329
|
+
{
|
|
6330
|
+
"name": "TriggeredAbove"
|
|
6331
|
+
},
|
|
6332
|
+
{
|
|
6333
|
+
"name": "TriggeredBelow"
|
|
6227
6334
|
}
|
|
6228
6335
|
]
|
|
6229
6336
|
}
|
|
@@ -6359,6 +6466,13 @@
|
|
|
6359
6466
|
"type": "u64",
|
|
6360
6467
|
"index": false
|
|
6361
6468
|
},
|
|
6469
|
+
{
|
|
6470
|
+
"name": "explanation",
|
|
6471
|
+
"type": {
|
|
6472
|
+
"defined": "DepositExplanation"
|
|
6473
|
+
},
|
|
6474
|
+
"index": false
|
|
6475
|
+
},
|
|
6362
6476
|
{
|
|
6363
6477
|
"name": "transferUser",
|
|
6364
6478
|
"type": {
|
|
@@ -6946,6 +7060,11 @@
|
|
|
6946
7060
|
"type": "i128",
|
|
6947
7061
|
"index": false
|
|
6948
7062
|
},
|
|
7063
|
+
{
|
|
7064
|
+
"name": "marginFreed",
|
|
7065
|
+
"type": "u64",
|
|
7066
|
+
"index": false
|
|
7067
|
+
},
|
|
6949
7068
|
{
|
|
6950
7069
|
"name": "liquidationId",
|
|
6951
7070
|
"type": "u16",
|
|
@@ -7049,6 +7168,13 @@
|
|
|
7049
7168
|
"name": "settlePrice",
|
|
7050
7169
|
"type": "i64",
|
|
7051
7170
|
"index": false
|
|
7171
|
+
},
|
|
7172
|
+
{
|
|
7173
|
+
"name": "explanation",
|
|
7174
|
+
"type": {
|
|
7175
|
+
"defined": "SettlePnlExplanation"
|
|
7176
|
+
},
|
|
7177
|
+
"index": false
|
|
7052
7178
|
}
|
|
7053
7179
|
]
|
|
7054
7180
|
},
|
|
@@ -7568,8 +7694,8 @@
|
|
|
7568
7694
|
},
|
|
7569
7695
|
{
|
|
7570
7696
|
"code": 6078,
|
|
7571
|
-
"name": "
|
|
7572
|
-
"msg": "
|
|
7697
|
+
"name": "PerpMarketNotFound",
|
|
7698
|
+
"msg": "PerpMarketNotFound"
|
|
7573
7699
|
},
|
|
7574
7700
|
{
|
|
7575
7701
|
"code": 6079,
|
|
@@ -7578,7 +7704,7 @@
|
|
|
7578
7704
|
},
|
|
7579
7705
|
{
|
|
7580
7706
|
"code": 6080,
|
|
7581
|
-
"name": "
|
|
7707
|
+
"name": "UnableToLoadPerpMarketAccount",
|
|
7582
7708
|
"msg": "UnableToLoadMarketAccount"
|
|
7583
7709
|
},
|
|
7584
7710
|
{
|
|
@@ -8245,6 +8371,16 @@
|
|
|
8245
8371
|
"code": 6213,
|
|
8246
8372
|
"name": "MarketBeingInitialized",
|
|
8247
8373
|
"msg": "Market Being Initialized"
|
|
8374
|
+
},
|
|
8375
|
+
{
|
|
8376
|
+
"code": 6214,
|
|
8377
|
+
"name": "InvalidUserSubAccountId",
|
|
8378
|
+
"msg": "Invalid Sub Account Id"
|
|
8379
|
+
},
|
|
8380
|
+
{
|
|
8381
|
+
"code": 6215,
|
|
8382
|
+
"name": "InvalidTriggerOrderCondition",
|
|
8383
|
+
"msg": "Invalid Trigger Order Condition"
|
|
8248
8384
|
}
|
|
8249
8385
|
]
|
|
8250
8386
|
}
|
package/src/math/oracles.ts
CHANGED
|
@@ -69,7 +69,7 @@ export function isOracleTooDivergent(
|
|
|
69
69
|
amm.historicalOracleData.lastOraclePriceTwapTs
|
|
70
70
|
);
|
|
71
71
|
const sinceStart = BN.max(ZERO, new BN(60 * 5).sub(sinceLastUpdate));
|
|
72
|
-
const oracleTwap5min = amm.historicalOracleData.
|
|
72
|
+
const oracleTwap5min = amm.historicalOracleData.lastOraclePriceTwap5Min
|
|
73
73
|
.mul(sinceStart)
|
|
74
74
|
.add(oraclePriceData.price)
|
|
75
75
|
.mul(sinceLastUpdate)
|
package/src/math/orders.ts
CHANGED
|
@@ -196,10 +196,7 @@ export function calculateBaseAssetAmountForAmmToFulfill(
|
|
|
196
196
|
oraclePriceData: OraclePriceData,
|
|
197
197
|
slot: number
|
|
198
198
|
): BN {
|
|
199
|
-
if (
|
|
200
|
-
isOneOfVariant(order.orderType, ['triggerMarket', 'triggerLimit']) &&
|
|
201
|
-
order.triggered === false
|
|
202
|
-
) {
|
|
199
|
+
if (mustBeTriggered(order) && !isTriggered(order)) {
|
|
203
200
|
return ZERO;
|
|
204
201
|
}
|
|
205
202
|
|
|
@@ -285,3 +282,11 @@ export function isMarketOrder(order: Order): boolean {
|
|
|
285
282
|
export function isLimitOrder(order: Order): boolean {
|
|
286
283
|
return isOneOfVariant(order.orderType, ['limit', 'triggerLimit']);
|
|
287
284
|
}
|
|
285
|
+
|
|
286
|
+
export function mustBeTriggered(order: Order): boolean {
|
|
287
|
+
return isOneOfVariant(order.orderType, ['triggerMarket', 'triggerLimit']);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function isTriggered(order: Order): boolean {
|
|
291
|
+
return isOneOfVariant(order.orderType, ['triggeredAbove', 'triggeredBelow']);
|
|
292
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTokenAccount = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
function parseTokenAccount(data) {
|
|
7
|
+
const accountInfo = spl_token_1.AccountLayout.decode(data);
|
|
8
|
+
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
|
|
9
|
+
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
|
|
10
|
+
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
|
|
11
|
+
if (accountInfo.delegateOption === 0) {
|
|
12
|
+
accountInfo.delegate = null;
|
|
13
|
+
// eslint-disable-next-line new-cap
|
|
14
|
+
accountInfo.delegatedAmount = new spl_token_1.u64(0);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
|
|
18
|
+
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
|
|
19
|
+
}
|
|
20
|
+
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
21
|
+
accountInfo.isFrozen = accountInfo.state === 2;
|
|
22
|
+
if (accountInfo.isNativeOption === 1) {
|
|
23
|
+
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
|
|
24
|
+
accountInfo.isNative = true;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
accountInfo.rentExemptReserve = null;
|
|
28
|
+
accountInfo.isNative = false;
|
|
29
|
+
}
|
|
30
|
+
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
+
accountInfo.closeAuthority = null;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
|
|
35
|
+
}
|
|
36
|
+
return accountInfo;
|
|
37
|
+
}
|
|
38
|
+
exports.parseTokenAccount = parseTokenAccount;
|
package/src/tx/types.js
ADDED
package/src/tx/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapInTx = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const COMPUTE_UNITS_DEFAULT = 200000;
|
|
6
|
+
function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
|
|
7
|
+
) {
|
|
8
|
+
const tx = new web3_js_1.Transaction();
|
|
9
|
+
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
10
|
+
tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
|
|
11
|
+
units: computeUnits,
|
|
12
|
+
additionalFee: 0,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
return tx.add(instruction);
|
|
16
|
+
}
|
|
17
|
+
exports.wrapInTx = wrapInTx;
|