@jup-ag/lend 0.2.0-beta.1 → 0.2.0-beta.2

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.
@@ -1,8 +1,11 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import { Program } from '@coral-xyz/anchor';
3
- import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
3
+ import { getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
4
+ import { q as getOracleSources } from '../shared/lend.DcHJFKzT.mjs';
4
5
  import { g as getLiquidityProgramId, a as getLiquidity, b as getUserBorrowPosition, c as getUserSupplyPosition, d as getRateModel, e as getReserve } from '../shared/lend.C3XdrR6R.mjs';
5
- import { g as getDex } from '../shared/lend.BC5Y1398.mjs';
6
+ import { g as getDex, a as getDexMetadata } from '../shared/lend.s0kjiHy3.mjs';
7
+ import 'bn.js';
8
+ import '../shared/lend.a53XYkl5.mjs';
6
9
 
7
10
  const address = "jupZ4m2GqUCJ5iueMfzQf8khFfH31d4XAQt3RzCT9Vd";
8
11
  const metadata = {
@@ -613,6 +616,36 @@ const instructions = [
613
616
  ]
614
617
  }
615
618
  },
619
+ {
620
+ name: "dex_metadata",
621
+ writable: true,
622
+ pda: {
623
+ seeds: [
624
+ {
625
+ kind: "const",
626
+ value: [
627
+ 100,
628
+ 101,
629
+ 120,
630
+ 95,
631
+ 109,
632
+ 101,
633
+ 116,
634
+ 97,
635
+ 100,
636
+ 97,
637
+ 116,
638
+ 97
639
+ ]
640
+ },
641
+ {
642
+ kind: "account",
643
+ path: "dex_admin.next_dex_id",
644
+ account: "DexAdmin"
645
+ }
646
+ ]
647
+ }
648
+ },
616
649
  {
617
650
  name: "token_0"
618
651
  },
@@ -691,6 +724,91 @@ const instructions = [
691
724
  }
692
725
  ]
693
726
  },
727
+ {
728
+ name: "init_dex_metadata",
729
+ discriminator: [
730
+ 114,
731
+ 167,
732
+ 144,
733
+ 220,
734
+ 143,
735
+ 73,
736
+ 224,
737
+ 8
738
+ ],
739
+ accounts: [
740
+ {
741
+ name: "authority",
742
+ writable: true,
743
+ signer: true
744
+ },
745
+ {
746
+ name: "dex_admin"
747
+ },
748
+ {
749
+ name: "dex",
750
+ pda: {
751
+ seeds: [
752
+ {
753
+ kind: "const",
754
+ value: [
755
+ 100,
756
+ 101,
757
+ 120
758
+ ]
759
+ },
760
+ {
761
+ kind: "arg",
762
+ path: "dex_id"
763
+ }
764
+ ]
765
+ }
766
+ },
767
+ {
768
+ name: "dex_metadata",
769
+ writable: true,
770
+ pda: {
771
+ seeds: [
772
+ {
773
+ kind: "const",
774
+ value: [
775
+ 100,
776
+ 101,
777
+ 120,
778
+ 95,
779
+ 109,
780
+ 101,
781
+ 116,
782
+ 97,
783
+ 100,
784
+ 97,
785
+ 116,
786
+ 97
787
+ ]
788
+ },
789
+ {
790
+ kind: "arg",
791
+ path: "dex_id"
792
+ }
793
+ ]
794
+ }
795
+ },
796
+ {
797
+ name: "system_program",
798
+ address: "11111111111111111111111111111111"
799
+ }
800
+ ],
801
+ args: [
802
+ {
803
+ name: "dex_id",
804
+ type: "u16"
805
+ },
806
+ {
807
+ name: "lookup_table",
808
+ type: "pubkey"
809
+ }
810
+ ]
811
+ },
694
812
  {
695
813
  name: "init_position",
696
814
  discriminator: [
@@ -2075,6 +2193,45 @@ const instructions = [
2075
2193
  }
2076
2194
  ]
2077
2195
  },
