@glamsystems/glam-sdk 0.1.25 → 0.1.26
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/index.cjs.js +1408 -520
- package/index.esm.js +1404 -517
- package/package.json +1 -1
- package/src/client/assets.d.ts +7 -4
- package/src/client/base.d.ts +0 -1
- package/src/client/drift.d.ts +31 -0
- package/src/client/kamino.d.ts +8 -14
- package/src/client/marinade.d.ts +2 -8
- package/src/client/price.d.ts +32 -3
- package/src/client/staking.d.ts +2 -2
- package/src/client/state.d.ts +1 -0
- package/src/client.d.ts +3 -1
- package/src/constants.d.ts +2 -1
- package/src/layouts/drift-vault.d.ts +51 -0
- package/src/utils/helpers.d.ts +5 -3
- package/target/idl/glam_protocol.json +788 -170
- package/target/types/glam_protocol.d.ts +784 -166
- package/target/types/glam_protocol.ts +788 -170
package/index.cjs.js
CHANGED
|
@@ -7,9 +7,9 @@ var splTokenMetadata = require('@solana/spl-token-metadata');
|
|
|
7
7
|
var DLMM = require('@meteora-ag/dlmm');
|
|
8
8
|
var sanctumLstList = require('sanctum-lst-list');
|
|
9
9
|
var bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
10
|
+
var borsh = require('@coral-xyz/borsh');
|
|
10
11
|
var marinadeTsSdk = require('@marinade.finance/marinade-ts-sdk');
|
|
11
12
|
var splStakePool = require('@solana/spl-stake-pool');
|
|
12
|
-
var borsh = require('@coral-xyz/borsh');
|
|
13
13
|
|
|
14
14
|
function _interopNamespaceDefault(e) {
|
|
15
15
|
var n = Object.create(null);
|
|
@@ -34,7 +34,7 @@ var borsh__namespace = /*#__PURE__*/_interopNamespaceDefault(borsh);
|
|
|
34
34
|
var address = "GLAMbTqav9N9witRjswJ8enwp9vv5G8bsSJ2kPJ4rcyc";
|
|
35
35
|
var metadata = {
|
|
36
36
|
name: "glam_protocol",
|
|
37
|
-
version: "0.4.
|
|
37
|
+
version: "0.4.28",
|
|
38
38
|
spec: "0.1.0",
|
|
39
39
|
description: "Glam Protocol"
|
|
40
40
|
};
|
|
@@ -1524,35 +1524,393 @@ var instructions = [
|
|
|
1524
1524
|
},
|
|
1525
1525
|
{
|
|
1526
1526
|
name: "cpi_program",
|
|
1527
|
-
address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
|
|
1527
|
+
address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
|
|
1528
|
+
},
|
|
1529
|
+
{
|
|
1530
|
+
name: "user",
|
|
1531
|
+
writable: true
|
|
1532
|
+
}
|
|
1533
|
+
],
|
|
1534
|
+
args: [
|
|
1535
|
+
{
|
|
1536
|
+
name: "sub_account_id",
|
|
1537
|
+
type: "u16"
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
name: "delegate",
|
|
1541
|
+
type: "pubkey"
|
|
1542
|
+
}
|
|
1543
|
+
]
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
name: "drift_update_user_margin_trading_enabled",
|
|
1547
|
+
discriminator: [
|
|
1548
|
+
157,
|
|
1549
|
+
175,
|
|
1550
|
+
12,
|
|
1551
|
+
19,
|
|
1552
|
+
202,
|
|
1553
|
+
114,
|
|
1554
|
+
17,
|
|
1555
|
+
36
|
|
1556
|
+
],
|
|
1557
|
+
accounts: [
|
|
1558
|
+
{
|
|
1559
|
+
name: "glam_state"
|
|
1560
|
+
},
|
|
1561
|
+
{
|
|
1562
|
+
name: "glam_vault",
|
|
1563
|
+
pda: {
|
|
1564
|
+
seeds: [
|
|
1565
|
+
{
|
|
1566
|
+
kind: "const",
|
|
1567
|
+
value: [
|
|
1568
|
+
118,
|
|
1569
|
+
97,
|
|
1570
|
+
117,
|
|
1571
|
+
108,
|
|
1572
|
+
116
|
|
1573
|
+
]
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
kind: "account",
|
|
1577
|
+
path: "glam_state"
|
|
1578
|
+
}
|
|
1579
|
+
]
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
{
|
|
1583
|
+
name: "glam_signer",
|
|
1584
|
+
writable: true,
|
|
1585
|
+
signer: true
|
|
1586
|
+
},
|
|
1587
|
+
{
|
|
1588
|
+
name: "cpi_program",
|
|
1589
|
+
address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
|
|
1590
|
+
},
|
|
1591
|
+
{
|
|
1592
|
+
name: "user",
|
|
1593
|
+
writable: true
|
|
1594
|
+
}
|
|
1595
|
+
],
|
|
1596
|
+
args: [
|
|
1597
|
+
{
|
|
1598
|
+
name: "sub_account_id",
|
|
1599
|
+
type: "u16"
|
|
1600
|
+
},
|
|
1601
|
+
{
|
|
1602
|
+
name: "margin_trading_enabled",
|
|
1603
|
+
type: "bool"
|
|
1604
|
+
}
|
|
1605
|
+
]
|
|
1606
|
+
},
|
|
1607
|
+
{
|
|
1608
|
+
name: "drift_vaults_cancel_request_withdraw",
|
|
1609
|
+
discriminator: [
|
|
1610
|
+
241,
|
|
1611
|
+
196,
|
|
1612
|
+
156,
|
|
1613
|
+
180,
|
|
1614
|
+
21,
|
|
1615
|
+
155,
|
|
1616
|
+
228,
|
|
1617
|
+
125
|
|
1618
|
+
],
|
|
1619
|
+
accounts: [
|
|
1620
|
+
{
|
|
1621
|
+
name: "glam_state"
|
|
1622
|
+
},
|
|
1623
|
+
{
|
|
1624
|
+
name: "glam_vault",
|
|
1625
|
+
pda: {
|
|
1626
|
+
seeds: [
|
|
1627
|
+
{
|
|
1628
|
+
kind: "const",
|
|
1629
|
+
value: [
|
|
1630
|
+
118,
|
|
1631
|
+
97,
|
|
1632
|
+
117,
|
|
1633
|
+
108,
|
|
1634
|
+
116
|
|
1635
|
+
]
|
|
1636
|
+
},
|
|
1637
|
+
{
|
|
1638
|
+
kind: "account",
|
|
1639
|
+
path: "glam_state"
|
|
1640
|
+
}
|
|
1641
|
+
]
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1644
|
+
{
|
|
1645
|
+
name: "glam_signer",
|
|
1646
|
+
writable: true,
|
|
1647
|
+
signer: true
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
name: "cpi_program",
|
|
1651
|
+
address: "vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR"
|
|
1652
|
+
},
|
|
1653
|
+
{
|
|
1654
|
+
name: "vault",
|
|
1655
|
+
writable: true
|
|
1656
|
+
},
|
|
1657
|
+
{
|
|
1658
|
+
name: "vault_depositor",
|
|
1659
|
+
writable: true
|
|
1660
|
+
},
|
|
1661
|
+
{
|
|
1662
|
+
name: "drift_user_stats"
|
|
1663
|
+
},
|
|
1664
|
+
{
|
|
1665
|
+
name: "drift_user"
|
|
1666
|
+
}
|
|
1667
|
+
],
|
|
1668
|
+
args: []
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
name: "drift_vaults_deposit",
|
|
1672
|
+
discriminator: [
|
|
1673
|
+
95,
|
|
1674
|
+
223,
|
|
1675
|
+
42,
|
|
1676
|
+
76,
|
|
1677
|
+
37,
|
|
1678
|
+
21,
|
|
1679
|
+
176,
|
|
1680
|
+
73
|
|
1681
|
+
],
|
|
1682
|
+
accounts: [
|
|
1683
|
+
{
|
|
1684
|
+
name: "glam_state"
|
|
1685
|
+
},
|
|
1686
|
+
{
|
|
1687
|
+
name: "glam_vault",
|
|
1688
|
+
pda: {
|
|
1689
|
+
seeds: [
|
|
1690
|
+
{
|
|
1691
|
+
kind: "const",
|
|
1692
|
+
value: [
|
|
1693
|
+
118,
|
|
1694
|
+
97,
|
|
1695
|
+
117,
|
|
1696
|
+
108,
|
|
1697
|
+
116
|
|
1698
|
+
]
|
|
1699
|
+
},
|
|
1700
|
+
{
|
|
1701
|
+
kind: "account",
|
|
1702
|
+
path: "glam_state"
|
|
1703
|
+
}
|
|
1704
|
+
]
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
name: "glam_signer",
|
|
1709
|
+
writable: true,
|
|
1710
|
+
signer: true
|
|
1711
|
+
},
|
|
1712
|
+
{
|
|
1713
|
+
name: "cpi_program",
|
|
1714
|
+
address: "vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR"
|
|
1715
|
+
},
|
|
1716
|
+
{
|
|
1717
|
+
name: "vault",
|
|
1718
|
+
writable: true
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
name: "vault_depositor",
|
|
1722
|
+
writable: true
|
|
1723
|
+
},
|
|
1724
|
+
{
|
|
1725
|
+
name: "vault_token_account",
|
|
1726
|
+
writable: true
|
|
1727
|
+
},
|
|
1728
|
+
{
|
|
1729
|
+
name: "drift_user_stats",
|
|
1730
|
+
writable: true
|
|
1731
|
+
},
|
|
1732
|
+
{
|
|
1733
|
+
name: "drift_user",
|
|
1734
|
+
writable: true
|
|
1735
|
+
},
|
|
1736
|
+
{
|
|
1737
|
+
name: "drift_state"
|
|
1738
|
+
},
|
|
1739
|
+
{
|
|
1740
|
+
name: "drift_spot_market_vault",
|
|
1741
|
+
writable: true
|
|
1742
|
+
},
|
|
1743
|
+
{
|
|
1744
|
+
name: "user_token_account",
|
|
1745
|
+
writable: true
|
|
1746
|
+
},
|
|
1747
|
+
{
|
|
1748
|
+
name: "drift_program"
|
|
1749
|
+
},
|
|
1750
|
+
{
|
|
1751
|
+
name: "token_program"
|
|
1752
|
+
}
|
|
1753
|
+
],
|
|
1754
|
+
args: [
|
|
1755
|
+
{
|
|
1756
|
+
name: "amount",
|
|
1757
|
+
type: "u64"
|
|
1758
|
+
}
|
|
1759
|
+
]
|
|
1760
|
+
},
|
|
1761
|
+
{
|
|
1762
|
+
name: "drift_vaults_initialize_vault_depositor",
|
|
1763
|
+
discriminator: [
|
|
1764
|
+
109,
|
|
1765
|
+
183,
|
|
1766
|
+
50,
|
|
1767
|
+
62,
|
|
1768
|
+
60,
|
|
1769
|
+
195,
|
|
1770
|
+
192,
|
|
1771
|
+
51
|
|
1772
|
+
],
|
|
1773
|
+
accounts: [
|
|
1774
|
+
{
|
|
1775
|
+
name: "glam_state",
|
|
1776
|
+
writable: true
|
|
1777
|
+
},
|
|
1778
|
+
{
|
|
1779
|
+
name: "glam_vault",
|
|
1780
|
+
writable: true,
|
|
1781
|
+
pda: {
|
|
1782
|
+
seeds: [
|
|
1783
|
+
{
|
|
1784
|
+
kind: "const",
|
|
1785
|
+
value: [
|
|
1786
|
+
118,
|
|
1787
|
+
97,
|
|
1788
|
+
117,
|
|
1789
|
+
108,
|
|
1790
|
+
116
|
|
1791
|
+
]
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
kind: "account",
|
|
1795
|
+
path: "glam_state"
|
|
1796
|
+
}
|
|
1797
|
+
]
|
|
1798
|
+
}
|
|
1799
|
+
},
|
|
1800
|
+
{
|
|
1801
|
+
name: "glam_signer",
|
|
1802
|
+
writable: true,
|
|
1803
|
+
signer: true
|
|
1804
|
+
},
|
|
1805
|
+
{
|
|
1806
|
+
name: "cpi_program",
|
|
1807
|
+
address: "vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR"
|
|
1808
|
+
},
|
|
1809
|
+
{
|
|
1810
|
+
name: "vault"
|
|
1811
|
+
},
|
|
1812
|
+
{
|
|
1813
|
+
name: "vault_depositor",
|
|
1814
|
+
writable: true
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
name: "rent",
|
|
1818
|
+
address: "SysvarRent111111111111111111111111111111111"
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
name: "system_program",
|
|
1822
|
+
address: "11111111111111111111111111111111"
|
|
1823
|
+
}
|
|
1824
|
+
],
|
|
1825
|
+
args: []
|
|
1826
|
+
},
|
|
1827
|
+
{
|
|
1828
|
+
name: "drift_vaults_request_withdraw",
|
|
1829
|
+
discriminator: [
|
|
1830
|
+
19,
|
|
1831
|
+
53,
|
|
1832
|
+
222,
|
|
1833
|
+
51,
|
|
1834
|
+
44,
|
|
1835
|
+
215,
|
|
1836
|
+
35,
|
|
1837
|
+
82
|
|
1838
|
+
],
|
|
1839
|
+
accounts: [
|
|
1840
|
+
{
|
|
1841
|
+
name: "glam_state"
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
name: "glam_vault",
|
|
1845
|
+
pda: {
|
|
1846
|
+
seeds: [
|
|
1847
|
+
{
|
|
1848
|
+
kind: "const",
|
|
1849
|
+
value: [
|
|
1850
|
+
118,
|
|
1851
|
+
97,
|
|
1852
|
+
117,
|
|
1853
|
+
108,
|
|
1854
|
+
116
|
|
1855
|
+
]
|
|
1856
|
+
},
|
|
1857
|
+
{
|
|
1858
|
+
kind: "account",
|
|
1859
|
+
path: "glam_state"
|
|
1860
|
+
}
|
|
1861
|
+
]
|
|
1862
|
+
}
|
|
1863
|
+
},
|
|
1864
|
+
{
|
|
1865
|
+
name: "glam_signer",
|
|
1866
|
+
writable: true,
|
|
1867
|
+
signer: true
|
|
1868
|
+
},
|
|
1869
|
+
{
|
|
1870
|
+
name: "cpi_program",
|
|
1871
|
+
address: "vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR"
|
|
1528
1872
|
},
|
|
1529
1873
|
{
|
|
1530
|
-
name: "
|
|
1874
|
+
name: "vault",
|
|
1875
|
+
writable: true
|
|
1876
|
+
},
|
|
1877
|
+
{
|
|
1878
|
+
name: "vault_depositor",
|
|
1531
1879
|
writable: true
|
|
1880
|
+
},
|
|
1881
|
+
{
|
|
1882
|
+
name: "drift_user_stats"
|
|
1883
|
+
},
|
|
1884
|
+
{
|
|
1885
|
+
name: "drift_user"
|
|
1532
1886
|
}
|
|
1533
1887
|
],
|
|
1534
1888
|
args: [
|
|
1535
1889
|
{
|
|
1536
|
-
name: "
|
|
1537
|
-
type: "
|
|
1890
|
+
name: "withdraw_amount",
|
|
1891
|
+
type: "u64"
|
|
1538
1892
|
},
|
|
1539
1893
|
{
|
|
1540
|
-
name: "
|
|
1541
|
-
type:
|
|
1894
|
+
name: "withdraw_unit",
|
|
1895
|
+
type: {
|
|
1896
|
+
defined: {
|
|
1897
|
+
name: "WithdrawUnit"
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1542
1900
|
}
|
|
1543
1901
|
]
|
|
1544
1902
|
},
|
|
1545
1903
|
{
|
|
1546
|
-
name: "
|
|
1904
|
+
name: "drift_vaults_withdraw",
|
|
1547
1905
|
discriminator: [
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1906
|
+
58,
|
|
1907
|
+
127,
|
|
1908
|
+
150,
|
|
1909
|
+
177,
|
|
1910
|
+
66,
|
|
1911
|
+
45,
|
|
1912
|
+
5,
|
|
1913
|
+
30
|
|
1556
1914
|
],
|
|
1557
1915
|
accounts: [
|
|
1558
1916
|
{
|
|
@@ -1586,23 +1944,50 @@ var instructions = [
|
|
|
1586
1944
|
},
|
|
1587
1945
|
{
|
|
1588
1946
|
name: "cpi_program",
|
|
1589
|
-
address: "
|
|
1947
|
+
address: "vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR"
|
|
1590
1948
|
},
|
|
1591
1949
|
{
|
|
1592
|
-
name: "
|
|
1950
|
+
name: "vault",
|
|
1593
1951
|
writable: true
|
|
1594
|
-
}
|
|
1595
|
-
],
|
|
1596
|
-
args: [
|
|
1952
|
+
},
|
|
1597
1953
|
{
|
|
1598
|
-
name: "
|
|
1599
|
-
|
|
1954
|
+
name: "vault_depositor",
|
|
1955
|
+
writable: true
|
|
1600
1956
|
},
|
|
1601
1957
|
{
|
|
1602
|
-
name: "
|
|
1603
|
-
|
|
1958
|
+
name: "vault_token_account",
|
|
1959
|
+
writable: true
|
|
1960
|
+
},
|
|
1961
|
+
{
|
|
1962
|
+
name: "drift_user_stats",
|
|
1963
|
+
writable: true
|
|
1964
|
+
},
|
|
1965
|
+
{
|
|
1966
|
+
name: "drift_user",
|
|
1967
|
+
writable: true
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
name: "drift_state"
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
name: "drift_spot_market_vault",
|
|
1974
|
+
writable: true
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
name: "drift_signer"
|
|
1978
|
+
},
|
|
1979
|
+
{
|
|
1980
|
+
name: "user_token_account",
|
|
1981
|
+
writable: true
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
name: "drift_program"
|
|
1985
|
+
},
|
|
1986
|
+
{
|
|
1987
|
+
name: "token_program"
|
|
1604
1988
|
}
|
|
1605
|
-
]
|
|
1989
|
+
],
|
|
1990
|
+
args: []
|
|
1606
1991
|
},
|
|
1607
1992
|
{
|
|
1608
1993
|
name: "drift_withdraw",
|
|
@@ -1772,6 +2157,40 @@ var instructions = [
|
|
|
1772
2157
|
}
|
|
1773
2158
|
]
|
|
1774
2159
|
},
|
|
2160
|
+
{
|
|
2161
|
+
name: "extend_state",
|
|
2162
|
+
discriminator: [
|
|
2163
|
+
34,
|
|
2164
|
+
147,
|
|
2165
|
+
151,
|
|
2166
|
+
206,
|
|
2167
|
+
134,
|
|
2168
|
+
128,
|
|
2169
|
+
82,
|
|
2170
|
+
228
|
|
2171
|
+
],
|
|
2172
|
+
accounts: [
|
|
2173
|
+
{
|
|
2174
|
+
name: "glam_state",
|
|
2175
|
+
writable: true
|
|
2176
|
+
},
|
|
2177
|
+
{
|
|
2178
|
+
name: "glam_signer",
|
|
2179
|
+
writable: true,
|
|
2180
|
+
signer: true
|
|
2181
|
+
},
|
|
2182
|
+
{
|
|
2183
|
+
name: "system_program",
|
|
2184
|
+
address: "11111111111111111111111111111111"
|
|
2185
|
+
}
|
|
2186
|
+
],
|
|
2187
|
+
args: [
|
|
2188
|
+
{
|
|
2189
|
+
name: "bytes",
|
|
2190
|
+
type: "u32"
|
|
2191
|
+
}
|
|
2192
|
+
]
|
|
2193
|
+
},
|
|
1775
2194
|
{
|
|
1776
2195
|
name: "force_transfer_tokens",
|
|
1777
2196
|
discriminator: [
|
|
@@ -3750,7 +4169,8 @@ var instructions = [
|
|
|
3750
4169
|
],
|
|
3751
4170
|
accounts: [
|
|
3752
4171
|
{
|
|
3753
|
-
name: "glam_state"
|
|
4172
|
+
name: "glam_state",
|
|
4173
|
+
writable: true
|
|
3754
4174
|
},
|
|
3755
4175
|
{
|
|
3756
4176
|
name: "glam_vault",
|
|
@@ -3851,25 +4271,118 @@ var instructions = [
|
|
|
3851
4271
|
]
|
|
3852
4272
|
},
|
|
3853
4273
|
{
|
|
3854
|
-
name: "
|
|
4274
|
+
name: "kamino_vaults_deposit",
|
|
3855
4275
|
discriminator: [
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
4276
|
+
209,
|
|
4277
|
+
133,
|
|
4278
|
+
37,
|
|
4279
|
+
193,
|
|
4280
|
+
192,
|
|
4281
|
+
217,
|
|
4282
|
+
55,
|
|
4283
|
+
40
|
|
3864
4284
|
],
|
|
3865
4285
|
accounts: [
|
|
3866
4286
|
{
|
|
3867
|
-
name: "glam_state"
|
|
3868
|
-
writable: true
|
|
4287
|
+
name: "glam_state"
|
|
3869
4288
|
},
|
|
3870
4289
|
{
|
|
3871
4290
|
name: "glam_vault",
|
|
4291
|
+
pda: {
|
|
4292
|
+
seeds: [
|
|
4293
|
+
{
|
|
4294
|
+
kind: "const",
|
|
4295
|
+
value: [
|
|
4296
|
+
118,
|
|
4297
|
+
97,
|
|
4298
|
+
117,
|
|
4299
|
+
108,
|
|
4300
|
+
116
|
|
4301
|
+
]
|
|
4302
|
+
},
|
|
4303
|
+
{
|
|
4304
|
+
kind: "account",
|
|
4305
|
+
path: "glam_state"
|
|
4306
|
+
}
|
|
4307
|
+
]
|
|
4308
|
+
}
|
|
4309
|
+
},
|
|
4310
|
+
{
|
|
4311
|
+
name: "glam_signer",
|
|
3872
4312
|
writable: true,
|
|
4313
|
+
signer: true
|
|
4314
|
+
},
|
|
4315
|
+
{
|
|
4316
|
+
name: "cpi_program",
|
|
4317
|
+
address: "KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd"
|
|
4318
|
+
},
|
|
4319
|
+
{
|
|
4320
|
+
name: "vault_state",
|
|
4321
|
+
writable: true
|
|
4322
|
+
},
|
|
4323
|
+
{
|
|
4324
|
+
name: "token_vault",
|
|
4325
|
+
writable: true
|
|
4326
|
+
},
|
|
4327
|
+
{
|
|
4328
|
+
name: "token_mint"
|
|
4329
|
+
},
|
|
4330
|
+
{
|
|
4331
|
+
name: "base_vault_authority"
|
|
4332
|
+
},
|
|
4333
|
+
{
|
|
4334
|
+
name: "shares_mint",
|
|
4335
|
+
writable: true
|
|
4336
|
+
},
|
|
4337
|
+
{
|
|
4338
|
+
name: "user_token_ata",
|
|
4339
|
+
writable: true
|
|
4340
|
+
},
|
|
4341
|
+
{
|
|
4342
|
+
name: "user_shares_ata",
|
|
4343
|
+
writable: true
|
|
4344
|
+
},
|
|
4345
|
+
{
|
|
4346
|
+
name: "klend_program"
|
|
4347
|
+
},
|
|
4348
|
+
{
|
|
4349
|
+
name: "token_program"
|
|
4350
|
+
},
|
|
4351
|
+
{
|
|
4352
|
+
name: "shares_token_program"
|
|
4353
|
+
},
|
|
4354
|
+
{
|
|
4355
|
+
name: "event_authority"
|
|
4356
|
+
},
|
|
4357
|
+
{
|
|
4358
|
+
name: "program"
|
|
4359
|
+
}
|
|
4360
|
+
],
|
|
4361
|
+
args: [
|
|
4362
|
+
{
|
|
4363
|
+
name: "amount",
|
|
4364
|
+
type: "u64"
|
|
4365
|
+
}
|
|
4366
|
+
]
|
|
4367
|
+
},
|
|
4368
|
+
{
|
|
4369
|
+
name: "kamino_vaults_withdraw",
|
|
4370
|
+
discriminator: [
|
|
4371
|
+
82,
|
|
4372
|
+
106,
|
|
4373
|
+
49,
|
|
4374
|
+
86,
|
|
4375
|
+
156,
|
|
4376
|
+
15,
|
|
4377
|
+
87,
|
|
4378
|
+
8
|
|
4379
|
+
],
|
|
4380
|
+
accounts: [
|
|
4381
|
+
{
|
|
4382
|
+
name: "glam_state"
|
|
4383
|
+
},
|
|
4384
|
+
{
|
|
4385
|
+
name: "glam_vault",
|
|
3873
4386
|
pda: {
|
|
3874
4387
|
seeds: [
|
|
3875
4388
|
{
|
|
@@ -3890,35 +4403,101 @@ var instructions = [
|
|
|
3890
4403
|
}
|
|
3891
4404
|
},
|
|
3892
4405
|
{
|
|
3893
|
-
name: "glam_signer",
|
|
3894
|
-
writable: true,
|
|
3895
|
-
signer: true
|
|
4406
|
+
name: "glam_signer",
|
|
4407
|
+
writable: true,
|
|
4408
|
+
signer: true
|
|
4409
|
+
},
|
|
4410
|
+
{
|
|
4411
|
+
name: "cpi_program",
|
|
4412
|
+
address: "KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd"
|
|
4413
|
+
},
|
|
4414
|
+
{
|
|
4415
|
+
name: "withdraw_from_available_vault_state",
|
|
4416
|
+
writable: true
|
|
4417
|
+
},
|
|
4418
|
+
{
|
|
4419
|
+
name: "withdraw_from_available_token_vault",
|
|
4420
|
+
writable: true
|
|
4421
|
+
},
|
|
4422
|
+
{
|
|
4423
|
+
name: "withdraw_from_available_base_vault_authority"
|
|
4424
|
+
},
|
|
4425
|
+
{
|
|
4426
|
+
name: "withdraw_from_available_user_token_ata",
|
|
4427
|
+
writable: true
|
|
4428
|
+
},
|
|
4429
|
+
{
|
|
4430
|
+
name: "withdraw_from_available_token_mint",
|
|
4431
|
+
writable: true
|
|
4432
|
+
},
|
|
4433
|
+
{
|
|
4434
|
+
name: "withdraw_from_available_user_shares_ata",
|
|
4435
|
+
writable: true
|
|
4436
|
+
},
|
|
4437
|
+
{
|
|
4438
|
+
name: "withdraw_from_available_shares_mint",
|
|
4439
|
+
writable: true
|
|
4440
|
+
},
|
|
4441
|
+
{
|
|
4442
|
+
name: "withdraw_from_available_token_program"
|
|
4443
|
+
},
|
|
4444
|
+
{
|
|
4445
|
+
name: "withdraw_from_available_shares_token_program"
|
|
4446
|
+
},
|
|
4447
|
+
{
|
|
4448
|
+
name: "withdraw_from_available_klend_program"
|
|
4449
|
+
},
|
|
4450
|
+
{
|
|
4451
|
+
name: "withdraw_from_available_event_authority"
|
|
4452
|
+
},
|
|
4453
|
+
{
|
|
4454
|
+
name: "withdraw_from_available_program"
|
|
4455
|
+
},
|
|
4456
|
+
{
|
|
4457
|
+
name: "withdraw_from_reserve_vault_state",
|
|
4458
|
+
writable: true
|
|
4459
|
+
},
|
|
4460
|
+
{
|
|
4461
|
+
name: "withdraw_from_reserve_reserve",
|
|
4462
|
+
writable: true
|
|
4463
|
+
},
|
|
4464
|
+
{
|
|
4465
|
+
name: "withdraw_from_reserve_ctoken_vault",
|
|
4466
|
+
writable: true
|
|
4467
|
+
},
|
|
4468
|
+
{
|
|
4469
|
+
name: "withdraw_from_reserve_lending_market"
|
|
3896
4470
|
},
|
|
3897
4471
|
{
|
|
3898
|
-
name: "
|
|
3899
|
-
address: "MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD"
|
|
4472
|
+
name: "withdraw_from_reserve_lending_market_authority"
|
|
3900
4473
|
},
|
|
3901
4474
|
{
|
|
3902
|
-
name: "
|
|
4475
|
+
name: "withdraw_from_reserve_reserve_liquidity_supply",
|
|
3903
4476
|
writable: true
|
|
3904
4477
|
},
|
|
3905
4478
|
{
|
|
3906
|
-
name: "
|
|
4479
|
+
name: "withdraw_from_reserve_reserve_collateral_mint",
|
|
3907
4480
|
writable: true
|
|
3908
4481
|
},
|
|
3909
4482
|
{
|
|
3910
|
-
name: "
|
|
3911
|
-
writable: true
|
|
4483
|
+
name: "withdraw_from_reserve_reserve_collateral_token_program"
|
|
3912
4484
|
},
|
|
3913
4485
|
{
|
|
3914
|
-
name: "
|
|
4486
|
+
name: "withdraw_from_reserve_instruction_sysvar_account"
|
|
3915
4487
|
},
|
|
3916
4488
|
{
|
|
3917
|
-
name: "
|
|
3918
|
-
|
|
4489
|
+
name: "event_authority"
|
|
4490
|
+
},
|
|
4491
|
+
{
|
|
4492
|
+
name: "program"
|
|
3919
4493
|
}
|
|
3920
4494
|
],
|
|
3921
|
-
args: [
|
|
4495
|
+
args: [
|
|
4496
|
+
{
|
|
4497
|
+
name: "amount",
|
|
4498
|
+
type: "u64"
|
|
4499
|
+
}
|
|
4500
|
+
]
|
|
3922
4501
|
},
|
|
3923
4502
|
{
|
|
3924
4503
|
name: "marinade_deposit",
|
|
@@ -4117,88 +4696,6 @@ var instructions = [
|
|
|
4117
4696
|
}
|
|
4118
4697
|
]
|
|
4119
4698
|
},
|
|
4120
|
-
{
|
|
4121
|
-
name: "marinade_order_unstake",
|
|
4122
|
-
discriminator: [
|
|
4123
|
-
202,
|
|
4124
|
-
3,
|
|
4125
|
-
33,
|
|
4126
|
-
27,
|
|
4127
|
-
183,
|
|
4128
|
-
156,
|
|
4129
|
-
57,
|
|
4130
|
-
231
|
|
4131
|
-
],
|
|
4132
|
-
accounts: [
|
|
4133
|
-
{
|
|
4134
|
-
name: "glam_state",
|
|
4135
|
-
writable: true
|
|
4136
|
-
},
|
|
4137
|
-
{
|
|
4138
|
-
name: "glam_vault",
|
|
4139
|
-
writable: true,
|
|
4140
|
-
pda: {
|
|
4141
|
-
seeds: [
|
|
4142
|
-
{
|
|
4143
|
-
kind: "const",
|
|
4144
|
-
value: [
|
|
4145
|
-
118,
|
|
4146
|
-
97,
|
|
4147
|
-
117,
|
|
4148
|
-
108,
|
|
4149
|
-
116
|
|
4150
|
-
]
|
|
4151
|
-
},
|
|
4152
|
-
{
|
|
4153
|
-
kind: "account",
|
|
4154
|
-
path: "glam_state"
|
|
4155
|
-
}
|
|
4156
|
-
]
|
|
4157
|
-
}
|
|
4158
|
-
},
|
|
4159
|
-
{
|
|
4160
|
-
name: "glam_signer",
|
|
4161
|
-
writable: true,
|
|
4162
|
-
signer: true
|
|
4163
|
-
},
|
|
4164
|
-
{
|
|
4165
|
-
name: "cpi_program",
|
|
4166
|
-
address: "MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD"
|
|
4167
|
-
},
|
|
4168
|
-
{
|
|
4169
|
-
name: "state",
|
|
4170
|
-
writable: true
|
|
4171
|
-
},
|
|
4172
|
-
{
|
|
4173
|
-
name: "msol_mint",
|
|
4174
|
-
writable: true
|
|
4175
|
-
},
|
|
4176
|
-
{
|
|
4177
|
-
name: "burn_msol_from",
|
|
4178
|
-
writable: true
|
|
4179
|
-
},
|
|
4180
|
-
{
|
|
4181
|
-
name: "new_ticket_account",
|
|
4182
|
-
writable: true
|
|
4183
|
-
},
|
|
4184
|
-
{
|
|
4185
|
-
name: "clock"
|
|
4186
|
-
},
|
|
4187
|
-
{
|
|
4188
|
-
name: "rent",
|
|
4189
|
-
address: "SysvarRent111111111111111111111111111111111"
|
|
4190
|
-
},
|
|
4191
|
-
{
|
|
4192
|
-
name: "token_program"
|
|
4193
|
-
}
|
|
4194
|
-
],
|
|
4195
|
-
args: [
|
|
4196
|
-
{
|
|
4197
|
-
name: "msol_amount",
|
|
4198
|
-
type: "u64"
|
|
4199
|
-
}
|
|
4200
|
-
]
|
|
4201
|
-
},
|
|
4202
4699
|
{
|
|
4203
4700
|
name: "marinade_withdraw_stake_account",
|
|
4204
4701
|
discriminator: [
|
|
@@ -5786,16 +6283,16 @@ var instructions = [
|
|
|
5786
6283
|
]
|
|
5787
6284
|
},
|
|
5788
6285
|
{
|
|
5789
|
-
name: "
|
|
6286
|
+
name: "price_drift_users",
|
|
5790
6287
|
discriminator: [
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
6288
|
+
12,
|
|
6289
|
+
5,
|
|
6290
|
+
143,
|
|
6291
|
+
51,
|
|
6292
|
+
101,
|
|
6293
|
+
81,
|
|
6294
|
+
200,
|
|
6295
|
+
150
|
|
5799
6296
|
],
|
|
5800
6297
|
accounts: [
|
|
5801
6298
|
{
|
|
@@ -5803,7 +6300,25 @@ var instructions = [
|
|
|
5803
6300
|
writable: true
|
|
5804
6301
|
},
|
|
5805
6302
|
{
|
|
5806
|
-
name: "glam_vault"
|
|
6303
|
+
name: "glam_vault",
|
|
6304
|
+
pda: {
|
|
6305
|
+
seeds: [
|
|
6306
|
+
{
|
|
6307
|
+
kind: "const",
|
|
6308
|
+
value: [
|
|
6309
|
+
118,
|
|
6310
|
+
97,
|
|
6311
|
+
117,
|
|
6312
|
+
108,
|
|
6313
|
+
116
|
|
6314
|
+
]
|
|
6315
|
+
},
|
|
6316
|
+
{
|
|
6317
|
+
kind: "account",
|
|
6318
|
+
path: "glam_state"
|
|
6319
|
+
}
|
|
6320
|
+
]
|
|
6321
|
+
}
|
|
5807
6322
|
},
|
|
5808
6323
|
{
|
|
5809
6324
|
name: "signer",
|
|
@@ -5814,13 +6329,66 @@ var instructions = [
|
|
|
5814
6329
|
name: "sol_oracle"
|
|
5815
6330
|
},
|
|
5816
6331
|
{
|
|
5817
|
-
name: "
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
6332
|
+
name: "glam_config",
|
|
6333
|
+
pda: {
|
|
6334
|
+
seeds: [
|
|
6335
|
+
{
|
|
6336
|
+
kind: "const",
|
|
6337
|
+
value: [
|
|
6338
|
+
103,
|
|
6339
|
+
108,
|
|
6340
|
+
111,
|
|
6341
|
+
98,
|
|
6342
|
+
97,
|
|
6343
|
+
108,
|
|
6344
|
+
95,
|
|
6345
|
+
99,
|
|
6346
|
+
111,
|
|
6347
|
+
110,
|
|
6348
|
+
102,
|
|
6349
|
+
105,
|
|
6350
|
+
103
|
|
6351
|
+
]
|
|
6352
|
+
}
|
|
6353
|
+
],
|
|
6354
|
+
program: {
|
|
6355
|
+
kind: "const",
|
|
6356
|
+
value: [
|
|
6357
|
+
10,
|
|
6358
|
+
11,
|
|
6359
|
+
0,
|
|
6360
|
+
83,
|
|
6361
|
+
72,
|
|
6362
|
+
16,
|
|
6363
|
+
46,
|
|
6364
|
+
144,
|
|
6365
|
+
46,
|
|
6366
|
+
42,
|
|
6367
|
+
79,
|
|
6368
|
+
22,
|
|
6369
|
+
157,
|
|
6370
|
+
123,
|
|
6371
|
+
21,
|
|
6372
|
+
242,
|
|
6373
|
+
192,
|
|
6374
|
+
146,
|
|
6375
|
+
1,
|
|
6376
|
+
78,
|
|
6377
|
+
88,
|
|
6378
|
+
59,
|
|
6379
|
+
102,
|
|
6380
|
+
9,
|
|
6381
|
+
190,
|
|
6382
|
+
226,
|
|
6383
|
+
92,
|
|
6384
|
+
189,
|
|
6385
|
+
187,
|
|
6386
|
+
232,
|
|
6387
|
+
83,
|
|
6388
|
+
220
|
|
6389
|
+
]
|
|
6390
|
+
}
|
|
6391
|
+
}
|
|
5824
6392
|
}
|
|
5825
6393
|
],
|
|
5826
6394
|
args: [
|
|
@@ -5835,16 +6403,16 @@ var instructions = [
|
|
|
5835
6403
|
]
|
|
5836
6404
|
},
|
|
5837
6405
|
{
|
|
5838
|
-
name: "
|
|
6406
|
+
name: "price_drift_vault_depositors",
|
|
5839
6407
|
discriminator: [
|
|
5840
|
-
166,
|
|
5841
|
-
110,
|
|
5842
6408
|
234,
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
6409
|
+
16,
|
|
6410
|
+
238,
|
|
6411
|
+
70,
|
|
6412
|
+
189,
|
|
6413
|
+
23,
|
|
6414
|
+
98,
|
|
6415
|
+
160
|
|
5848
6416
|
],
|
|
5849
6417
|
accounts: [
|
|
5850
6418
|
{
|
|
@@ -5873,14 +6441,10 @@ var instructions = [
|
|
|
5873
6441
|
}
|
|
5874
6442
|
},
|
|
5875
6443
|
{
|
|
5876
|
-
name: "
|
|
6444
|
+
name: "signer",
|
|
5877
6445
|
writable: true,
|
|
5878
6446
|
signer: true
|
|
5879
6447
|
},
|
|
5880
|
-
{
|
|
5881
|
-
name: "kamino_lending_program",
|
|
5882
|
-
address: "KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"
|
|
5883
|
-
},
|
|
5884
6448
|
{
|
|
5885
6449
|
name: "sol_oracle"
|
|
5886
6450
|
},
|
|
@@ -5945,22 +6509,6 @@ var instructions = [
|
|
|
5945
6509
|
]
|
|
5946
6510
|
}
|
|
5947
6511
|
}
|
|
5948
|
-
},
|
|
5949
|
-
{
|
|
5950
|
-
name: "pyth_oracle",
|
|
5951
|
-
optional: true
|
|
5952
|
-
},
|
|
5953
|
-
{
|
|
5954
|
-
name: "switchboard_price_oracle",
|
|
5955
|
-
optional: true
|
|
5956
|
-
},
|
|
5957
|
-
{
|
|
5958
|
-
name: "switchboard_twap_oracle",
|
|
5959
|
-
optional: true
|
|
5960
|
-
},
|
|
5961
|
-
{
|
|
5962
|
-
name: "scope_prices",
|
|
5963
|
-
optional: true
|
|
5964
6512
|
}
|
|
5965
6513
|
],
|
|
5966
6514
|
args: [
|
|
@@ -5975,16 +6523,16 @@ var instructions = [
|
|
|
5975
6523
|
]
|
|
5976
6524
|
},
|
|
5977
6525
|
{
|
|
5978
|
-
name: "
|
|
6526
|
+
name: "price_kamino_obligations",
|
|
5979
6527
|
discriminator: [
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
6528
|
+
166,
|
|
6529
|
+
110,
|
|
6530
|
+
234,
|
|
6531
|
+
179,
|
|
6532
|
+
240,
|
|
6533
|
+
179,
|
|
6534
|
+
69,
|
|
6535
|
+
246
|
|
5988
6536
|
],
|
|
5989
6537
|
accounts: [
|
|
5990
6538
|
{
|
|
@@ -6013,10 +6561,14 @@ var instructions = [
|
|
|
6013
6561
|
}
|
|
6014
6562
|
},
|
|
6015
6563
|
{
|
|
6016
|
-
name: "
|
|
6564
|
+
name: "signer",
|
|
6017
6565
|
writable: true,
|
|
6018
6566
|
signer: true
|
|
6019
6567
|
},
|
|
6568
|
+
{
|
|
6569
|
+
name: "kamino_lending_program",
|
|
6570
|
+
address: "KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"
|
|
6571
|
+
},
|
|
6020
6572
|
{
|
|
6021
6573
|
name: "sol_oracle"
|
|
6022
6574
|
},
|
|
@@ -6081,6 +6633,22 @@ var instructions = [
|
|
|
6081
6633
|
]
|
|
6082
6634
|
}
|
|
6083
6635
|
}
|
|
6636
|
+
},
|
|
6637
|
+
{
|
|
6638
|
+
name: "pyth_oracle",
|
|
6639
|
+
optional: true
|
|
6640
|
+
},
|
|
6641
|
+
{
|
|
6642
|
+
name: "switchboard_price_oracle",
|
|
6643
|
+
optional: true
|
|
6644
|
+
},
|
|
6645
|
+
{
|
|
6646
|
+
name: "switchboard_twap_oracle",
|
|
6647
|
+
optional: true
|
|
6648
|
+
},
|
|
6649
|
+
{
|
|
6650
|
+
name: "scope_prices",
|
|
6651
|
+
optional: true
|
|
6084
6652
|
}
|
|
6085
6653
|
],
|
|
6086
6654
|
args: [
|
|
@@ -6095,16 +6663,16 @@ var instructions = [
|
|
|
6095
6663
|
]
|
|
6096
6664
|
},
|
|
6097
6665
|
{
|
|
6098
|
-
name: "
|
|
6666
|
+
name: "price_meteora_positions",
|
|
6099
6667
|
discriminator: [
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6668
|
+
186,
|
|
6669
|
+
22,
|
|
6670
|
+
157,
|
|
6671
|
+
249,
|
|
6672
|
+
185,
|
|
6673
|
+
176,
|
|
6674
|
+
253,
|
|
6675
|
+
133
|
|
6108
6676
|
],
|
|
6109
6677
|
accounts: [
|
|
6110
6678
|
{
|
|
@@ -6133,7 +6701,7 @@ var instructions = [
|
|
|
6133
6701
|
}
|
|
6134
6702
|
},
|
|
6135
6703
|
{
|
|
6136
|
-
name: "
|
|
6704
|
+
name: "signer",
|
|
6137
6705
|
writable: true,
|
|
6138
6706
|
signer: true
|
|
6139
6707
|
},
|
|
@@ -6215,16 +6783,16 @@ var instructions = [
|
|
|
6215
6783
|
]
|
|
6216
6784
|
},
|
|
6217
6785
|
{
|
|
6218
|
-
name: "
|
|
6786
|
+
name: "price_stakes",
|
|
6219
6787
|
discriminator: [
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6788
|
+
0,
|
|
6789
|
+
60,
|
|
6790
|
+
60,
|
|
6791
|
+
103,
|
|
6792
|
+
201,
|
|
6793
|
+
94,
|
|
6794
|
+
72,
|
|
6795
|
+
223
|
|
6228
6796
|
],
|
|
6229
6797
|
accounts: [
|
|
6230
6798
|
{
|
|
@@ -6253,7 +6821,7 @@ var instructions = [
|
|
|
6253
6821
|
}
|
|
6254
6822
|
},
|
|
6255
6823
|
{
|
|
6256
|
-
name: "
|
|
6824
|
+
name: "signer",
|
|
6257
6825
|
writable: true,
|
|
6258
6826
|
signer: true
|
|
6259
6827
|
},
|
|
@@ -6373,7 +6941,7 @@ var instructions = [
|
|
|
6373
6941
|
}
|
|
6374
6942
|
},
|
|
6375
6943
|
{
|
|
6376
|
-
name: "
|
|
6944
|
+
name: "signer",
|
|
6377
6945
|
writable: true,
|
|
6378
6946
|
signer: true
|
|
6379
6947
|
},
|
|
@@ -9512,11 +10080,6 @@ var errors = [
|
|
|
9512
10080
|
name: "InvalidAuthority",
|
|
9513
10081
|
msg: "Invalid authority"
|
|
9514
10082
|
},
|
|
9515
|
-
{
|
|
9516
|
-
code: 48009,
|
|
9517
|
-
name: "InvalidPriceDenom",
|
|
9518
|
-
msg: "Invalid price denom"
|
|
9519
|
-
},
|
|
9520
10083
|
{
|
|
9521
10084
|
code: 49000,
|
|
9522
10085
|
name: "InvalidAccountType",
|
|
@@ -9717,6 +10280,26 @@ var errors = [
|
|
|
9717
10280
|
name: "BaseAssetNotSupported",
|
|
9718
10281
|
msg: "Base asset must have 6 decimals."
|
|
9719
10282
|
},
|
|
10283
|
+
{
|
|
10284
|
+
code: 51110,
|
|
10285
|
+
name: "InvalidQuoteSpotMarket",
|
|
10286
|
+
msg: "Unsupported spot market for perp quotes"
|
|
10287
|
+
},
|
|
10288
|
+
{
|
|
10289
|
+
code: 51111,
|
|
10290
|
+
name: "UnknownExternalVaultAsset",
|
|
10291
|
+
msg: "Unknown external vault account"
|
|
10292
|
+
},
|
|
10293
|
+
{
|
|
10294
|
+
code: 51112,
|
|
10295
|
+
name: "InvalidPriceDenom",
|
|
10296
|
+
msg: "Invalid price denom"
|
|
10297
|
+
},
|
|
10298
|
+
{
|
|
10299
|
+
code: 51113,
|
|
10300
|
+
name: "UnexpectedDiscriminator",
|
|
10301
|
+
msg: "Invalid account: discriminator mismatch"
|
|
10302
|
+
},
|
|
9720
10303
|
{
|
|
9721
10304
|
code: 52000,
|
|
9722
10305
|
name: "TransfersDisabled",
|
|
@@ -11048,6 +11631,12 @@ var types = [
|
|
|
11048
11631
|
},
|
|
11049
11632
|
{
|
|
11050
11633
|
name: "MeteoraDlmm"
|
|
11634
|
+
},
|
|
11635
|
+
{
|
|
11636
|
+
name: "DriftVaults"
|
|
11637
|
+
},
|
|
11638
|
+
{
|
|
11639
|
+
name: "KaminoVaults"
|
|
11051
11640
|
}
|
|
11052
11641
|
]
|
|
11053
11642
|
}
|
|
@@ -12168,6 +12757,18 @@ var types = [
|
|
|
12168
12757
|
},
|
|
12169
12758
|
{
|
|
12170
12759
|
name: "EmergencyUpdate"
|
|
12760
|
+
},
|
|
12761
|
+
{
|
|
12762
|
+
name: "DriftVaultsDeposit"
|
|
12763
|
+
},
|
|
12764
|
+
{
|
|
12765
|
+
name: "DriftVaultsWithdraw"
|
|
12766
|
+
},
|
|
12767
|
+
{
|
|
12768
|
+
name: "KaminoVaultsDeposit"
|
|
12769
|
+
},
|
|
12770
|
+
{
|
|
12771
|
+
name: "KaminoVaultsWithdraw"
|
|
12171
12772
|
}
|
|
12172
12773
|
]
|
|
12173
12774
|
}
|
|
@@ -13024,6 +13625,23 @@ var types = [
|
|
|
13024
13625
|
}
|
|
13025
13626
|
]
|
|
13026
13627
|
}
|
|
13628
|
+
},
|
|
13629
|
+
{
|
|
13630
|
+
name: "WithdrawUnit",
|
|
13631
|
+
type: {
|
|
13632
|
+
kind: "enum",
|
|
13633
|
+
variants: [
|
|
13634
|
+
{
|
|
13635
|
+
name: "Shares"
|
|
13636
|
+
},
|
|
13637
|
+
{
|
|
13638
|
+
name: "Token"
|
|
13639
|
+
},
|
|
13640
|
+
{
|
|
13641
|
+
name: "SharesPercent"
|
|
13642
|
+
}
|
|
13643
|
+
]
|
|
13644
|
+
}
|
|
13027
13645
|
}
|
|
13028
13646
|
];
|
|
13029
13647
|
var constants = [
|
|
@@ -13090,10 +13708,10 @@ const SEED_MINT = (GlamProtocolIdlJson.constants.find((x)=>x.name === "SEED_MINT
|
|
|
13090
13708
|
const SEED_STATE = (GlamProtocolIdlJson.constants.find((x)=>x.name === "SEED_STATE")?.value || "").replace(/"/g, "");
|
|
13091
13709
|
const SEED_VAULT = (GlamProtocolIdlJson.constants.find((x)=>x.name === "SEED_VAULT")?.value || "").replace(/"/g, "");
|
|
13092
13710
|
const SEED_ESCROW = (GlamProtocolIdlJson.constants.find((x)=>x.name === "SEED_ESCROW")?.value || "").replace(/"/g, "");
|
|
13093
|
-
const MARINADE_TICKET_SIZE = 88;
|
|
13094
13711
|
const STAKE_ACCOUNT_SIZE = 200;
|
|
13095
13712
|
const METEORA_POSITION_SIZE = 8120;
|
|
13096
13713
|
const KAMINO_OBTRIGATION_SIZE = 3344;
|
|
13714
|
+
const DRIFT_VAULT_DEPOSITOR_SIZE = 272;
|
|
13097
13715
|
const JITO_TIP_DEFAULT = new web3_js.PublicKey("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5");
|
|
13098
13716
|
const KAMINO_SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
|
|
13099
13717
|
const MARINADE_NATIVE_STAKE_AUTHORITY = new web3_js.PublicKey("stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq");
|
|
@@ -13111,6 +13729,7 @@ const JUP = new web3_js.PublicKey("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN")
|
|
|
13111
13729
|
* Program IDs
|
|
13112
13730
|
*/ const MARINADE_PROGRAM_ID = new web3_js.PublicKey("MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD");
|
|
13113
13731
|
const DRIFT_PROGRAM_ID = new web3_js.PublicKey("dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH");
|
|
13732
|
+
const DRIFT_VAULTS_PROGRAM_ID = new web3_js.PublicKey("vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR");
|
|
13114
13733
|
const JUPITER_PROGRAM_ID = new web3_js.PublicKey("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
|
|
13115
13734
|
const SANCTUM_STAKE_POOL_PROGRAM_ID = new web3_js.PublicKey("SP12tWFxD9oJsVWNavTTBZvMbA6gkAmxtVgxdqvyvhY");
|
|
13116
13735
|
const GOVERNANCE_PROGRAM_ID = new web3_js.PublicKey("GovaE4iu227srtG2s3tZzB4RmWBzw8sTwrCLZz7kN7rY");
|
|
@@ -13519,7 +14138,7 @@ var ClusterNetwork = /*#__PURE__*/ function(ClusterNetwork) {
|
|
|
13519
14138
|
return ClusterNetwork;
|
|
13520
14139
|
}({});
|
|
13521
14140
|
|
|
13522
|
-
const
|
|
14141
|
+
const findStakeAccounts = async (connection, withdrawAuthority)=>{
|
|
13523
14142
|
// stake authority offset: 12
|
|
13524
14143
|
// withdraw authority offset: 44
|
|
13525
14144
|
const accounts = await connection.getParsedProgramAccounts(web3_js.StakeProgram.programId, {
|
|
@@ -13586,43 +14205,6 @@ const getStakeAccountsWithStates = async (connection, withdrawAuthority)=>{
|
|
|
13586
14205
|
// order by lamports desc
|
|
13587
14206
|
return stakes.sort((a, b)=>b.lamports - a.lamports);
|
|
13588
14207
|
};
|
|
13589
|
-
const fetchMarinadeTicketAccounts = async (connection, beneficiary)=>await connection.getProgramAccounts(MARINADE_PROGRAM_ID, {
|
|
13590
|
-
filters: [
|
|
13591
|
-
{
|
|
13592
|
-
dataSize: MARINADE_TICKET_SIZE
|
|
13593
|
-
},
|
|
13594
|
-
{
|
|
13595
|
-
memcmp: {
|
|
13596
|
-
offset: 40,
|
|
13597
|
-
bytes: beneficiary.toBase58()
|
|
13598
|
-
}
|
|
13599
|
-
}
|
|
13600
|
-
]
|
|
13601
|
-
});
|
|
13602
|
-
const fetchKaminoObligations = async (connection, owner, market)=>{
|
|
13603
|
-
const accounts = await connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
|
|
13604
|
-
filters: [
|
|
13605
|
-
{
|
|
13606
|
-
dataSize: KAMINO_OBTRIGATION_SIZE
|
|
13607
|
-
},
|
|
13608
|
-
{
|
|
13609
|
-
memcmp: {
|
|
13610
|
-
offset: 64,
|
|
13611
|
-
bytes: owner.toBase58()
|
|
13612
|
-
}
|
|
13613
|
-
},
|
|
13614
|
-
...market ? [
|
|
13615
|
-
{
|
|
13616
|
-
memcmp: {
|
|
13617
|
-
offset: 32,
|
|
13618
|
-
bytes: market.toBase58()
|
|
13619
|
-
}
|
|
13620
|
-
}
|
|
13621
|
-
] : []
|
|
13622
|
-
]
|
|
13623
|
-
});
|
|
13624
|
-
return accounts.map((a)=>a.pubkey);
|
|
13625
|
-
};
|
|
13626
14208
|
const fetchMeteoraPositions = async (connection, owner)=>{
|
|
13627
14209
|
const accounts = await connection.getProgramAccounts(METEORA_DLMM_PROGRAM, {
|
|
13628
14210
|
filters: [
|
|
@@ -13679,6 +14261,22 @@ async function fetchLookupTables(connection, authority, firstEntry) {
|
|
|
13679
14261
|
// );
|
|
13680
14262
|
return [];
|
|
13681
14263
|
}
|
|
14264
|
+
/**
|
|
14265
|
+
* Parses program logs to extract error message
|
|
14266
|
+
*/ function parseProgramLogs(logs) {
|
|
14267
|
+
// "Error Message:" indicates an anchor program error
|
|
14268
|
+
// Other messages are manually sourced & handled
|
|
14269
|
+
const errorMsgLog = (logs || []).find((log)=>log.includes("Error Message:") || log.includes("Error: insufficient funds"));
|
|
14270
|
+
console.log("error message found in program logs", errorMsgLog);
|
|
14271
|
+
if (errorMsgLog) {
|
|
14272
|
+
if (errorMsgLog.includes("Error Message:")) {
|
|
14273
|
+
return errorMsgLog.split("Error Message:")[1].trim();
|
|
14274
|
+
} else {
|
|
14275
|
+
return "Insufficient funds";
|
|
14276
|
+
}
|
|
14277
|
+
}
|
|
14278
|
+
return "Unknown error";
|
|
14279
|
+
}
|
|
13682
14280
|
const getSimulationComputeUnits = async (connection, instructions, payer, lookupTables)=>{
|
|
13683
14281
|
const testInstructions = [
|
|
13684
14282
|
// Set an arbitrarily high number in simulation
|
|
@@ -13726,12 +14324,15 @@ const getErrorFromRPCResponse = (rpcResponse)=>{
|
|
|
13726
14324
|
const customErrorCode = instructionError[1]["Custom"];
|
|
13727
14325
|
const { errors: glamErrors } = GlamProtocolIdlJson;
|
|
13728
14326
|
const glamError = glamErrors.find((e)=>e.code === customErrorCode);
|
|
13729
|
-
|
|
13730
|
-
|
|
13731
|
-
|
|
14327
|
+
if (glamError?.msg) {
|
|
14328
|
+
throw new Error(glamError.msg);
|
|
14329
|
+
}
|
|
14330
|
+
// Unrecognized error code, try to parse program logs to get error message
|
|
14331
|
+
const errMsg = parseProgramLogs(rpcResponse.value.logs);
|
|
14332
|
+
throw new Error(errMsg);
|
|
13732
14333
|
}
|
|
13733
14334
|
}
|
|
13734
|
-
throw Error(error
|
|
14335
|
+
throw Error("Unknown error");
|
|
13735
14336
|
}
|
|
13736
14337
|
};
|
|
13737
14338
|
const setsAreEqual = (a, b)=>{
|
|
@@ -13743,14 +14344,19 @@ const setsAreEqual = (a, b)=>{
|
|
|
13743
14344
|
};
|
|
13744
14345
|
|
|
13745
14346
|
const STAKE_POOLS = sanctumLstList.LstList.filter((lst)=>!lst.name.includes("Sanctum Automated") && (lst.pool.program === "Spl" || lst.pool.program === "Marinade" || lst.pool.program === "SanctumSpl" || lst.pool.program === "SanctumSplMulti")).map((lst)=>{
|
|
13746
|
-
const { pool,
|
|
14347
|
+
const { pool, program } = lst.pool;
|
|
14348
|
+
const poolState = program === "Marinade" ? "8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC" : pool;
|
|
14349
|
+
if (!poolState) {
|
|
14350
|
+
throw new Error("Invalid pool state for LST: " + lst.name);
|
|
14351
|
+
}
|
|
13747
14352
|
return {
|
|
13748
14353
|
name: lst.name,
|
|
13749
14354
|
symbol: lst.symbol,
|
|
13750
14355
|
mint: lst.mint,
|
|
14356
|
+
decimals: lst.decimals,
|
|
13751
14357
|
logoURI: lst.logoUri,
|
|
13752
|
-
tokenProgram,
|
|
13753
|
-
poolState:
|
|
14358
|
+
tokenProgram: new web3_js.PublicKey(lst.tokenProgram),
|
|
14359
|
+
poolState: new web3_js.PublicKey(poolState)
|
|
13754
14360
|
};
|
|
13755
14361
|
});
|
|
13756
14362
|
const STAKE_POOLS_MAP = new Map(STAKE_POOLS.map((p)=>[
|
|
@@ -13901,6 +14507,7 @@ const ASSETS_MAINNET = new Map([
|
|
|
13901
14507
|
]);
|
|
13902
14508
|
const ASSETS_TESTS = new Map([]);
|
|
13903
14509
|
const SOL_ORACLE = ASSETS_MAINNET.get("So11111111111111111111111111111111111111112").oracle;
|
|
14510
|
+
const USDC_ORACLE = ASSETS_MAINNET.get("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v").oracle;
|
|
13904
14511
|
|
|
13905
14512
|
class GlamError extends Error {
|
|
13906
14513
|
constructor(message, rawError, programLogs){
|
|
@@ -14221,18 +14828,10 @@ class BaseClient {
|
|
|
14221
14828
|
const errTx = await connection.getTransaction(txSig, {
|
|
14222
14829
|
maxSupportedTransactionVersion: 0
|
|
14223
14830
|
});
|
|
14224
|
-
throw new GlamError(
|
|
14831
|
+
throw new GlamError(parseProgramLogs(errTx?.meta?.logMessages), errTx?.meta?.err || undefined, errTx?.meta?.logMessages || []);
|
|
14225
14832
|
}
|
|
14226
14833
|
return txSig;
|
|
14227
14834
|
}
|
|
14228
|
-
parseProgramLogs(logs) {
|
|
14229
|
-
const errorMsgLog = (logs || []).find((log)=>log.includes("Error Message:"));
|
|
14230
|
-
console.log("error message from program logs", errorMsgLog);
|
|
14231
|
-
if (errorMsgLog) {
|
|
14232
|
-
return errorMsgLog.split("Error Message:")[1].trim();
|
|
14233
|
-
}
|
|
14234
|
-
return "Unknown error";
|
|
14235
|
-
}
|
|
14236
14835
|
async getAdressLookupTableAccounts(keys) {
|
|
14237
14836
|
if (!keys) {
|
|
14238
14837
|
throw new Error("addressLookupTableAddresses is undefined");
|
|
@@ -15107,6 +15706,64 @@ SwapReduceOnly.Out = {
|
|
|
15107
15706
|
out: {}
|
|
15108
15707
|
};
|
|
15109
15708
|
|
|
15709
|
+
const DriftVaultLayout = borsh.struct([
|
|
15710
|
+
borsh.array(borsh.u8(), 8, "discriminator"),
|
|
15711
|
+
// Basic vault info
|
|
15712
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
15713
|
+
borsh.publicKey("pubkey"),
|
|
15714
|
+
borsh.publicKey("manager"),
|
|
15715
|
+
borsh.publicKey("tokenAccount"),
|
|
15716
|
+
borsh.publicKey("userStats"),
|
|
15717
|
+
borsh.publicKey("user"),
|
|
15718
|
+
borsh.publicKey("delegate"),
|
|
15719
|
+
borsh.publicKey("liquidationDelegate"),
|
|
15720
|
+
// Share accounting
|
|
15721
|
+
borsh.u128("userShares"),
|
|
15722
|
+
borsh.u128("totalShares"),
|
|
15723
|
+
// Timestamps
|
|
15724
|
+
borsh.i64("lastFeeUpdateTs"),
|
|
15725
|
+
borsh.i64("liquidationStartTs"),
|
|
15726
|
+
borsh.i64("redeemPeriod"),
|
|
15727
|
+
// Withdrawal tracking
|
|
15728
|
+
borsh.u64("totalWithdrawRequested"),
|
|
15729
|
+
// Capacity and fees
|
|
15730
|
+
borsh.u64("maxTokens"),
|
|
15731
|
+
borsh.i64("managementFee"),
|
|
15732
|
+
borsh.i64("initTs"),
|
|
15733
|
+
// Deposit/withdrawal accounting
|
|
15734
|
+
borsh.i64("netDeposits"),
|
|
15735
|
+
borsh.i64("managerNetDeposits"),
|
|
15736
|
+
borsh.u64("totalDeposits"),
|
|
15737
|
+
borsh.u64("totalWithdraws"),
|
|
15738
|
+
borsh.u64("managerTotalDeposits"),
|
|
15739
|
+
borsh.u64("managerTotalWithdraws"),
|
|
15740
|
+
borsh.i64("managerTotalFee"),
|
|
15741
|
+
borsh.i64("managerTotalProfitShare"),
|
|
15742
|
+
borsh.u64("minDepositAmount"),
|
|
15743
|
+
// Manager withdraw request
|
|
15744
|
+
borsh.struct([
|
|
15745
|
+
borsh.u128("shares"),
|
|
15746
|
+
borsh.u64("amount"),
|
|
15747
|
+
borsh.i64("ts")
|
|
15748
|
+
], "lastManagerWithdrawRequest"),
|
|
15749
|
+
// Configuration
|
|
15750
|
+
borsh.u32("sharesBase"),
|
|
15751
|
+
borsh.u32("profitShare"),
|
|
15752
|
+
borsh.u32("hurdleRate"),
|
|
15753
|
+
borsh.u16("spotMarketIndex"),
|
|
15754
|
+
borsh.u8("bump"),
|
|
15755
|
+
borsh.bool("permissioned"),
|
|
15756
|
+
borsh.bool("vaultProtocol"),
|
|
15757
|
+
borsh.u8("fuelDistributionMode"),
|
|
15758
|
+
borsh.u8("feeUpdateStatus"),
|
|
15759
|
+
borsh.u8("padding1"),
|
|
15760
|
+
borsh.u32("lastCumulativeFuelPerShareTs"),
|
|
15761
|
+
borsh.u128("cumulativeFuelPerShare"),
|
|
15762
|
+
borsh.u128("cumulativeFuel"),
|
|
15763
|
+
// Final padding
|
|
15764
|
+
borsh.array(borsh.u64(), 3, "padding")
|
|
15765
|
+
]);
|
|
15766
|
+
|
|
15110
15767
|
function readUnsignedBigInt64LE(buffer, offset) {
|
|
15111
15768
|
return new anchor.BN(buffer.subarray(offset, offset + 8), 10, "le");
|
|
15112
15769
|
}
|
|
@@ -15590,8 +16247,14 @@ class DriftClient {
|
|
|
15590
16247
|
}
|
|
15591
16248
|
});
|
|
15592
16249
|
}
|
|
15593
|
-
// At this point this.spotMarkets
|
|
15594
|
-
|
|
16250
|
+
// At this point this.spotMarkets should have all the requested markets
|
|
16251
|
+
// If not, it means some market indexes are invalid and we throw an error
|
|
16252
|
+
const spotMarkets = marketIndexes.map((marketIndex)=>this.spotMarkets.get(marketIndex)).filter((m)=>m);
|
|
16253
|
+
const invalidIndexes = marketIndexes.filter((marketIndex)=>!this.spotMarkets.has(marketIndex));
|
|
16254
|
+
if (invalidIndexes.length > 0) {
|
|
16255
|
+
console.warn(`The following spot markets could not be found: ${invalidIndexes.join(", ")}`);
|
|
16256
|
+
}
|
|
16257
|
+
return spotMarkets;
|
|
15595
16258
|
}
|
|
15596
16259
|
async fetchAndParsePerpMarket(marketIndex) {
|
|
15597
16260
|
const markets = await this.fetchAndParsePerpMarkets([
|
|
@@ -15621,7 +16284,12 @@ class DriftClient {
|
|
|
15621
16284
|
console.log("Requested perp markets already cached:", marketIndexes);
|
|
15622
16285
|
}
|
|
15623
16286
|
}
|
|
15624
|
-
|
|
16287
|
+
const perpMarkets = marketIndexes.map((marketIndex)=>this.perpMarkets.get(marketIndex)).filter((m)=>m);
|
|
16288
|
+
const invalidIndexes = marketIndexes.filter((marketIndex)=>!this.perpMarkets.has(marketIndex));
|
|
16289
|
+
if (invalidIndexes.length > 0) {
|
|
16290
|
+
console.warn(`The following perp markets could not be found: ${invalidIndexes.join(", ")}`);
|
|
16291
|
+
}
|
|
16292
|
+
return perpMarkets;
|
|
15625
16293
|
}
|
|
15626
16294
|
async fetchMarketConfigs() {
|
|
15627
16295
|
// const response = await fetch(
|
|
@@ -16039,47 +16707,231 @@ class DriftClient {
|
|
|
16039
16707
|
const tx = await this.base.program.methods.driftCancelOrdersByIds(orderIds).accounts({
|
|
16040
16708
|
glamState: this.base.statePda,
|
|
16041
16709
|
glamSigner,
|
|
16042
|
-
user,
|
|
16043
|
-
state: this.driftStatePda
|
|
16710
|
+
user,
|
|
16711
|
+
state: this.driftStatePda
|
|
16712
|
+
}).remainingAccounts(remainingAccounts).transaction();
|
|
16713
|
+
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16714
|
+
}
|
|
16715
|
+
async settlePnlTx(marketIndex, subAccountId = 0, txOptions = {}) {
|
|
16716
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16717
|
+
const { user } = this.getDriftUserPdas(subAccountId);
|
|
16718
|
+
const { vault: driftVault } = await this.fetchAndParseSpotMarket(0);
|
|
16719
|
+
const remainingAccounts = await this.composeRemainingAccounts(subAccountId, MarketType.PERP, marketIndex);
|
|
16720
|
+
// @ts-ignore
|
|
16721
|
+
const tx = await this.base.program.methods.driftSettlePnl(marketIndex).accounts({
|
|
16722
|
+
glamState: this.base.statePda,
|
|
16723
|
+
glamSigner,
|
|
16724
|
+
user,
|
|
16725
|
+
state: this.driftStatePda,
|
|
16726
|
+
spotMarketVault: driftVault
|
|
16727
|
+
}).remainingAccounts(remainingAccounts).transaction();
|
|
16728
|
+
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16729
|
+
}
|
|
16730
|
+
constructor(base){
|
|
16731
|
+
this.base = base;
|
|
16732
|
+
this.spotMarkets = new Map();
|
|
16733
|
+
this.perpMarkets = new Map();
|
|
16734
|
+
this.marketConfigs = null;
|
|
16735
|
+
this./*
|
|
16736
|
+
* Utils
|
|
16737
|
+
*/ getMarketPda = (marketType, marketIndex)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16738
|
+
Buffer.from(`${marketType === MarketType.PERP ? "perp" : "spot"}_market`),
|
|
16739
|
+
new anchor__namespace.BN(marketIndex).toArrayLike(Buffer, "le", 2)
|
|
16740
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
16741
|
+
this.getUserPda = (authority, subAccountId = 0)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16742
|
+
Buffer.from("user"),
|
|
16743
|
+
authority.toBuffer(),
|
|
16744
|
+
new anchor__namespace.BN(subAccountId).toArrayLike(Buffer, "le", 2)
|
|
16745
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
16746
|
+
this.getUserStatsPda = (authority)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16747
|
+
Buffer.from("user_stats"),
|
|
16748
|
+
authority.toBuffer()
|
|
16749
|
+
], DRIFT_PROGRAM_ID)[0];
|
|
16750
|
+
this.marketTypeEquals = (a, b)=>a && Object.keys(a)[0] === Object.keys(b)[0];
|
|
16751
|
+
}
|
|
16752
|
+
}
|
|
16753
|
+
class DriftVaultsClient {
|
|
16754
|
+
async fetchUserPositions(user) {
|
|
16755
|
+
const accountInfo = await this.base.provider.connection.getAccountInfo(user);
|
|
16756
|
+
if (!accountInfo) {
|
|
16757
|
+
throw new Error(`Drift user ${user} account not found for vault.`);
|
|
16758
|
+
}
|
|
16759
|
+
const { spotPositions, perpPositions } = decodeUser(accountInfo.data);
|
|
16760
|
+
return {
|
|
16761
|
+
perpPositions,
|
|
16762
|
+
spotPositions
|
|
16763
|
+
};
|
|
16764
|
+
}
|
|
16765
|
+
getDepositorPda(driftVault) {
|
|
16766
|
+
return web3_js.PublicKey.findProgramAddressSync([
|
|
16767
|
+
Buffer.from("vault_depositor"),
|
|
16768
|
+
driftVault.toBuffer(),
|
|
16769
|
+
this.base.vaultPda.toBuffer()
|
|
16770
|
+
], DRIFT_VAULTS_PROGRAM_ID)[0];
|
|
16771
|
+
}
|
|
16772
|
+
async parseDriftVault(driftVault) {
|
|
16773
|
+
const connection = this.base.provider.connection;
|
|
16774
|
+
const accountInfo = await connection.getAccountInfo(driftVault);
|
|
16775
|
+
if (!accountInfo) {
|
|
16776
|
+
throw new Error(`Drift vault account not found: ${driftVault.toBase58()}`);
|
|
16777
|
+
}
|
|
16778
|
+
try {
|
|
16779
|
+
return DriftVaultLayout.decode(accountInfo.data);
|
|
16780
|
+
} catch (error) {
|
|
16781
|
+
throw new Error(`Failed to parse drift vault account: ${error}`);
|
|
16782
|
+
}
|
|
16783
|
+
}
|
|
16784
|
+
async composeRemainingAccounts(user) {
|
|
16785
|
+
const { spotPositions, perpPositions } = await this.fetchUserPositions(user);
|
|
16786
|
+
const spotMarketIndexes = spotPositions.map((p)=>p.marketIndex);
|
|
16787
|
+
const perpMarketIndexes = perpPositions.map((p)=>p.marketIndex);
|
|
16788
|
+
// If there are perp positions, add spot market 0 as it's used as quote market for perp
|
|
16789
|
+
if (perpMarketIndexes.length > 0 && !spotMarketIndexes.includes(0)) {
|
|
16790
|
+
spotMarketIndexes.push(0);
|
|
16791
|
+
}
|
|
16792
|
+
const spotMarkets = await this.drift.fetchAndParseSpotMarkets(spotMarketIndexes);
|
|
16793
|
+
const perpMarkets = await this.drift.fetchAndParsePerpMarkets(perpMarketIndexes);
|
|
16794
|
+
const oracles = spotMarkets.map((m)=>m.oracle).concat(perpMarkets.map((m)=>m.oracle));
|
|
16795
|
+
const markets = spotMarkets.map((m)=>m.marketPda).concat(perpMarkets.map((m)=>m.marketPda));
|
|
16796
|
+
return oracles.map((o)=>({
|
|
16797
|
+
pubkey: new web3_js.PublicKey(o),
|
|
16798
|
+
isWritable: false,
|
|
16799
|
+
isSigner: false
|
|
16800
|
+
})).concat(markets.map((m)=>({
|
|
16801
|
+
pubkey: new web3_js.PublicKey(m),
|
|
16802
|
+
isWritable: true,
|
|
16803
|
+
isSigner: false
|
|
16804
|
+
})));
|
|
16805
|
+
}
|
|
16806
|
+
parseDepositor(depositor, data) {
|
|
16807
|
+
const driftVault = new web3_js.PublicKey(data.subarray(8, 40));
|
|
16808
|
+
const shares = new anchor.BN(data.subarray(104, 112), "le");
|
|
16809
|
+
return {
|
|
16810
|
+
address: depositor,
|
|
16811
|
+
driftVault,
|
|
16812
|
+
shares
|
|
16813
|
+
};
|
|
16814
|
+
}
|
|
16815
|
+
/**
|
|
16816
|
+
* Finds all drift vault depositors
|
|
16817
|
+
*/ async findAndParseVaultDepositors(authority) {
|
|
16818
|
+
const accounts = await this.base.provider.connection.getProgramAccounts(DRIFT_VAULTS_PROGRAM_ID, {
|
|
16819
|
+
filters: [
|
|
16820
|
+
{
|
|
16821
|
+
dataSize: DRIFT_VAULT_DEPOSITOR_SIZE
|
|
16822
|
+
},
|
|
16823
|
+
{
|
|
16824
|
+
memcmp: {
|
|
16825
|
+
offset: 72,
|
|
16826
|
+
bytes: (authority || this.base.vaultPda).toBase58()
|
|
16827
|
+
}
|
|
16828
|
+
}
|
|
16829
|
+
]
|
|
16830
|
+
});
|
|
16831
|
+
return accounts.map((a)=>this.parseDepositor(a.pubkey, a.account.data));
|
|
16832
|
+
}
|
|
16833
|
+
async initializeVaultDepositor(driftVault, txOptions = {}) {
|
|
16834
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16835
|
+
const vaultDepositor = this.getDepositorPda(driftVault);
|
|
16836
|
+
const tx = await this.base.program.methods.driftVaultsInitializeVaultDepositor().accounts({
|
|
16837
|
+
glamState: this.base.statePda,
|
|
16838
|
+
glamSigner,
|
|
16839
|
+
vault: driftVault,
|
|
16840
|
+
vaultDepositor
|
|
16841
|
+
}).transaction();
|
|
16842
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16843
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16844
|
+
}
|
|
16845
|
+
async deposit(driftVault, amount, txOptions = {}) {
|
|
16846
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16847
|
+
const vaultDepositor = this.getDepositorPda(driftVault);
|
|
16848
|
+
const { user: driftUser, tokenAccount: vaultTokenAccount, userStats: driftUserStats, spotMarketIndex, vaultProtocol } = await this.parseDriftVault(driftVault);
|
|
16849
|
+
if (vaultProtocol) {
|
|
16850
|
+
throw new Error("Vault protocol fees not supported");
|
|
16851
|
+
}
|
|
16852
|
+
const { vault: driftSpotMarketVault, mint, tokenProgram } = await this.drift.fetchAndParseSpotMarket(spotMarketIndex);
|
|
16853
|
+
const remainingAccounts = await this.composeRemainingAccounts(driftUser);
|
|
16854
|
+
// GLAM vault's token account for deposit, we assume it exists
|
|
16855
|
+
const userTokenAccount = this.base.getVaultAta(mint, tokenProgram);
|
|
16856
|
+
const tx = await this.base.program.methods.driftVaultsDeposit(amount).accounts({
|
|
16857
|
+
glamState: this.base.statePda,
|
|
16858
|
+
glamSigner,
|
|
16859
|
+
vault: driftVault,
|
|
16860
|
+
vaultDepositor,
|
|
16861
|
+
vaultTokenAccount,
|
|
16862
|
+
driftUserStats,
|
|
16863
|
+
driftUser,
|
|
16864
|
+
driftState: this.drift.driftStatePda,
|
|
16865
|
+
driftSpotMarketVault,
|
|
16866
|
+
userTokenAccount,
|
|
16867
|
+
tokenProgram,
|
|
16868
|
+
driftProgram: DRIFT_PROGRAM_ID
|
|
16869
|
+
}).remainingAccounts(remainingAccounts).transaction();
|
|
16870
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16871
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16872
|
+
}
|
|
16873
|
+
async requestWithdraw(driftVault, amount, txOptions = {}) {
|
|
16874
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16875
|
+
const vaultDepositor = this.getDepositorPda(driftVault);
|
|
16876
|
+
const { user: driftUser, userStats: driftUserStats } = await this.parseDriftVault(driftVault);
|
|
16877
|
+
const remainingAccounts = await this.composeRemainingAccounts(driftUser);
|
|
16878
|
+
const tx = await this.base.program.methods.driftVaultsRequestWithdraw(amount, {
|
|
16879
|
+
shares: {}
|
|
16880
|
+
}).accounts({
|
|
16881
|
+
glamState: this.base.statePda,
|
|
16882
|
+
glamSigner,
|
|
16883
|
+
vault: driftVault,
|
|
16884
|
+
vaultDepositor,
|
|
16885
|
+
driftUserStats,
|
|
16886
|
+
driftUser
|
|
16887
|
+
}).remainingAccounts(remainingAccounts).transaction();
|
|
16888
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16889
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16890
|
+
}
|
|
16891
|
+
async cancelWithdrawRequest(driftVault, txOptions = {}) {
|
|
16892
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16893
|
+
const vaultDepositor = this.getDepositorPda(driftVault);
|
|
16894
|
+
const { user: driftUser, userStats: driftUserStats } = await this.parseDriftVault(driftVault);
|
|
16895
|
+
const remainingAccounts = await this.composeRemainingAccounts(driftUser);
|
|
16896
|
+
const tx = await this.base.program.methods.driftVaultsCancelRequestWithdraw().accounts({
|
|
16897
|
+
glamState: this.base.statePda,
|
|
16898
|
+
glamSigner,
|
|
16899
|
+
vault: driftVault,
|
|
16900
|
+
vaultDepositor,
|
|
16901
|
+
driftUserStats,
|
|
16902
|
+
driftUser
|
|
16044
16903
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
16045
|
-
|
|
16904
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16905
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16046
16906
|
}
|
|
16047
|
-
async
|
|
16907
|
+
async withdraw(driftVault, txOptions = {}) {
|
|
16048
16908
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16049
|
-
const
|
|
16050
|
-
const {
|
|
16051
|
-
const
|
|
16052
|
-
|
|
16053
|
-
const
|
|
16909
|
+
const vaultDepositor = this.getDepositorPda(driftVault);
|
|
16910
|
+
const { user: driftUser, userStats: driftUserStats, tokenAccount: vaultTokenAccount, spotMarketIndex } = await this.parseDriftVault(driftVault);
|
|
16911
|
+
const { vault: driftSpotMarketVault, mint, tokenProgram } = await this.drift.fetchAndParseSpotMarket(spotMarketIndex);
|
|
16912
|
+
const userTokenAccount = this.base.getVaultAta(mint, tokenProgram);
|
|
16913
|
+
const remainingAccounts = await this.composeRemainingAccounts(driftUser);
|
|
16914
|
+
const tx = await this.base.program.methods.driftVaultsWithdraw().accounts({
|
|
16054
16915
|
glamState: this.base.statePda,
|
|
16055
16916
|
glamSigner,
|
|
16056
|
-
|
|
16057
|
-
|
|
16058
|
-
|
|
16917
|
+
vault: driftVault,
|
|
16918
|
+
vaultDepositor,
|
|
16919
|
+
vaultTokenAccount,
|
|
16920
|
+
driftUserStats,
|
|
16921
|
+
driftUser,
|
|
16922
|
+
driftSpotMarketVault,
|
|
16923
|
+
driftSigner: DRIFT_SIGNER,
|
|
16924
|
+
userTokenAccount,
|
|
16925
|
+
driftState: this.drift.driftStatePda,
|
|
16926
|
+
driftProgram: DRIFT_PROGRAM_ID,
|
|
16927
|
+
tokenProgram
|
|
16059
16928
|
}).remainingAccounts(remainingAccounts).transaction();
|
|
16060
|
-
|
|
16929
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16930
|
+
return await this.base.sendAndConfirm(vTx);
|
|
16061
16931
|
}
|
|
16062
|
-
constructor(base){
|
|
16932
|
+
constructor(base, drift){
|
|
16063
16933
|
this.base = base;
|
|
16064
|
-
this.
|
|
16065
|
-
this.perpMarkets = new Map();
|
|
16066
|
-
this.marketConfigs = null;
|
|
16067
|
-
this./*
|
|
16068
|
-
* Utils
|
|
16069
|
-
*/ getMarketPda = (marketType, marketIndex)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16070
|
-
Buffer.from(`${marketType === MarketType.PERP ? "perp" : "spot"}_market`),
|
|
16071
|
-
new anchor__namespace.BN(marketIndex).toArrayLike(Buffer, "le", 2)
|
|
16072
|
-
], DRIFT_PROGRAM_ID)[0];
|
|
16073
|
-
this.getUserPda = (authority, subAccountId = 0)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16074
|
-
Buffer.from("user"),
|
|
16075
|
-
authority.toBuffer(),
|
|
16076
|
-
new anchor__namespace.BN(subAccountId).toArrayLike(Buffer, "le", 2)
|
|
16077
|
-
], DRIFT_PROGRAM_ID)[0];
|
|
16078
|
-
this.getUserStatsPda = (authority)=>web3_js.PublicKey.findProgramAddressSync([
|
|
16079
|
-
Buffer.from("user_stats"),
|
|
16080
|
-
authority.toBuffer()
|
|
16081
|
-
], DRIFT_PROGRAM_ID)[0];
|
|
16082
|
-
this.marketTypeEquals = (a, b)=>a && Object.keys(a)[0] === Object.keys(b)[0];
|
|
16934
|
+
this.drift = drift;
|
|
16083
16935
|
}
|
|
16084
16936
|
}
|
|
16085
16937
|
|
|
@@ -16153,8 +17005,8 @@ class JupiterSwapClient {
|
|
|
16153
17005
|
this.getTokenProgram(inputMint),
|
|
16154
17006
|
this.getTokenProgram(outputMint)
|
|
16155
17007
|
]);
|
|
16156
|
-
const inputStakePool =
|
|
16157
|
-
const outputStakePool =
|
|
17008
|
+
const inputStakePool = STAKE_POOLS_MAP.get(inputMint.toBase58())?.poolState || null;
|
|
17009
|
+
const outputStakePool = STAKE_POOLS_MAP.get(outputMint.toBase58())?.poolState || null;
|
|
16158
17010
|
const preInstructions = await this.getPreInstructions(glamSigner, inputMint, outputMint, amount, inputTokenProgram, outputTokenProgram);
|
|
16159
17011
|
// @ts-ignore
|
|
16160
17012
|
const tx = await this.base.program.methods.jupiterSwap(swapIx.data).accounts({
|
|
@@ -16492,45 +17344,15 @@ class MarinadeClient {
|
|
|
16492
17344
|
const tx = await this.depositStakeAccountTx(stakeAccount, {});
|
|
16493
17345
|
return await this.base.sendAndConfirm(tx);
|
|
16494
17346
|
}
|
|
16495
|
-
async withdrawStakeAccount(amount, txOptions = {}) {
|
|
16496
|
-
const [tx, extraSigner] = await this.withdrawStakeAccountTx(amount, txOptions);
|
|
17347
|
+
async withdrawStakeAccount(amount, deactivate = false, txOptions = {}) {
|
|
17348
|
+
const [tx, extraSigner] = await this.withdrawStakeAccountTx(amount, deactivate, txOptions);
|
|
16497
17349
|
return await this.base.sendAndConfirm(tx, [
|
|
16498
17350
|
extraSigner
|
|
16499
17351
|
]);
|
|
16500
17352
|
}
|
|
16501
|
-
async orderUnstake(amount, txOptions = {}) {
|
|
16502
|
-
const tx = await this.orderUnstakeTx(amount, txOptions);
|
|
16503
|
-
return await this.base.sendAndConfirm(tx);
|
|
16504
|
-
}
|
|
16505
|
-
async claim(tickets, txOptions = {}) {
|
|
16506
|
-
const tx = await this.claimTx(tickets, txOptions);
|
|
16507
|
-
return await this.base.sendAndConfirm(tx);
|
|
16508
|
-
}
|
|
16509
17353
|
/*
|
|
16510
17354
|
* Utils
|
|
16511
|
-
*/
|
|
16512
|
-
const vault = this.base.vaultPda;
|
|
16513
|
-
const accounts = await fetchMarinadeTicketAccounts(this.base.provider.connection, vault);
|
|
16514
|
-
return accounts.map((a)=>a.pubkey);
|
|
16515
|
-
}
|
|
16516
|
-
async getParsedTickets() {
|
|
16517
|
-
const vault = this.base.vaultPda;
|
|
16518
|
-
const accounts = await fetchMarinadeTicketAccounts(this.base.provider.connection, vault);
|
|
16519
|
-
const currentEpoch = await this.base.provider.connection.getEpochInfo();
|
|
16520
|
-
return accounts.map((a)=>{
|
|
16521
|
-
const lamports = Number(a.account.data.readBigInt64LE(72));
|
|
16522
|
-
const createdEpoch = Number(a.account.data.readBigInt64LE(80));
|
|
16523
|
-
const isDue = currentEpoch.epoch > createdEpoch;
|
|
16524
|
-
return {
|
|
16525
|
-
address: a.pubkey,
|
|
16526
|
-
lamports,
|
|
16527
|
-
createdEpoch,
|
|
16528
|
-
isDue,
|
|
16529
|
-
isClaimable: isDue && currentEpoch.slotIndex > 5000
|
|
16530
|
-
};
|
|
16531
|
-
});
|
|
16532
|
-
}
|
|
16533
|
-
/**
|
|
17355
|
+
*/ /**
|
|
16534
17356
|
* @deprecated Use Marinade.getMarinadeState() instead
|
|
16535
17357
|
*/ get marinadeStateStatic() {
|
|
16536
17358
|
// The addresses are the same in mainnet and devnet:
|
|
@@ -16692,7 +17514,7 @@ class MarinadeClient {
|
|
|
16692
17514
|
validatorIndex
|
|
16693
17515
|
};
|
|
16694
17516
|
}
|
|
16695
|
-
async withdrawStakeAccountTx(amount, txOptions) {
|
|
17517
|
+
async withdrawStakeAccountTx(amount, deactivate = false, txOptions) {
|
|
16696
17518
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16697
17519
|
const marinadeState = await this.fetchMarinadeState();
|
|
16698
17520
|
// Get mariande stake withdraw authority
|
|
@@ -16706,6 +17528,13 @@ class MarinadeClient {
|
|
|
16706
17528
|
const { stakeIndex, validatorIndex } = await this.getIndexes(stakeAccounts[0], stakeList, validatorList);
|
|
16707
17529
|
const burnMsolFrom = this.base.getVaultAta(MSOL);
|
|
16708
17530
|
const newStake = web3_js.Keypair.generate();
|
|
17531
|
+
const postInstructions = deactivate ? [
|
|
17532
|
+
await this.base.program.methods.stakeDeactivate().accounts({
|
|
17533
|
+
glamSigner,
|
|
17534
|
+
glamState: this.base.statePda,
|
|
17535
|
+
stake: newStake.publicKey
|
|
17536
|
+
}).instruction()
|
|
17537
|
+
] : [];
|
|
16709
17538
|
const tx = await this.base.program.methods.marinadeWithdrawStakeAccount(stakeIndex, validatorIndex, amount, this.base.vaultPda).accounts({
|
|
16710
17539
|
glamState: this.base.statePda,
|
|
16711
17540
|
glamSigner,
|
|
@@ -16722,61 +17551,13 @@ class MarinadeClient {
|
|
|
16722
17551
|
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
16723
17552
|
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
|
16724
17553
|
stakeProgram: web3_js.StakeProgram.programId
|
|
16725
|
-
}).transaction();
|
|
17554
|
+
}).postInstructions(postInstructions).transaction();
|
|
16726
17555
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16727
17556
|
return [
|
|
16728
17557
|
vTx,
|
|
16729
17558
|
newStake
|
|
16730
17559
|
];
|
|
16731
17560
|
}
|
|
16732
|
-
async orderUnstakeTx(amount, txOptions) {
|
|
16733
|
-
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16734
|
-
const marinadeState = this.marinadeStateStatic;
|
|
16735
|
-
const vaultMsolAta = this.base.getVaultAta(marinadeState.msolMintAddress);
|
|
16736
|
-
const ticketSeed = Date.now().toString();
|
|
16737
|
-
const ticket = await web3_js.PublicKey.createWithSeed(glamSigner, ticketSeed, MARINADE_PROGRAM_ID);
|
|
16738
|
-
const lamports = await this.base.provider.connection.getMinimumBalanceForRentExemption(MARINADE_TICKET_SIZE);
|
|
16739
|
-
const createTicketIx = web3_js.SystemProgram.createAccountWithSeed({
|
|
16740
|
-
fromPubkey: glamSigner,
|
|
16741
|
-
newAccountPubkey: ticket,
|
|
16742
|
-
basePubkey: glamSigner,
|
|
16743
|
-
seed: ticketSeed,
|
|
16744
|
-
lamports,
|
|
16745
|
-
space: MARINADE_TICKET_SIZE,
|
|
16746
|
-
programId: MARINADE_PROGRAM_ID
|
|
16747
|
-
});
|
|
16748
|
-
const tx = await this.base.program.methods.marinadeOrderUnstake(amount).accounts({
|
|
16749
|
-
glamState: this.base.statePda,
|
|
16750
|
-
glamSigner,
|
|
16751
|
-
newTicketAccount: ticket,
|
|
16752
|
-
msolMint: marinadeState.msolMintAddress,
|
|
16753
|
-
burnMsolFrom: vaultMsolAta,
|
|
16754
|
-
state: marinadeState.marinadeStateAddress,
|
|
16755
|
-
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
16756
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID
|
|
16757
|
-
}).preInstructions([
|
|
16758
|
-
createTicketIx
|
|
16759
|
-
]).transaction();
|
|
16760
|
-
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16761
|
-
}
|
|
16762
|
-
async claimTx(tickets, txOptions) {
|
|
16763
|
-
if (tickets.length < 1) {
|
|
16764
|
-
throw new Error("At least one ticket is required");
|
|
16765
|
-
}
|
|
16766
|
-
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
16767
|
-
const marinadeState = this.marinadeStateStatic;
|
|
16768
|
-
const instructions = await Promise.all(tickets.map((ticket)=>this.base.program.methods.marinadeClaim().accounts({
|
|
16769
|
-
glamState: this.base.statePda,
|
|
16770
|
-
glamSigner,
|
|
16771
|
-
ticketAccount: ticket,
|
|
16772
|
-
state: marinadeState.marinadeStateAddress,
|
|
16773
|
-
reservePda: marinadeState.reserveAddress,
|
|
16774
|
-
clock: web3_js.SYSVAR_CLOCK_PUBKEY
|
|
16775
|
-
}).instruction()));
|
|
16776
|
-
const tx = new web3_js.Transaction();
|
|
16777
|
-
tx.add(...instructions);
|
|
16778
|
-
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
16779
|
-
}
|
|
16780
17561
|
constructor(base){
|
|
16781
17562
|
this.base = base;
|
|
16782
17563
|
}
|
|
@@ -16968,20 +17749,17 @@ class VaultClient {
|
|
|
16968
17749
|
class StakingClient {
|
|
16969
17750
|
/*
|
|
16970
17751
|
* Client methods
|
|
16971
|
-
*/ async unstake(asset, amount, txOptions = {}) {
|
|
16972
|
-
const assetStr = asset.toBase58();
|
|
17752
|
+
*/ async unstake(asset, amount, deactivate = false, txOptions = {}) {
|
|
16973
17753
|
// mSOL
|
|
16974
|
-
if (
|
|
16975
|
-
|
|
16976
|
-
return await this.base.sendAndConfirm(tx);
|
|
17754
|
+
if (asset.equals(MSOL)) {
|
|
17755
|
+
return await this.marinade.withdrawStakeAccount(new anchor.BN(amount), deactivate, txOptions);
|
|
16977
17756
|
}
|
|
16978
17757
|
// Other LSTs
|
|
16979
|
-
const
|
|
16980
|
-
if (!
|
|
16981
|
-
throw new Error(
|
|
17758
|
+
const stakePool = STAKE_POOLS.find((p)=>p.mint === asset.toBase58());
|
|
17759
|
+
if (!stakePool) {
|
|
17760
|
+
throw new Error(`LST not supported: ${asset}`);
|
|
16982
17761
|
}
|
|
16983
|
-
|
|
16984
|
-
return await this.base.sendAndConfirm(tx);
|
|
17762
|
+
return await this.stakePoolWithdrawStake(stakePool.poolState, new anchor.BN(amount), deactivate, txOptions);
|
|
16985
17763
|
}
|
|
16986
17764
|
async stakePoolDepositSol(stakePool, amount, txOptions = {}) {
|
|
16987
17765
|
const tx = await this.stakePoolDepositSolTx(stakePool, amount, txOptions);
|
|
@@ -16991,8 +17769,8 @@ class StakingClient {
|
|
|
16991
17769
|
const tx = await this.stakePoolDepositStakeTx(stakePool, stakeAccount, txOptions);
|
|
16992
17770
|
return await this.base.sendAndConfirm(tx);
|
|
16993
17771
|
}
|
|
16994
|
-
async stakePoolWithdrawStake(stakePool, amount, txOptions = {}) {
|
|
16995
|
-
const tx = await this.stakePoolWithdrawStakeTx(stakePool, amount,
|
|
17772
|
+
async stakePoolWithdrawStake(stakePool, amount, deactivate = false, txOptions = {}) {
|
|
17773
|
+
const tx = await this.stakePoolWithdrawStakeTx(stakePool, amount, deactivate, txOptions);
|
|
16996
17774
|
return await this.base.sendAndConfirm(tx);
|
|
16997
17775
|
}
|
|
16998
17776
|
async initializeAndDelegateStake(vote, amount, txOptions = {}) {
|
|
@@ -17210,11 +17988,9 @@ class StakingClient {
|
|
|
17210
17988
|
async stakePoolWithdrawStakeTx(stakePool, amount, deactivate = false, txOptions = {}) {
|
|
17211
17989
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17212
17990
|
const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, tokenProgramId: tokenProgram, validatorList, reserveStake } = await this.getStakePoolAccountData(stakePool);
|
|
17213
|
-
this.base.vaultPda;
|
|
17214
17991
|
const poolTokensFrom = this.base.getVaultAta(poolMint, tokenProgram);
|
|
17215
17992
|
// The reserve stake account should NOT be used for withdrawals unless we have no other options.
|
|
17216
17993
|
const validatorStakeCandidates = (await getStakeAccountsWithStates(this.base.provider.connection, withdrawAuthority)).filter((s)=>!s.address.equals(reserveStake));
|
|
17217
|
-
console.log("validatorStakeCandidates", validatorStakeCandidates);
|
|
17218
17994
|
const validatorStakeAccount = validatorStakeCandidates.length === 0 ? reserveStake : validatorStakeCandidates[0].address;
|
|
17219
17995
|
const [stakeAccount, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
|
|
17220
17996
|
const postInstructions = deactivate ? [
|
|
@@ -17466,6 +18242,14 @@ class StateClient {
|
|
|
17466
18242
|
}).preInstructions(txOptions.preInstructions || []).transaction();
|
|
17467
18243
|
return await this.base.intoVersionedTransaction(tx, txOptions);
|
|
17468
18244
|
}
|
|
18245
|
+
async extend(newBytes, txOptions = {}) {
|
|
18246
|
+
const tx = await this.base.program.methods.extendState(newBytes).accounts({
|
|
18247
|
+
glamState: this.base.statePda,
|
|
18248
|
+
glamSigner: this.base.signer
|
|
18249
|
+
}).transaction();
|
|
18250
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18251
|
+
return await this.base.sendAndConfirm(vTx);
|
|
18252
|
+
}
|
|
17469
18253
|
async close(txOptions = {}) {
|
|
17470
18254
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
17471
18255
|
const tx = await this.base.program.methods.closeState().accounts({
|
|
@@ -18024,7 +18808,7 @@ function refreshObligationFarmsForReserve(args, accounts, programId = KAMINO_LEN
|
|
|
18024
18808
|
const data = Buffer.concat([
|
|
18025
18809
|
identifier,
|
|
18026
18810
|
buffer
|
|
18027
|
-
]).
|
|
18811
|
+
]).subarray(0, 8 + len);
|
|
18028
18812
|
const ix = new web3_js.TransactionInstruction({
|
|
18029
18813
|
keys,
|
|
18030
18814
|
programId,
|
|
@@ -18123,21 +18907,6 @@ class KaminoLendingClient {
|
|
|
18123
18907
|
], KAMINO_FARM_PROGRAM);
|
|
18124
18908
|
return obligationFarm;
|
|
18125
18909
|
}
|
|
18126
|
-
async initUserMetadataTx(txOptions = {}) {
|
|
18127
|
-
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
18128
|
-
const vault = this.base.vaultPda;
|
|
18129
|
-
const userMetadata = this.getUserMetadataPda(vault);
|
|
18130
|
-
const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
|
|
18131
|
-
// @ts-ignore
|
|
18132
|
-
const tx = await this.base.program.methods.kaminoLendingInitUserMetadata(lookupTable).accounts({
|
|
18133
|
-
glamState: this.base.statePda,
|
|
18134
|
-
glamSigner,
|
|
18135
|
-
userMetadata,
|
|
18136
|
-
referrerUserMetadata: null
|
|
18137
|
-
}).transaction();
|
|
18138
|
-
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
18139
|
-
return vTx;
|
|
18140
|
-
}
|
|
18141
18910
|
refreshReserveIxs(lendingMarket, reserves) {
|
|
18142
18911
|
return reserves.map((reserve)=>refreshReserve({
|
|
18143
18912
|
reserve,
|
|
@@ -18235,26 +19004,7 @@ class KaminoLendingClient {
|
|
|
18235
19004
|
feeVault
|
|
18236
19005
|
};
|
|
18237
19006
|
}
|
|
18238
|
-
|
|
18239
|
-
* Fetches and parses obligation account
|
|
18240
|
-
*
|
|
18241
|
-
* @param obligation User obligation pubkey
|
|
18242
|
-
* @returns Pubkeys of reserves for deposits and borrows
|
|
18243
|
-
*/ async fetchAndParseObligation(obligation) {
|
|
18244
|
-
const cached = this.obligations.get(obligation);
|
|
18245
|
-
if (cached) {
|
|
18246
|
-
return cached;
|
|
18247
|
-
}
|
|
18248
|
-
const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
|
|
18249
|
-
if (!obligationAccount) {
|
|
18250
|
-
return {
|
|
18251
|
-
address: obligation,
|
|
18252
|
-
lendingMarket: null,
|
|
18253
|
-
deposits: [],
|
|
18254
|
-
borrows: []
|
|
18255
|
-
};
|
|
18256
|
-
}
|
|
18257
|
-
const data = obligationAccount.data;
|
|
19007
|
+
parseObligation(obligation, data) {
|
|
18258
19008
|
const lendingMarket = new web3_js.PublicKey(data.subarray(32, 64));
|
|
18259
19009
|
// read deposits
|
|
18260
19010
|
let depositsOffset = 96;
|
|
@@ -18284,21 +19034,40 @@ class KaminoLendingClient {
|
|
|
18284
19034
|
reserve
|
|
18285
19035
|
};
|
|
18286
19036
|
}).filter((d)=>!d.reserve.equals(web3_js.PublicKey.default));
|
|
18287
|
-
|
|
19037
|
+
return {
|
|
18288
19038
|
address: obligation,
|
|
18289
19039
|
lendingMarket,
|
|
18290
19040
|
deposits,
|
|
18291
19041
|
borrows
|
|
18292
19042
|
};
|
|
19043
|
+
}
|
|
19044
|
+
/**
|
|
19045
|
+
* Fetches and parses an obligation account
|
|
19046
|
+
*/ async fetchAndParseObligation(obligation) {
|
|
19047
|
+
const cached = this.obligations.get(obligation);
|
|
19048
|
+
if (cached) {
|
|
19049
|
+
return cached;
|
|
19050
|
+
}
|
|
19051
|
+
const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
|
|
19052
|
+
if (!obligationAccount) {
|
|
19053
|
+
return {
|
|
19054
|
+
address: obligation,
|
|
19055
|
+
lendingMarket: null,
|
|
19056
|
+
deposits: [],
|
|
19057
|
+
borrows: []
|
|
19058
|
+
};
|
|
19059
|
+
}
|
|
19060
|
+
const parsedObligation = this.parseObligation(obligation, obligationAccount.data);
|
|
18293
19061
|
this.obligations.set(obligation, parsedObligation);
|
|
18294
19062
|
return parsedObligation;
|
|
18295
19063
|
}
|
|
18296
|
-
|
|
19064
|
+
parseReserveAccount(reserve, data) {
|
|
18297
19065
|
const market = new web3_js.PublicKey(data.subarray(32, 64));
|
|
18298
19066
|
const farmCollateral = new web3_js.PublicKey(data.subarray(64, 96));
|
|
18299
19067
|
const farmDebt = new web3_js.PublicKey(data.subarray(96, 128));
|
|
18300
19068
|
const liquidityMint = new web3_js.PublicKey(data.subarray(128, 160));
|
|
18301
19069
|
return {
|
|
19070
|
+
address: reserve,
|
|
18302
19071
|
farmCollateral: farmCollateral.equals(web3_js.PublicKey.default) ? null : farmCollateral,
|
|
18303
19072
|
farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
|
|
18304
19073
|
liquidityMint,
|
|
@@ -18314,10 +19083,7 @@ class KaminoLendingClient {
|
|
|
18314
19083
|
throw new Error("Not all reserves can be found");
|
|
18315
19084
|
}
|
|
18316
19085
|
return reserveAccounts.filter((a)=>!!a).map((account, i)=>{
|
|
18317
|
-
const parsedReserve =
|
|
18318
|
-
address: reserves[i],
|
|
18319
|
-
...this._parseReserveAccount(account.data)
|
|
18320
|
-
};
|
|
19086
|
+
const parsedReserve = this.parseReserveAccount(reserves[i], account.data);
|
|
18321
19087
|
this.reserves.set(reserves[i], parsedReserve);
|
|
18322
19088
|
return parsedReserve;
|
|
18323
19089
|
});
|
|
@@ -18345,14 +19111,55 @@ class KaminoLendingClient {
|
|
|
18345
19111
|
if (accounts.length === 0) {
|
|
18346
19112
|
throw new Error("Reserve not found");
|
|
18347
19113
|
}
|
|
18348
|
-
const
|
|
18349
|
-
|
|
18350
|
-
address: account.pubkey,
|
|
18351
|
-
...this._parseReserveAccount(account.account.data)
|
|
18352
|
-
};
|
|
18353
|
-
this.reserves.set(account.pubkey, parsedReserve);
|
|
19114
|
+
const parsedReserve = this.parseReserveAccount(accounts[0].pubkey, accounts[0].account.data);
|
|
19115
|
+
this.reserves.set(accounts[0].pubkey, parsedReserve);
|
|
18354
19116
|
return parsedReserve;
|
|
18355
19117
|
}
|
|
19118
|
+
/**
|
|
19119
|
+
* Finds and parses Kamino obligations for a given owner and market (optional)
|
|
19120
|
+
*/ async findAndParseObligations(owner, market) {
|
|
19121
|
+
const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
|
|
19122
|
+
filters: [
|
|
19123
|
+
{
|
|
19124
|
+
dataSize: KAMINO_OBTRIGATION_SIZE
|
|
19125
|
+
},
|
|
19126
|
+
{
|
|
19127
|
+
memcmp: {
|
|
19128
|
+
offset: 64,
|
|
19129
|
+
bytes: owner.toBase58()
|
|
19130
|
+
}
|
|
19131
|
+
},
|
|
19132
|
+
...market ? [
|
|
19133
|
+
{
|
|
19134
|
+
memcmp: {
|
|
19135
|
+
offset: 32,
|
|
19136
|
+
bytes: market.toBase58()
|
|
19137
|
+
}
|
|
19138
|
+
}
|
|
19139
|
+
] : []
|
|
19140
|
+
]
|
|
19141
|
+
});
|
|
19142
|
+
// Parse obligations and cache them
|
|
19143
|
+
return accounts.map((a)=>{
|
|
19144
|
+
const parsedObligation = this.parseObligation(a.pubkey, a.account.data);
|
|
19145
|
+
this.obligations.set(a.pubkey, parsedObligation);
|
|
19146
|
+
return parsedObligation;
|
|
19147
|
+
});
|
|
19148
|
+
}
|
|
19149
|
+
async initUserMetadataTx(txOptions = {}) {
|
|
19150
|
+
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
19151
|
+
const vault = this.base.vaultPda;
|
|
19152
|
+
const userMetadata = this.getUserMetadataPda(vault);
|
|
19153
|
+
const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
|
|
19154
|
+
const tx = await this.base.program.methods.kaminoLendingInitUserMetadata(lookupTable).accounts({
|
|
19155
|
+
glamState: this.base.statePda,
|
|
19156
|
+
glamSigner,
|
|
19157
|
+
userMetadata,
|
|
19158
|
+
referrerUserMetadata: null
|
|
19159
|
+
}).transaction();
|
|
19160
|
+
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
19161
|
+
return vTx;
|
|
19162
|
+
}
|
|
18356
19163
|
async depositTx(market, asset, amount, txOptions) {
|
|
18357
19164
|
const glamSigner = txOptions.signer || this.base.getSigner();
|
|
18358
19165
|
const vault = this.base.vaultPda;
|
|
@@ -19331,14 +20138,17 @@ class PriceClient {
|
|
|
19331
20138
|
* !! If the vault has not been priced or pricing data is outdated, the number is NOT meaningful.
|
|
19332
20139
|
*/ async getAum() {
|
|
19333
20140
|
console.warn("getAum() should only be used for testing. It doesn't reflect the actual AUM of the vault in production.");
|
|
19334
|
-
// @ts-ignore
|
|
19335
20141
|
const stateModel = await this.base.fetchStateModel();
|
|
19336
20142
|
return (stateModel?.pricedAssets || []).reduce((sum, p)=>new anchor.BN(p.amount).add(sum), new anchor.BN(0));
|
|
19337
20143
|
}
|
|
19338
|
-
|
|
19339
|
-
|
|
19340
|
-
|
|
19341
|
-
|
|
20144
|
+
/**
|
|
20145
|
+
* Returns an instruction that prices Kamino obligations.
|
|
20146
|
+
* If there are no Kamino obligations, returns null.
|
|
20147
|
+
*/ async priceKaminoObligationsIx(priceDenom) {
|
|
20148
|
+
const parsedObligations = await this.klend.findAndParseObligations(this.base.vaultPda);
|
|
20149
|
+
if (parsedObligations.length === 0) {
|
|
20150
|
+
return null;
|
|
20151
|
+
}
|
|
19342
20152
|
const pubkeySet = new Set([]);
|
|
19343
20153
|
parsedObligations.filter((o)=>o.lendingMarket !== null).map((o)=>{
|
|
19344
20154
|
pubkeySet.add(o.address.toBase58());
|
|
@@ -19351,7 +20161,6 @@ class PriceClient {
|
|
|
19351
20161
|
isSigner: false,
|
|
19352
20162
|
isWritable: true
|
|
19353
20163
|
}));
|
|
19354
|
-
// @ts-ignore
|
|
19355
20164
|
const priceIx = await this.base.program.methods.priceKaminoObligations(priceDenom).accounts({
|
|
19356
20165
|
glamState: this.base.statePda,
|
|
19357
20166
|
solOracle: SOL_ORACLE,
|
|
@@ -19362,81 +20171,152 @@ class PriceClient {
|
|
|
19362
20171
|
}).remainingAccounts(remainingAccounts).instruction();
|
|
19363
20172
|
return priceIx;
|
|
19364
20173
|
}
|
|
19365
|
-
|
|
19366
|
-
|
|
19367
|
-
|
|
20174
|
+
/**
|
|
20175
|
+
* Returns an instruction that prices the all Drift users (aka sub-accounts) controlled by the GLAM vault.
|
|
20176
|
+
* These Drift users must share the same user_stats that's also controlled by the GLAM vault.
|
|
20177
|
+
*/ async priceDriftUsersIx(priceDenom) {
|
|
20178
|
+
// FIXME: check more users than #0
|
|
20179
|
+
const { user, userStats } = this.drift.getDriftUserPdas();
|
|
20180
|
+
try {
|
|
20181
|
+
const remainingAccounts = await this.drift.composeRemainingAccounts(0);
|
|
20182
|
+
const priceDriftUsersIx = await this.base.program.methods.priceDriftUsers(priceDenom).accounts({
|
|
20183
|
+
glamState: this.base.statePda,
|
|
20184
|
+
solOracle: SOL_ORACLE
|
|
20185
|
+
}).remainingAccounts([
|
|
20186
|
+
{
|
|
20187
|
+
pubkey: userStats,
|
|
20188
|
+
isSigner: false,
|
|
20189
|
+
isWritable: false
|
|
20190
|
+
},
|
|
20191
|
+
{
|
|
20192
|
+
pubkey: user,
|
|
20193
|
+
isSigner: false,
|
|
20194
|
+
isWritable: false
|
|
20195
|
+
},
|
|
20196
|
+
...remainingAccounts
|
|
20197
|
+
]).instruction();
|
|
20198
|
+
return priceDriftUsersIx;
|
|
20199
|
+
} catch (error) {
|
|
20200
|
+
return null;
|
|
20201
|
+
}
|
|
20202
|
+
}
|
|
20203
|
+
/**
|
|
20204
|
+
* Returns an instruction that prices a drift vault depositor.
|
|
20205
|
+
* If there are no vault depositor accounts, returns null.
|
|
20206
|
+
*/ async priceDriftVaultDepositorsIx(priceDenom) {
|
|
20207
|
+
const parsedVaultDepositors = await this.driftVaults.findAndParseVaultDepositors();
|
|
20208
|
+
if (parsedVaultDepositors.length === 0) {
|
|
20209
|
+
return null;
|
|
20210
|
+
}
|
|
20211
|
+
// For each vault deposit, we need the following pubkeys in remaining accounts:
|
|
20212
|
+
// - depositor
|
|
20213
|
+
// - drift vault
|
|
20214
|
+
// - drift user of the vault
|
|
20215
|
+
// - oracles
|
|
20216
|
+
// - spot & perp markets
|
|
20217
|
+
// There might be overlaps between markets and oracles so we use a set to avoid duplicates
|
|
20218
|
+
const remainingAccountsKeys = new Set();
|
|
20219
|
+
for (const depositor of parsedVaultDepositors){
|
|
20220
|
+
remainingAccountsKeys.add(depositor.address.toBase58());
|
|
20221
|
+
remainingAccountsKeys.add(depositor.driftVault.toBase58());
|
|
20222
|
+
const { user: driftUser } = await this.driftVaults.parseDriftVault(depositor.driftVault);
|
|
20223
|
+
remainingAccountsKeys.add(driftUser.toBase58());
|
|
20224
|
+
const markets_and_oracles = (await this.driftVaults.composeRemainingAccounts(driftUser)).map((a)=>a.pubkey.toBase58());
|
|
20225
|
+
for (const k of markets_and_oracles){
|
|
20226
|
+
remainingAccountsKeys.add(k);
|
|
20227
|
+
}
|
|
20228
|
+
}
|
|
20229
|
+
const remainingAccounts = Array.from(remainingAccountsKeys).map((k)=>({
|
|
20230
|
+
pubkey: new web3_js.PublicKey(k),
|
|
20231
|
+
isSigner: false,
|
|
20232
|
+
isWritable: false
|
|
20233
|
+
}));
|
|
20234
|
+
const priceIx = await this.base.program.methods.priceDriftVaultDepositors(priceDenom).accounts({
|
|
19368
20235
|
glamState: this.base.statePda,
|
|
19369
20236
|
solOracle: SOL_ORACLE
|
|
19370
|
-
}).remainingAccounts(
|
|
19371
|
-
|
|
19372
|
-
|
|
19373
|
-
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
}
|
|
19379
|
-
const tickets = await fetchMarinadeTicketAccounts(this.base.provider.connection, glamVault);
|
|
19380
|
-
// @ts-ignore
|
|
19381
|
-
const priceTicketsIx = await this.base.program.methods.priceTickets(priceDenom).accounts({
|
|
20237
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
20238
|
+
return priceIx;
|
|
20239
|
+
}
|
|
20240
|
+
/**
|
|
20241
|
+
* Returns an instruction that prices vault balance and tokens the vault holds
|
|
20242
|
+
*/ async priceVaultIx(priceDenom) {
|
|
20243
|
+
const remainingAccounts = await this.remainingAccountsForPricingVaultAssets(priceDenom == PriceDenom.ASSET);
|
|
20244
|
+
const priceVaultIx = await this.base.program.methods.priceVault(priceDenom).accounts({
|
|
19382
20245
|
glamState: this.base.statePda,
|
|
19383
20246
|
solOracle: SOL_ORACLE
|
|
19384
|
-
}).remainingAccounts(
|
|
19385
|
-
|
|
19386
|
-
|
|
19387
|
-
|
|
19388
|
-
|
|
19389
|
-
|
|
20247
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
20248
|
+
return priceVaultIx;
|
|
20249
|
+
}
|
|
20250
|
+
/**
|
|
20251
|
+
* Returns an instruction that prices stake accounts.
|
|
20252
|
+
* If there are no stake accounts, returns null.
|
|
20253
|
+
*/ async priceStakesIx(priceDenom) {
|
|
20254
|
+
const stakes = await findStakeAccounts(this.base.provider.connection, this.base.vaultPda);
|
|
20255
|
+
if (stakes.length === 0) {
|
|
20256
|
+
return null;
|
|
20257
|
+
}
|
|
19390
20258
|
const priceStakesIx = await this.base.program.methods.priceStakes(priceDenom).accounts({
|
|
19391
20259
|
glamState: this.base.statePda,
|
|
19392
20260
|
solOracle: SOL_ORACLE
|
|
19393
|
-
}).remainingAccounts(stakes.map((
|
|
19394
|
-
pubkey
|
|
20261
|
+
}).remainingAccounts(stakes.map((pubkey)=>({
|
|
20262
|
+
pubkey,
|
|
19395
20263
|
isSigner: false,
|
|
19396
20264
|
isWritable: false
|
|
19397
20265
|
}))).instruction();
|
|
20266
|
+
return priceStakesIx;
|
|
20267
|
+
}
|
|
20268
|
+
/**
|
|
20269
|
+
* Returns an instruction that prices Meteora positions.
|
|
20270
|
+
* If there are no Meteora positions, returns null.
|
|
20271
|
+
*/ async priceMeteoraPositionsIx(priceDenom) {
|
|
20272
|
+
const remainingAccounts = await this.remainingAccountsForPricingMeteora();
|
|
20273
|
+
if (remainingAccounts.length === 0) {
|
|
20274
|
+
return null;
|
|
20275
|
+
}
|
|
19398
20276
|
const priceMeteoraIx = await this.base.program.methods.priceMeteoraPositions(priceDenom).accounts({
|
|
19399
20277
|
glamState: this.base.statePda,
|
|
19400
20278
|
solOracle: SOL_ORACLE
|
|
19401
|
-
}).remainingAccounts(
|
|
19402
|
-
|
|
19403
|
-
|
|
19404
|
-
|
|
19405
|
-
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
user,
|
|
19411
|
-
userStats,
|
|
19412
|
-
state: this.drift.driftStatePda
|
|
19413
|
-
}).remainingAccounts(remainingAccounts).instruction();
|
|
20279
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
20280
|
+
return priceMeteoraIx;
|
|
20281
|
+
}
|
|
20282
|
+
async priceVaultIxs(priceDenom) {
|
|
20283
|
+
const priceVaultIx = await this.priceVaultIx(priceDenom);
|
|
20284
|
+
// If priceDenom is ASSET, only priceVaultIx is returned
|
|
20285
|
+
// We currently don't support pricing other assets in custom base asset
|
|
20286
|
+
// due to the lack of oracles
|
|
20287
|
+
if (priceDenom == PriceDenom.ASSET) {
|
|
19414
20288
|
return [
|
|
19415
|
-
|
|
19416
|
-
priceStakesIx,
|
|
19417
|
-
priceVaultIx,
|
|
19418
|
-
priceMeteoraIx,
|
|
19419
|
-
priceKaminoIx,
|
|
19420
|
-
priceDriftIx
|
|
20289
|
+
priceVaultIx
|
|
19421
20290
|
];
|
|
19422
|
-
}
|
|
19423
|
-
|
|
20291
|
+
}
|
|
20292
|
+
// If there are no external assets, we don't need to price DeFi positions
|
|
20293
|
+
const stateModel = await this.base.fetchStateModel();
|
|
20294
|
+
if ((stateModel.externalVaultAccounts || []).length === 0) {
|
|
19424
20295
|
return [
|
|
19425
|
-
|
|
19426
|
-
priceStakesIx,
|
|
19427
|
-
priceVaultIx,
|
|
19428
|
-
priceMeteoraIx,
|
|
19429
|
-
priceKaminoIx
|
|
20296
|
+
priceVaultIx
|
|
19430
20297
|
];
|
|
19431
20298
|
}
|
|
19432
|
-
|
|
19433
|
-
|
|
20299
|
+
const priceStakesIx = await this.priceStakesIx(priceDenom);
|
|
20300
|
+
const priceMeteoraIx = await this.priceMeteoraPositionsIx(priceDenom);
|
|
20301
|
+
const priceKaminoIx = await this.priceKaminoObligationsIx(priceDenom);
|
|
20302
|
+
const priceDriftUsersIx = await this.priceDriftUsersIx(priceDenom);
|
|
20303
|
+
const priceDriftVaultDepositorsIx = await this.priceDriftVaultDepositorsIx(priceDenom);
|
|
20304
|
+
return [
|
|
20305
|
+
priceVaultIx,
|
|
20306
|
+
priceStakesIx,
|
|
20307
|
+
priceMeteoraIx,
|
|
20308
|
+
priceKaminoIx,
|
|
20309
|
+
priceDriftUsersIx,
|
|
20310
|
+
priceDriftVaultDepositorsIx
|
|
20311
|
+
].filter((ix)=>ix !== null);
|
|
20312
|
+
}
|
|
20313
|
+
constructor(base, klend, drift, driftVaults){
|
|
19434
20314
|
this.base = base;
|
|
19435
20315
|
this.klend = klend;
|
|
19436
20316
|
this.drift = drift;
|
|
20317
|
+
this.driftVaults = driftVaults;
|
|
19437
20318
|
this.remainingAccountsForPricingMeteora = async ()=>{
|
|
19438
|
-
const
|
|
19439
|
-
const positions = await fetchMeteoraPositions(this.base.provider.connection, glamVault);
|
|
20319
|
+
const positions = await fetchMeteoraPositions(this.base.provider.connection, this.base.vaultPda);
|
|
19440
20320
|
let chunks = await Promise.all(positions.map(async (pubkey)=>{
|
|
19441
20321
|
const { lbPair, binArrayLower, binArrayUpper } = await parseMeteoraPosition(this.base.provider.connection, pubkey);
|
|
19442
20322
|
return [
|
|
@@ -19444,8 +20324,8 @@ class PriceClient {
|
|
|
19444
20324
|
lbPair,
|
|
19445
20325
|
binArrayLower,
|
|
19446
20326
|
binArrayUpper,
|
|
19447
|
-
|
|
19448
|
-
|
|
20327
|
+
SOL_ORACLE,
|
|
20328
|
+
USDC_ORACLE
|
|
19449
20329
|
].map((k)=>({
|
|
19450
20330
|
pubkey: k,
|
|
19451
20331
|
isSigner: false,
|
|
@@ -19505,6 +20385,12 @@ class PriceClient {
|
|
|
19505
20385
|
}
|
|
19506
20386
|
return this._drift;
|
|
19507
20387
|
}
|
|
20388
|
+
get driftVaults() {
|
|
20389
|
+
if (!this._driftVaults) {
|
|
20390
|
+
this._driftVaults = new DriftVaultsClient(this, this.drift);
|
|
20391
|
+
}
|
|
20392
|
+
return this._driftVaults;
|
|
20393
|
+
}
|
|
19508
20394
|
get investor() {
|
|
19509
20395
|
if (!this._investor) {
|
|
19510
20396
|
this._investor = new InvestorClient(this);
|
|
@@ -19543,7 +20429,7 @@ class PriceClient {
|
|
|
19543
20429
|
}
|
|
19544
20430
|
get price() {
|
|
19545
20431
|
if (!this._price) {
|
|
19546
|
-
this._price = new PriceClient(this, this.kaminoLending, this.drift);
|
|
20432
|
+
this._price = new PriceClient(this, this.kaminoLending, this.drift, this.driftVaults);
|
|
19547
20433
|
}
|
|
19548
20434
|
return this._price;
|
|
19549
20435
|
}
|
|
@@ -19663,11 +20549,14 @@ exports.ContractTier = ContractTier;
|
|
|
19663
20549
|
exports.ContractType = ContractType;
|
|
19664
20550
|
exports.CreatedModel = CreatedModel;
|
|
19665
20551
|
exports.DRIFT_PROGRAM_ID = DRIFT_PROGRAM_ID;
|
|
20552
|
+
exports.DRIFT_VAULTS_PROGRAM_ID = DRIFT_VAULTS_PROGRAM_ID;
|
|
20553
|
+
exports.DRIFT_VAULT_DEPOSITOR_SIZE = DRIFT_VAULT_DEPOSITOR_SIZE;
|
|
19666
20554
|
exports.DefaultOrderParams = DefaultOrderParams;
|
|
19667
20555
|
exports.DelegateAcl = DelegateAcl;
|
|
19668
20556
|
exports.DepositDirection = DepositDirection;
|
|
19669
20557
|
exports.DepositExplanation = DepositExplanation;
|
|
19670
20558
|
exports.DriftClient = DriftClient;
|
|
20559
|
+
exports.DriftVaultsClient = DriftVaultsClient;
|
|
19671
20560
|
exports.ExchangeStatus = ExchangeStatus;
|
|
19672
20561
|
exports.FuelOverflowStatus = FuelOverflowStatus;
|
|
19673
20562
|
exports.FundOpenfundsModel = FundOpenfundsModel;
|
|
@@ -19697,7 +20586,6 @@ exports.LPAction = LPAction;
|
|
|
19697
20586
|
exports.LiquidationType = LiquidationType;
|
|
19698
20587
|
exports.MARINADE_NATIVE_STAKE_AUTHORITY = MARINADE_NATIVE_STAKE_AUTHORITY;
|
|
19699
20588
|
exports.MARINADE_PROGRAM_ID = MARINADE_PROGRAM_ID;
|
|
19700
|
-
exports.MARINADE_TICKET_SIZE = MARINADE_TICKET_SIZE;
|
|
19701
20589
|
exports.MEMO_PROGRAM = MEMO_PROGRAM;
|
|
19702
20590
|
exports.MERKLE_DISTRIBUTOR_PROGRAM = MERKLE_DISTRIBUTOR_PROGRAM;
|
|
19703
20591
|
exports.METEORA_DLMM_PROGRAM = METEORA_DLMM_PROGRAM;
|
|
@@ -19751,15 +20639,14 @@ exports.TRANSFER_HOOK_PROGRAM = TRANSFER_HOOK_PROGRAM;
|
|
|
19751
20639
|
exports.TimeUnit = TimeUnit;
|
|
19752
20640
|
exports.TradeSide = TradeSide;
|
|
19753
20641
|
exports.USDC = USDC;
|
|
20642
|
+
exports.USDC_ORACLE = USDC_ORACLE;
|
|
19754
20643
|
exports.UserStatus = UserStatus;
|
|
19755
20644
|
exports.WSOL = WSOL;
|
|
19756
20645
|
exports.ZERO = ZERO;
|
|
19757
20646
|
exports.decodeUser = decodeUser;
|
|
19758
|
-
exports.fetchKaminoObligations = fetchKaminoObligations;
|
|
19759
20647
|
exports.fetchLookupTables = fetchLookupTables;
|
|
19760
|
-
exports.fetchMarinadeTicketAccounts = fetchMarinadeTicketAccounts;
|
|
19761
20648
|
exports.fetchMeteoraPositions = fetchMeteoraPositions;
|
|
19762
|
-
exports.
|
|
20649
|
+
exports.findStakeAccounts = findStakeAccounts;
|
|
19763
20650
|
exports.getAccountPolicyPda = getAccountPolicyPda;
|
|
19764
20651
|
exports.getEscrowPda = getEscrowPda;
|
|
19765
20652
|
exports.getExtraMetasPda = getExtraMetasPda;
|
|
@@ -19782,4 +20669,5 @@ exports.isBrowser = isBrowser;
|
|
|
19782
20669
|
exports.isOneOfVariant = isOneOfVariant;
|
|
19783
20670
|
exports.isVariant = isVariant;
|
|
19784
20671
|
exports.parseMeteoraPosition = parseMeteoraPosition;
|
|
20672
|
+
exports.parseProgramLogs = parseProgramLogs;
|
|
19785
20673
|
exports.setsAreEqual = setsAreEqual;
|