2196
+ {
2197
+ name: "update_dex_lookup_table",
2198
+ discriminator: [
2199
+ 87,
2200
+ 149,
2201
+ 96,
2202
+ 95,
2203
+ 24,
2204
+ 20,
2205
+ 211,
2206
+ 43
2207
+ ],
2208
+ accounts: [
2209
+ {
2210
+ name: "authority",
2211
+ signer: true
2212
+ },
2213
+ {
2214
+ name: "dex_admin"
2215
+ },
2216
+ {
2217
+ name: "dex_metadata",
2218
+ docs: [
2219
+ "@dev Verification inside instruction logic"
2220
+ ],
2221
+ writable: true
2222
+ }
2223
+ ],
2224
+ args: [
2225
+ {
2226
+ name: "dex_id",
2227
+ type: "u16"
2228
+ },
2229
+ {
2230
+ name: "lookup_table",
2231
+ type: "pubkey"
2232
+ }
2233
+ ]
2234
+ },
2078
2235
  {
2079
2236
  name: "update_fee_and_revenue_cut",
2080
2237
  discriminator: [
@@ -2855,6 +3012,19 @@ const accounts = [
2855
3012
  155
2856
3013
  ]
2857
3014
  },
3015
+ {
3016
+ name: "DexMetadata",
3017
+ discriminator: [
3018
+ 177,
3019
+ 231,
3020
+ 57,
3021
+ 253,
3022
+ 64,
3023
+ 12,
3024
+ 205,
3025
+ 37
3026
+ ]
3027
+ },
2858
3028
  {
2859
3029
  name: "DexPosition",
2860
3030
  discriminator: [
@@ -2987,6 +3157,19 @@ const events = [
2987
3157
  132
2988
3158
  ]
2989
3159
  },
3160
+ {
3161
+ name: "LogInitDexMetadata",
3162
+ discriminator: [
3163
+ 53,
3164
+ 61,
3165
+ 248,
3166
+ 111,
3167
+ 245,
3168
+ 219,
3169
+ 167,
3170
+ 73
3171
+ ]
3172
+ },
2990
3173
  {
2991
3174
  name: "LogInitDexPriceParams",
2992
3175
  discriminator: [
@@ -3208,6 +3391,19 @@ const events = [
3208
3391
  17
3209
3392
  ]
3210
3393
  },
3394
+ {
3395
+ name: "LogUpdateDexLookupTable",
3396
+ discriminator: [
3397
+ 135,
3398
+ 31,
3399
+ 232,
3400
+ 96,
3401
+ 2,
3402
+ 64,
3403
+ 116,
3404
+ 229
3405
+ ]
3406
+ },
3211
3407
  {
3212
3408
  name: "LogUpdateFeeAndRevenueCut",
3213
3409
  discriminator: [
@@ -3780,6 +3976,11 @@ const errors = [
3780
3976
  code: 6082,
3781
3977
  name: "DexSwapOutResult",
3782
3978
  msg: "DEX_SWAP_OUT_RESULT"
3979
+ },
3980
+ {
3981
+ code: 6083,
3982
+ name: "DexAdminDexIdMismatch",
3983
+ msg: "DEX_ADMIN_DEX_ID_MISMATCH"
3783
3984
  }
3784
3985
  ];
3785
3986
  const types = [
@@ -4051,6 +4252,31 @@ const types = [
4051
4252
  ]
4052
4253
  }
4053
4254
  },
4255
+ {
4256
+ name: "DexMetadata",
4257
+ type: {
4258
+ kind: "struct",
4259
+ fields: [
4260
+ {
4261
+ name: "dex_id",
4262
+ type: "u16"
4263
+ },
4264
+ {
4265
+ name: "lookup_table",
4266
+ type: "pubkey"
4267
+ },
4268
+ {
4269
+ name: "_reserved",
4270
+ type: {
4271
+ array: [
4272
+ "u8",
4273
+ 32
4274
+ ]
4275
+ }
4276
+ }
4277
+ ]
4278
+ }
4279
+ },
4054
4280
  {
4055
4281
  name: "DexPosition",
4056
4282
  docs: [
@@ -4411,6 +4637,22 @@ const types = [
4411
4637
  ]
4412
4638
  }
4413
4639
  },
4640
+ {
4641
+ name: "LogInitDexMetadata",
4642
+ type: {
4643
+ kind: "struct",
4644
+ fields: [
4645
+ {
4646
+ name: "dex_id",
4647
+ type: "u16"
4648
+ },
4649
+ {
4650
+ name: "lookup_table",
4651
+ type: "pubkey"
4652
+ }
4653
+ ]
4654
+ }
4655
+ },
4414
4656
  {
4415
4657
  name: "LogInitDexPriceParams",
4416
4658
  type: {
@@ -4777,6 +5019,22 @@ const types = [
4777
5019
  ]
4778
5020
  }
4779
5021
  },
5022
+ {
5023
+ name: "LogUpdateDexLookupTable",
5024
+ type: {
5025
+ kind: "struct",
5026
+ fields: [
5027
+ {
5028
+ name: "dex_id",
5029
+ type: "u16"
5030
+ },
5031
+ {
5032
+ name: "lookup_table",
5033
+ type: "pubkey"
5034
+ }
5035
+ ]
5036
+ }
5037
+ },
4780
5038
  {
4781
5039
  name: "LogUpdateFeeAndRevenueCut",
4782
5040
  type: {
@@ -5338,7 +5596,6 @@ const getAccountOwner = async (account, connection) => {
5338
5596
  throw new Error(`Account info not found for ${account.toString()}`);
5339
5597
  return info.owner;
5340
5598
  };
5341
- const decodeBool = (v) => Number(v) === 1;
5342
5599
 
5343
5600
  const getDexProgram = ({
5344
5601
  connection,
@@ -5350,6 +5607,12 @@ const getDexProgram = ({
5350
5607
  publicKey: signer
5351
5608
  });
5352
5609
  };
5610
+ async function resolveDexMetadata(dexId, connection) {
5611
+ const dex2 = getDexMetadata(dexId);
5612
+ const program = getDexProgram({ connection });
5613
+ const dexMetadata = await program.account.dexMetadata.fetch(dex2);
5614
+ return dexMetadata;
5615
+ }
5353
5616
  async function resolvePool(dexId, connection) {
5354
5617
  const dex2 = getDex(dexId);
5355
5618
  const program = getDexProgram({ connection });
@@ -5368,8 +5631,8 @@ async function resolvePool(dexId, connection) {
5368
5631
  token1,
5369
5632
  token0Program,
5370
5633
  token1Program,
5371
- smartCol: decodeBool(dexAccount.isSmartCollateralEnabled),
5372
- smartDebt: decodeBool(dexAccount.isSmartDebtEnabled),
5634
+ smartCol: dexAccount.isSmartCollateralEnabled === 1,
5635
+ smartDebt: dexAccount.isSmartDebtEnabled === 1,
5373
5636
  centerPriceAddress: dexAccount.centerPriceAddress,
5374
5637
  liquidity: liquidity$1,
5375
5638
  token0Reserve: getReserve(token0, "main"),
@@ -5395,17 +5658,62 @@ async function resolvePool(dexId, connection) {
5395
5658
  };
5396
5659
  return resolved;
5397
5660
  }
5398
- const getSwapAccounts = async (params) => {
5661
+ async function getCenterPriceRemainingAccounts({
5662
+ connection,
5663
+ oracle
5664
+ }) {
5665
+ if (oracle.equals(PublicKey.default)) {
5666
+ return [];
5667
+ }
5668
+ const accounts = [
5669
+ oracle,
5670
+ // 0th accounts is center price address
5671
+ ...// rest of the accounts are oracle sources
5672
+ (await getOracleSources({
5673
+ connection,
5674
+ oracle
5675
+ })).map((s) => s.source)
5676
+ ];
5677
+ return accounts.map((a) => ({
5678
+ pubkey: a,
5679
+ isWritable: false,
5680
+ isSigner: false
5681
+ }));
5682
+ }
5683
+ const getSwapContext = async (params) => {
5399
5684
  const { signer, recipient, connection, dexId } = params;
5400
- const pool = await resolvePool(dexId, connection);
5401
- return {
5685
+ const [pool, dexMetadata] = await Promise.all([
5686
+ resolvePool(dexId, connection),
5687
+ resolveDexMetadata(dexId, connection)
5688
+ ]);
5689
+ const accounts = {
5402
5690
  signer,
5403
5691
  dex: pool.dex,
5404
- userToken0Account: getAssociatedTokenAddressSync(pool.token0, signer, true, pool.token0Program),
5405
- userToken1Account: getAssociatedTokenAddressSync(pool.token1, signer, true, pool.token1Program),
5692
+ userToken0Account: getAssociatedTokenAddressSync(
5693
+ pool.token0,
5694
+ signer,
5695
+ true,
5696
+ pool.token0Program
5697
+ ),
5698
+ userToken1Account: getAssociatedTokenAddressSync(
5699
+ pool.token1,
5700
+ signer,
5701
+ true,
5702
+ pool.token1Program
5703
+ ),
5406
5704
  recipient,
5407
- recipientToken0Account: getAssociatedTokenAddressSync(pool.token0, recipient ?? signer, true, pool.token0Program),
5408
- recipientToken1Account: getAssociatedTokenAddressSync(pool.token1, recipient ?? signer, true, pool.token1Program),
5705
+ recipientToken0Account: getAssociatedTokenAddressSync(
5706
+ pool.token0,
5707
+ recipient ?? signer,
5708
+ true,
5709
+ pool.token0Program
5710
+ ),
5711
+ recipientToken1Account: getAssociatedTokenAddressSync(
5712
+ pool.token1,
5713
+ recipient ?? signer,
5714
+ true,
5715
+ pool.token1Program
5716
+ ),
5409
5717
  token0: pool.token0,
5410
5718
  token1: pool.token1,
5411
5719
  token0Reserve: pool.token0Reserve,
@@ -5425,36 +5733,57 @@ const getSwapAccounts = async (params) => {
5425
5733
  oracleProgram: new PublicKey("jupnw4B6Eqs7ft6rxpzYLJZYSnrpRgPcr589n5Kv4oc"),
5426
5734
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID
5427
5735
  };
5736
+ const centerPriceRemainingAccounts = await getCenterPriceRemainingAccounts({
5737
+ connection,
5738
+ oracle: pool.centerPriceAddress
5739
+ });
5740
+ return {
5741
+ accounts,
5742
+ remainingAccounts: [...centerPriceRemainingAccounts],
5743
+ lookupTable: dexMetadata.lookupTable
5744
+ };
5428
5745
  };
5429
- async function swapIn(params) {
5430
- const { connection, signer, swap0to1, amountIn, amountOutMin, centerPriceRemainingAccounts } = params;
5746
+ async function getSwapInIx(params) {
5747
+ const { connection, signer, swap0to1, amountIn, amountOutMin } = params;
5431
5748
  const program = getDexProgram({ connection, signer });
5432
- const ix = await program.methods.swapIn(swap0to1, amountIn, amountOutMin).accountsPartial(await getSwapAccounts({
5749
+ const { accounts, remainingAccounts, lookupTable } = await getSwapContext({
5433
5750
  dexId: params.dexId,
5434
5751
  connection: params.connection,
5435
5752
  signer: params.signer,
5436
5753
  recipient: params.recipient
5437
- })).remainingAccounts(
5438
- (centerPriceRemainingAccounts || []).map((a) => ({ pubkey: a, isSigner: false, isWritable: false }))
5439
- ).instruction();
5754
+ });
5755
+ const [ix, addressLookupTable] = await Promise.all([
5756
+ program.methods.swapIn(swap0to1, amountIn, amountOutMin).accountsPartial(accounts).remainingAccounts(remainingAccounts).instruction(),
5757
+ connection.getAddressLookupTable(lookupTable)
5758
+ ]);
5440
5759
  return {
5441
- ixs: [ix]
5760
+ ixs: [ix],
5761
+ accounts,
5762
+ remainingAccounts,
5763
+ addressLookupTableAddresses: lookupTable ? [lookupTable] : [],
5764
+ addressLookupTableAccounts: addressLookupTable.value ? [addressLookupTable.value] : []
5442
5765
  };
5443
5766
  }
5444
- async function swapOut(params) {
5445
- const { connection, signer, swap0to1, amountIn, amountInMax, centerPriceRemainingAccounts } = params;
5767
+ async function getSwapOutIx(params) {
5768
+ const { connection, signer, swap0to1, amountOut, amountInMax } = params;
5446
5769
  const program = getDexProgram({ connection, signer });
5447
- const ix = await program.methods.swapIn(swap0to1, amountIn, amountInMax).accountsPartial(await getSwapAccounts({
5770
+ const { accounts, remainingAccounts, lookupTable } = await getSwapContext({
5448
5771
  dexId: params.dexId,
5449
5772
  connection: params.connection,
5450
5773
  signer: params.signer,
5451
5774
  recipient: params.recipient
5452
- })).remainingAccounts(
5453
- (centerPriceRemainingAccounts || []).map((a) => ({ pubkey: a, isSigner: false, isWritable: false }))
5454
- ).instruction();
5775
+ });
5776
+ const [ix, addressLookupTable] = await Promise.all([
5777
+ program.methods.swapOut(swap0to1, amountOut, amountInMax).accountsPartial(accounts).remainingAccounts(remainingAccounts).instruction(),
5778
+ connection.getAddressLookupTable(lookupTable)
5779
+ ]);
5455
5780
  return {
5456
- ixs: [ix]
5781
+ ixs: [ix],
5782
+ accounts,
5783
+ remainingAccounts,
5784
+ addressLookupTableAddresses: lookupTable ? [lookupTable] : [],
5785
+ addressLookupTableAccounts: addressLookupTable.value ? [addressLookupTable.value] : []
5457
5786
  };
5458
5787
  }
5459
5788
 
5460
- export { getDexProgram, swapIn, swapOut };
5789
+ export { getDexProgram, getSwapInIx, getSwapOutIx };
package/dist/index.d.mts CHANGED
@@ -119,11 +119,14 @@ declare namespace borrow {
119
119
  }
120
120
 
121
121
  declare const getDex: (dexId: number) => PublicKey;
122
+ declare const getDexMetadata: (dexId: number) => PublicKey;
122
123
 
123
124
  declare const dex_getDex: typeof getDex;
125
+ declare const dex_getDexMetadata: typeof getDexMetadata;
124
126
  declare namespace dex {
125
127
  export {
126
128
  dex_getDex as getDex,
129
+ dex_getDexMetadata as getDexMetadata,
127
130
  };
128
131
  }
129
132
 
package/dist/index.d.ts CHANGED
@@ -119,11 +119,14 @@ declare namespace borrow {
119
119
  }
120
120
 
121
121
  declare const getDex: (dexId: number) => PublicKey;
122
+ declare const getDexMetadata: (dexId: number) => PublicKey;
122
123
 
123
124
  declare const dex_getDex: typeof getDex;
125
+ declare const dex_getDexMetadata: typeof getDexMetadata;
124
126
  declare namespace dex {
125
127
  export {
126
128
  dex_getDex as getDex,
129
+ dex_getDexMetadata as getDexMetadata,
127
130
  };
128
131
  }
129
132
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { b as borrowPda } from './shared/lend.ByiEG4eI.mjs';
2
- export { d as dexPda } from './shared/lend.BC5Y1398.mjs';
1
+ export { b as borrowPda } from './shared/lend.a53XYkl5.mjs';
2
+ export { d as dexPda } from './shared/lend.s0kjiHy3.mjs';
3
3
  export { f as flashloanPda } from './shared/lend.BXNM1zms.mjs';
4
4
  export { l as lendingPda, e as lendingRewardRateModelPda } from './shared/lend.BQkL9C4i.mjs';
5
5
  export { l as liquidityPda } from './shared/lend.C3XdrR6R.mjs';
@@ -8,6 +8,6 @@ import '@solana/web3.js';
8
8
  import '@solana/spl-token';
9
9
  import 'bn.js';
10
10
 
11
- const version = "0.2.0-beta.1";
11
+ const version = "0.2.0-beta.2";
12
12
 
13
13
  export { version };
@@ -1,9 +1,10 @@
1
- import { v as getOperateIx, F as vaultsIdl } from '../shared/lend.CTcB5yyK.mjs';
1
+ import { A as vaultsIdl } from '../shared/lend.DcHJFKzT.mjs';
2
+ import { e as getOperateIx } from '../shared/lend.siYu8A-9.mjs';
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  import { Program } from '@coral-xyz/anchor';
4
5
  import 'bn.js';
6
+ import '../shared/lend.a53XYkl5.mjs';
5
7
  import '@solana/spl-token';
6
- import '../shared/lend.ByiEG4eI.mjs';
7
8
  import '../shared/lend.C3XdrR6R.mjs';
8
9
 
9
10
  const address = "jup8QcdtqecBGw1iXHW3hQAsHQbTgEqbLbNMvvULmeK";