flash-sdk 2.12.7 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/PerpetualsClient.d.ts +22 -4
- package/dist/PerpetualsClient.js +533 -169
- package/dist/ViewHelper.d.ts +8 -0
- package/dist/ViewHelper.js +108 -0
- package/dist/backupOracle.d.ts +2 -0
- package/dist/backupOracle.js +31 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/IdlCoder.d.ts +8 -0
- package/dist/utils/IdlCoder.js +166 -0
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -76,7 +76,9 @@ var rpc_1 = require("./utils/rpc");
|
|
76
76
|
var utils_1 = require("./utils");
|
77
77
|
var constants_1 = require("./constants");
|
78
78
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
79
|
+
var backupOracle_1 = require("./backupOracle");
|
79
80
|
var getNftAccounts_1 = require("./utils/getNftAccounts");
|
81
|
+
var ViewHelper_1 = require("./ViewHelper");
|
80
82
|
var PerpetualsClient = (function () {
|
81
83
|
function PerpetualsClient(provider, programId, composabilityProgramId, fbNftRewardProgramId, rewardDistributionProgramId, opts, useExtOracleAccount) {
|
82
84
|
if (useExtOracleAccount === void 0) { useExtOracleAccount = false; }
|
@@ -541,175 +543,6 @@ var PerpetualsClient = (function () {
|
|
541
543
|
}
|
542
544
|
});
|
543
545
|
}); };
|
544
|
-
this.getLiquidationState = function (positionAccount, poolName, tokenMint, collateralMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
545
|
-
var targetCustodyConfig, collateralCustodyConfig;
|
546
|
-
return __generator(this, function (_a) {
|
547
|
-
switch (_a.label) {
|
548
|
-
case 0:
|
549
|
-
targetCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
550
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
551
|
-
return [4, this.program.methods
|
552
|
-
.getLiquidationState({})
|
553
|
-
.accounts({
|
554
|
-
perpetuals: this.perpetuals.publicKey,
|
555
|
-
pool: poolConfig.poolAddress,
|
556
|
-
position: positionAccount,
|
557
|
-
targetCustody: this.getCustodyKey(poolName, tokenMint),
|
558
|
-
targetOracleAccount: targetCustodyConfig.custodyAccount,
|
559
|
-
collateralCustody: this.getCustodyKey(poolName, collateralMint),
|
560
|
-
collateralOracleAccount: collateralCustodyConfig.custodyAccount,
|
561
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
562
|
-
})
|
563
|
-
.view()
|
564
|
-
.catch(function (err) {
|
565
|
-
console.error(err);
|
566
|
-
throw err;
|
567
|
-
})];
|
568
|
-
case 1: return [2, _a.sent()];
|
569
|
-
}
|
570
|
-
});
|
571
|
-
}); };
|
572
|
-
this.getCompoundingTokenData = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
573
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
|
574
|
-
return __generator(this, function (_d) {
|
575
|
-
switch (_d.label) {
|
576
|
-
case 0:
|
577
|
-
custodyAccountMetas = [];
|
578
|
-
custodyOracleAccountMetas = [];
|
579
|
-
markets = [];
|
580
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
581
|
-
custody = _a[_i];
|
582
|
-
custodyAccountMetas.push({
|
583
|
-
pubkey: custody.custodyAccount,
|
584
|
-
isSigner: false,
|
585
|
-
isWritable: false,
|
586
|
-
});
|
587
|
-
custodyOracleAccountMetas.push({
|
588
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
589
|
-
isSigner: false,
|
590
|
-
isWritable: false,
|
591
|
-
});
|
592
|
-
}
|
593
|
-
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
594
|
-
market = _c[_b];
|
595
|
-
markets.push({
|
596
|
-
pubkey: market.marketAccount,
|
597
|
-
isSigner: false,
|
598
|
-
isWritable: false,
|
599
|
-
});
|
600
|
-
}
|
601
|
-
return [4, this.program.methods
|
602
|
-
.getCompoundingTokenData({})
|
603
|
-
.accounts({
|
604
|
-
perpetuals: this.perpetuals.publicKey,
|
605
|
-
pool: poolConfig.poolAddress,
|
606
|
-
lpTokenMint: poolConfig.stakedLpTokenMint,
|
607
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
608
|
-
})
|
609
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
610
|
-
.view()
|
611
|
-
.catch(function (err) {
|
612
|
-
console.error(err);
|
613
|
-
throw err;
|
614
|
-
})];
|
615
|
-
case 1: return [2, _d.sent()];
|
616
|
-
}
|
617
|
-
});
|
618
|
-
}); };
|
619
|
-
this.getLpTokenPrice = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
620
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
|
621
|
-
return __generator(this, function (_d) {
|
622
|
-
switch (_d.label) {
|
623
|
-
case 0:
|
624
|
-
custodyAccountMetas = [];
|
625
|
-
custodyOracleAccountMetas = [];
|
626
|
-
markets = [];
|
627
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
628
|
-
custody = _a[_i];
|
629
|
-
custodyAccountMetas.push({
|
630
|
-
pubkey: custody.custodyAccount,
|
631
|
-
isSigner: false,
|
632
|
-
isWritable: false,
|
633
|
-
});
|
634
|
-
custodyOracleAccountMetas.push({
|
635
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
636
|
-
isSigner: false,
|
637
|
-
isWritable: false,
|
638
|
-
});
|
639
|
-
}
|
640
|
-
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
641
|
-
market = _c[_b];
|
642
|
-
markets.push({
|
643
|
-
pubkey: market.marketAccount,
|
644
|
-
isSigner: false,
|
645
|
-
isWritable: false,
|
646
|
-
});
|
647
|
-
}
|
648
|
-
return [4, this.program.methods
|
649
|
-
.getLpTokenPrice({})
|
650
|
-
.accounts({
|
651
|
-
perpetuals: this.perpetuals.publicKey,
|
652
|
-
pool: poolConfig.poolAddress,
|
653
|
-
lpTokenMint: poolConfig.stakedLpTokenMint,
|
654
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
655
|
-
})
|
656
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
657
|
-
.view()
|
658
|
-
.catch(function (err) {
|
659
|
-
console.error(err);
|
660
|
-
throw err;
|
661
|
-
})];
|
662
|
-
case 1: return [2, _d.sent()];
|
663
|
-
}
|
664
|
-
});
|
665
|
-
}); };
|
666
|
-
this.getCompoundingTokenDataView = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
667
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
|
668
|
-
return __generator(this, function (_d) {
|
669
|
-
switch (_d.label) {
|
670
|
-
case 0:
|
671
|
-
custodyAccountMetas = [];
|
672
|
-
custodyOracleAccountMetas = [];
|
673
|
-
markets = [];
|
674
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
675
|
-
custody = _a[_i];
|
676
|
-
custodyAccountMetas.push({
|
677
|
-
pubkey: custody.custodyAccount,
|
678
|
-
isSigner: false,
|
679
|
-
isWritable: false,
|
680
|
-
});
|
681
|
-
custodyOracleAccountMetas.push({
|
682
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
683
|
-
isSigner: false,
|
684
|
-
isWritable: false,
|
685
|
-
});
|
686
|
-
}
|
687
|
-
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
688
|
-
market = _c[_b];
|
689
|
-
markets.push({
|
690
|
-
pubkey: market.marketAccount,
|
691
|
-
isSigner: false,
|
692
|
-
isWritable: false,
|
693
|
-
});
|
694
|
-
}
|
695
|
-
return [4, this.program.methods
|
696
|
-
.getCompoundingTokenData({})
|
697
|
-
.accounts({
|
698
|
-
perpetuals: this.perpetuals.publicKey,
|
699
|
-
pool: poolConfig.poolAddress,
|
700
|
-
lpTokenMint: poolConfig.stakedLpTokenMint,
|
701
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
702
|
-
})
|
703
|
-
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
704
|
-
.view()
|
705
|
-
.catch(function (err) {
|
706
|
-
console.error(err);
|
707
|
-
throw err;
|
708
|
-
})];
|
709
|
-
case 1: return [2, _d.sent()];
|
710
|
-
}
|
711
|
-
});
|
712
|
-
}); };
|
713
546
|
this.liquidate = function (positionAccount, poolConfig, tokenMint, collateralMint, marketPk) { return __awaiter(_this, void 0, void 0, function () {
|
714
547
|
var targetCustodyConfig, collateralCustodyConfig;
|
715
548
|
return __generator(this, function (_a) {
|
@@ -1859,6 +1692,536 @@ var PerpetualsClient = (function () {
|
|
1859
1692
|
}
|
1860
1693
|
return finalIndexPriceAtT1.toString();
|
1861
1694
|
};
|
1695
|
+
this.getStakedLpTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1696
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_1, token, _a, custodies_2, custody, _b, _c, market, transaction, backUpOracleInstruction, result, index, res;
|
1697
|
+
var _d;
|
1698
|
+
return __generator(this, function (_e) {
|
1699
|
+
switch (_e.label) {
|
1700
|
+
case 0:
|
1701
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
1702
|
+
custodies = POOL_CONFIG.custodies;
|
1703
|
+
custodyMetas = [];
|
1704
|
+
marketMetas = [];
|
1705
|
+
for (_i = 0, custodies_1 = custodies; _i < custodies_1.length; _i++) {
|
1706
|
+
token = custodies_1[_i];
|
1707
|
+
custodyMetas.push({
|
1708
|
+
isSigner: false,
|
1709
|
+
isWritable: false,
|
1710
|
+
pubkey: token.custodyAccount,
|
1711
|
+
});
|
1712
|
+
}
|
1713
|
+
for (_a = 0, custodies_2 = custodies; _a < custodies_2.length; _a++) {
|
1714
|
+
custody = custodies_2[_a];
|
1715
|
+
custodyMetas.push({
|
1716
|
+
isSigner: false,
|
1717
|
+
isWritable: false,
|
1718
|
+
pubkey: custody.intOracleAccount,
|
1719
|
+
});
|
1720
|
+
}
|
1721
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
1722
|
+
market = _c[_b];
|
1723
|
+
marketMetas.push({
|
1724
|
+
pubkey: market.marketAccount,
|
1725
|
+
isSigner: false,
|
1726
|
+
isWritable: false,
|
1727
|
+
});
|
1728
|
+
}
|
1729
|
+
return [4, this.program.methods
|
1730
|
+
.getLpTokenPrice({})
|
1731
|
+
.accounts({
|
1732
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
1733
|
+
pool: poolKey,
|
1734
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
1735
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
1736
|
+
})
|
1737
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
1738
|
+
.transaction()];
|
1739
|
+
case 1:
|
1740
|
+
transaction = _e.sent();
|
1741
|
+
return [4, backUpOracleInstructionPromise];
|
1742
|
+
case 2:
|
1743
|
+
backUpOracleInstruction = _e.sent();
|
1744
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1745
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1746
|
+
case 3:
|
1747
|
+
result = _e.sent();
|
1748
|
+
console.log('result :>> ', result);
|
1749
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getLpTokenPrice'; });
|
1750
|
+
res = this.viewHelper.decodeLogs(result, index, 'getLpTokenPrice');
|
1751
|
+
console.log("res:", res);
|
1752
|
+
return [2, res.toString()];
|
1753
|
+
}
|
1754
|
+
});
|
1755
|
+
}); };
|
1756
|
+
this.getAddLiquidityAmountAndFee = function (amount, poolKey, depositCustodyKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1757
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_3, token, _a, custodies_4, custody, _b, _c, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1758
|
+
var _d;
|
1759
|
+
return __generator(this, function (_e) {
|
1760
|
+
switch (_e.label) {
|
1761
|
+
case 0:
|
1762
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
1763
|
+
custodies = POOL_CONFIG.custodies;
|
1764
|
+
custodyMetas = [];
|
1765
|
+
marketMetas = [];
|
1766
|
+
for (_i = 0, custodies_3 = custodies; _i < custodies_3.length; _i++) {
|
1767
|
+
token = custodies_3[_i];
|
1768
|
+
custodyMetas.push({
|
1769
|
+
isSigner: false,
|
1770
|
+
isWritable: false,
|
1771
|
+
pubkey: token.custodyAccount,
|
1772
|
+
});
|
1773
|
+
}
|
1774
|
+
for (_a = 0, custodies_4 = custodies; _a < custodies_4.length; _a++) {
|
1775
|
+
custody = custodies_4[_a];
|
1776
|
+
custodyMetas.push({
|
1777
|
+
isSigner: false,
|
1778
|
+
isWritable: false,
|
1779
|
+
pubkey: custody.intOracleAccount,
|
1780
|
+
});
|
1781
|
+
}
|
1782
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
1783
|
+
market = _c[_b];
|
1784
|
+
marketMetas.push({
|
1785
|
+
pubkey: market.marketAccount,
|
1786
|
+
isSigner: false,
|
1787
|
+
isWritable: false,
|
1788
|
+
});
|
1789
|
+
}
|
1790
|
+
depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
|
1791
|
+
return [4, this.program.methods
|
1792
|
+
.getAddLiquidityAmountAndFee({
|
1793
|
+
amountIn: amount,
|
1794
|
+
})
|
1795
|
+
.accounts({
|
1796
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
1797
|
+
pool: poolKey,
|
1798
|
+
custody: depositCustodyKey,
|
1799
|
+
custodyOracleAccount: depositCustodyConfig.intOracleAccount,
|
1800
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
1801
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
1802
|
+
})
|
1803
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
1804
|
+
.transaction()];
|
1805
|
+
case 1:
|
1806
|
+
transaction = _e.sent();
|
1807
|
+
return [4, backUpOracleInstructionPromise];
|
1808
|
+
case 2:
|
1809
|
+
backUpOracleInstruction = _e.sent();
|
1810
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1811
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1812
|
+
case 3:
|
1813
|
+
result = _e.sent();
|
1814
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
1815
|
+
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
1816
|
+
return [2, {
|
1817
|
+
amount: res.amount,
|
1818
|
+
fee: res.fee,
|
1819
|
+
}];
|
1820
|
+
}
|
1821
|
+
});
|
1822
|
+
}); };
|
1823
|
+
this.getRemoveLiquidityAmountAndFee = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1824
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
1825
|
+
var _d;
|
1826
|
+
return __generator(this, function (_e) {
|
1827
|
+
switch (_e.label) {
|
1828
|
+
case 0:
|
1829
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
1830
|
+
custodies = POOL_CONFIG.custodies;
|
1831
|
+
custodyMetas = [];
|
1832
|
+
marketMetas = [];
|
1833
|
+
for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
|
1834
|
+
token = custodies_5[_i];
|
1835
|
+
custodyMetas.push({
|
1836
|
+
isSigner: false,
|
1837
|
+
isWritable: false,
|
1838
|
+
pubkey: token.custodyAccount,
|
1839
|
+
});
|
1840
|
+
}
|
1841
|
+
for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
|
1842
|
+
custody = custodies_6[_a];
|
1843
|
+
custodyMetas.push({
|
1844
|
+
isSigner: false,
|
1845
|
+
isWritable: false,
|
1846
|
+
pubkey: custody.intOracleAccount,
|
1847
|
+
});
|
1848
|
+
}
|
1849
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
1850
|
+
market = _c[_b];
|
1851
|
+
marketMetas.push({
|
1852
|
+
pubkey: market.marketAccount,
|
1853
|
+
isSigner: false,
|
1854
|
+
isWritable: false,
|
1855
|
+
});
|
1856
|
+
}
|
1857
|
+
removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
|
1858
|
+
return [4, this.program.methods
|
1859
|
+
.getRemoveLiquidityAmountAndFee({
|
1860
|
+
lpAmountIn: amount,
|
1861
|
+
})
|
1862
|
+
.accounts({
|
1863
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
1864
|
+
pool: poolKey,
|
1865
|
+
custody: removeTokenCustodyKey,
|
1866
|
+
custodyOracleAccount: removeCustodyConfig.intOracleAccount,
|
1867
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
1868
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
1869
|
+
})
|
1870
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
1871
|
+
.transaction()];
|
1872
|
+
case 1:
|
1873
|
+
transaction = _e.sent();
|
1874
|
+
return [4, backUpOracleInstructionPromise];
|
1875
|
+
case 2:
|
1876
|
+
backUpOracleInstruction = _e.sent();
|
1877
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1878
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1879
|
+
case 3:
|
1880
|
+
result = _e.sent();
|
1881
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
1882
|
+
if (result.value.err) {
|
1883
|
+
return [2, {
|
1884
|
+
amount: new anchor_1.BN(0),
|
1885
|
+
fee: new anchor_1.BN(0),
|
1886
|
+
}];
|
1887
|
+
}
|
1888
|
+
res = this.viewHelper.decodeLogs(result, index, 'getRemoveLiquidityAmountAndFee');
|
1889
|
+
return [2, {
|
1890
|
+
amount: res.amount,
|
1891
|
+
fee: res.fee,
|
1892
|
+
}];
|
1893
|
+
}
|
1894
|
+
});
|
1895
|
+
}); };
|
1896
|
+
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1897
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
1898
|
+
var _d;
|
1899
|
+
return __generator(this, function (_e) {
|
1900
|
+
switch (_e.label) {
|
1901
|
+
case 0:
|
1902
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
1903
|
+
custodies = POOL_CONFIG.custodies;
|
1904
|
+
custodyMetas = [];
|
1905
|
+
marketMetas = [];
|
1906
|
+
for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
|
1907
|
+
token = custodies_7[_i];
|
1908
|
+
custodyMetas.push({
|
1909
|
+
isSigner: false,
|
1910
|
+
isWritable: false,
|
1911
|
+
pubkey: token.custodyAccount,
|
1912
|
+
});
|
1913
|
+
}
|
1914
|
+
for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
|
1915
|
+
custody = custodies_8[_a];
|
1916
|
+
custodyMetas.push({
|
1917
|
+
isSigner: false,
|
1918
|
+
isWritable: false,
|
1919
|
+
pubkey: custody.intOracleAccount,
|
1920
|
+
});
|
1921
|
+
}
|
1922
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
1923
|
+
market = _c[_b];
|
1924
|
+
marketMetas.push({
|
1925
|
+
pubkey: market.marketAccount,
|
1926
|
+
isSigner: false,
|
1927
|
+
isWritable: false,
|
1928
|
+
});
|
1929
|
+
}
|
1930
|
+
return [4, backUpOracleInstructionPromise];
|
1931
|
+
case 1:
|
1932
|
+
backUpOracleInstruction = _e.sent();
|
1933
|
+
return [4, this.program.methods
|
1934
|
+
.getCompoundingTokenPrice({})
|
1935
|
+
.accounts({
|
1936
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
1937
|
+
pool: poolKey,
|
1938
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
1939
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
1940
|
+
})
|
1941
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
1942
|
+
.transaction()];
|
1943
|
+
case 2:
|
1944
|
+
transaction = _e.sent();
|
1945
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
1946
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
1947
|
+
case 3:
|
1948
|
+
result = _e.sent();
|
1949
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getCompoundingTokenPrice'; });
|
1950
|
+
res = this.viewHelper.decodeLogs(result, index, 'getCompoundingTokenPrice');
|
1951
|
+
return [2, res.toString()];
|
1952
|
+
}
|
1953
|
+
});
|
1954
|
+
}); };
|
1955
|
+
this.getSFLPAddLiquidityAmountAndFee = function (amount, poolKey, depositCustodyKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
1956
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
1957
|
+
var _d;
|
1958
|
+
return __generator(this, function (_e) {
|
1959
|
+
switch (_e.label) {
|
1960
|
+
case 0:
|
1961
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
1962
|
+
custodies = POOL_CONFIG.custodies;
|
1963
|
+
custodyMetas = [];
|
1964
|
+
marketMetas = [];
|
1965
|
+
for (_i = 0, custodies_9 = custodies; _i < custodies_9.length; _i++) {
|
1966
|
+
token = custodies_9[_i];
|
1967
|
+
custodyMetas.push({
|
1968
|
+
isSigner: false,
|
1969
|
+
isWritable: false,
|
1970
|
+
pubkey: token.custodyAccount,
|
1971
|
+
});
|
1972
|
+
}
|
1973
|
+
for (_a = 0, custodies_10 = custodies; _a < custodies_10.length; _a++) {
|
1974
|
+
custody = custodies_10[_a];
|
1975
|
+
custodyMetas.push({
|
1976
|
+
isSigner: false,
|
1977
|
+
isWritable: false,
|
1978
|
+
pubkey: custody.intOracleAccount,
|
1979
|
+
});
|
1980
|
+
}
|
1981
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
1982
|
+
market = _c[_b];
|
1983
|
+
marketMetas.push({
|
1984
|
+
pubkey: market.marketAccount,
|
1985
|
+
isSigner: false,
|
1986
|
+
isWritable: false,
|
1987
|
+
});
|
1988
|
+
}
|
1989
|
+
depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
|
1990
|
+
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
1991
|
+
return [4, backUpOracleInstructionPromise];
|
1992
|
+
case 1:
|
1993
|
+
backUpOracleInstruction = _e.sent();
|
1994
|
+
return [4, this.program.methods
|
1995
|
+
.getAddCompoundingLiquidityAmountAndFee({
|
1996
|
+
amountIn: amount,
|
1997
|
+
})
|
1998
|
+
.accounts({
|
1999
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2000
|
+
pool: poolKey,
|
2001
|
+
inCustody: depositCustodyKey,
|
2002
|
+
inCustodyOracleAccount: depositCustodyConfig.intOracleAccount,
|
2003
|
+
rewardCustody: rewardCustody.custodyAccount,
|
2004
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
2005
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2006
|
+
compoundingTokenMint: POOL_CONFIG.compoundingTokenMint,
|
2007
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2008
|
+
})
|
2009
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2010
|
+
.transaction()];
|
2011
|
+
case 2:
|
2012
|
+
transaction = _e.sent();
|
2013
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2014
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
2015
|
+
case 3:
|
2016
|
+
result = _e.sent();
|
2017
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2018
|
+
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2019
|
+
return [2, {
|
2020
|
+
amount: res.amount,
|
2021
|
+
fee: res.fee,
|
2022
|
+
}];
|
2023
|
+
}
|
2024
|
+
});
|
2025
|
+
}); };
|
2026
|
+
this.getSFLPRemoveLiquidityAmountAndFee = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2027
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2028
|
+
var _d;
|
2029
|
+
return __generator(this, function (_e) {
|
2030
|
+
switch (_e.label) {
|
2031
|
+
case 0:
|
2032
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2033
|
+
custodies = POOL_CONFIG.custodies;
|
2034
|
+
custodyMetas = [];
|
2035
|
+
marketMetas = [];
|
2036
|
+
for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
|
2037
|
+
token = custodies_11[_i];
|
2038
|
+
custodyMetas.push({
|
2039
|
+
isSigner: false,
|
2040
|
+
isWritable: false,
|
2041
|
+
pubkey: token.custodyAccount,
|
2042
|
+
});
|
2043
|
+
}
|
2044
|
+
for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
|
2045
|
+
custody = custodies_12[_a];
|
2046
|
+
custodyMetas.push({
|
2047
|
+
isSigner: false,
|
2048
|
+
isWritable: false,
|
2049
|
+
pubkey: custody.intOracleAccount,
|
2050
|
+
});
|
2051
|
+
}
|
2052
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2053
|
+
market = _c[_b];
|
2054
|
+
marketMetas.push({
|
2055
|
+
pubkey: market.marketAccount,
|
2056
|
+
isSigner: false,
|
2057
|
+
isWritable: false,
|
2058
|
+
});
|
2059
|
+
}
|
2060
|
+
removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
|
2061
|
+
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2062
|
+
return [4, backUpOracleInstructionPromise];
|
2063
|
+
case 1:
|
2064
|
+
backUpOracleInstruction = _e.sent();
|
2065
|
+
return [4, this.program.methods
|
2066
|
+
.getRemoveCompoundingLiquidityAmountAndFee({
|
2067
|
+
compoundingAmountIn: amount,
|
2068
|
+
})
|
2069
|
+
.accounts({
|
2070
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2071
|
+
pool: poolKey,
|
2072
|
+
outCustody: removeTokenCustodyKey,
|
2073
|
+
outCustodyOracleAccount: removeCustodyConfig.intOracleAccount,
|
2074
|
+
rewardCustody: rewardCustody.custodyAccount,
|
2075
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
2076
|
+
compoundingTokenMint: POOL_CONFIG.compoundingTokenMint,
|
2077
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2078
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2079
|
+
})
|
2080
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2081
|
+
.transaction()];
|
2082
|
+
case 2:
|
2083
|
+
transaction = _e.sent();
|
2084
|
+
(_d = transaction.instructions).unshift.apply(_d, backUpOracleInstruction);
|
2085
|
+
return [4, this.viewHelper.simulateTransaction(transaction)];
|
2086
|
+
case 3:
|
2087
|
+
result = _e.sent();
|
2088
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2089
|
+
if (result.value.err) {
|
2090
|
+
return [2, {
|
2091
|
+
amount: new anchor_1.BN(0),
|
2092
|
+
fee: new anchor_1.BN(0),
|
2093
|
+
}];
|
2094
|
+
}
|
2095
|
+
res = this.viewHelper.decodeLogs(result, index, 'getRemoveCompoundingLiquidityAmountAndFee');
|
2096
|
+
return [2, {
|
2097
|
+
amount: res.amount,
|
2098
|
+
fee: res.fee,
|
2099
|
+
}];
|
2100
|
+
}
|
2101
|
+
});
|
2102
|
+
}); };
|
2103
|
+
this.getLiquidationStateView = function (positionAccount, poolName, tokenMint, collateralMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
2104
|
+
var targetCustodyConfig, collateralCustodyConfig;
|
2105
|
+
return __generator(this, function (_a) {
|
2106
|
+
switch (_a.label) {
|
2107
|
+
case 0:
|
2108
|
+
targetCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(tokenMint); });
|
2109
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (f) { return f.mintKey.equals(collateralMint); });
|
2110
|
+
return [4, this.program.methods
|
2111
|
+
.getLiquidationState({})
|
2112
|
+
.accounts({
|
2113
|
+
perpetuals: this.perpetuals.publicKey,
|
2114
|
+
pool: poolConfig.poolAddress,
|
2115
|
+
position: positionAccount,
|
2116
|
+
targetCustody: this.getCustodyKey(poolName, tokenMint),
|
2117
|
+
targetOracleAccount: targetCustodyConfig.custodyAccount,
|
2118
|
+
collateralCustody: this.getCustodyKey(poolName, collateralMint),
|
2119
|
+
collateralOracleAccount: collateralCustodyConfig.custodyAccount,
|
2120
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2121
|
+
})
|
2122
|
+
.view()
|
2123
|
+
.catch(function (err) {
|
2124
|
+
console.error(err);
|
2125
|
+
throw err;
|
2126
|
+
})];
|
2127
|
+
case 1: return [2, _a.sent()];
|
2128
|
+
}
|
2129
|
+
});
|
2130
|
+
}); };
|
2131
|
+
this.getCompoundingTokenDataView = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
2132
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
|
2133
|
+
return __generator(this, function (_d) {
|
2134
|
+
switch (_d.label) {
|
2135
|
+
case 0:
|
2136
|
+
custodyAccountMetas = [];
|
2137
|
+
custodyOracleAccountMetas = [];
|
2138
|
+
markets = [];
|
2139
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
2140
|
+
custody = _a[_i];
|
2141
|
+
custodyAccountMetas.push({
|
2142
|
+
pubkey: custody.custodyAccount,
|
2143
|
+
isSigner: false,
|
2144
|
+
isWritable: false,
|
2145
|
+
});
|
2146
|
+
custodyOracleAccountMetas.push({
|
2147
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
2148
|
+
isSigner: false,
|
2149
|
+
isWritable: false,
|
2150
|
+
});
|
2151
|
+
}
|
2152
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
2153
|
+
market = _c[_b];
|
2154
|
+
markets.push({
|
2155
|
+
pubkey: market.marketAccount,
|
2156
|
+
isSigner: false,
|
2157
|
+
isWritable: false,
|
2158
|
+
});
|
2159
|
+
}
|
2160
|
+
return [4, this.program.methods
|
2161
|
+
.getCompoundingTokenData({})
|
2162
|
+
.accounts({
|
2163
|
+
perpetuals: this.perpetuals.publicKey,
|
2164
|
+
pool: poolConfig.poolAddress,
|
2165
|
+
lpTokenMint: poolConfig.stakedLpTokenMint,
|
2166
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2167
|
+
})
|
2168
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
2169
|
+
.view()
|
2170
|
+
.catch(function (err) {
|
2171
|
+
console.error(err);
|
2172
|
+
throw err;
|
2173
|
+
})];
|
2174
|
+
case 1: return [2, _d.sent()];
|
2175
|
+
}
|
2176
|
+
});
|
2177
|
+
}); };
|
2178
|
+
this.getLpTokenPriceView = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
2179
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market;
|
2180
|
+
return __generator(this, function (_d) {
|
2181
|
+
switch (_d.label) {
|
2182
|
+
case 0:
|
2183
|
+
custodyAccountMetas = [];
|
2184
|
+
custodyOracleAccountMetas = [];
|
2185
|
+
markets = [];
|
2186
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
2187
|
+
custody = _a[_i];
|
2188
|
+
custodyAccountMetas.push({
|
2189
|
+
pubkey: custody.custodyAccount,
|
2190
|
+
isSigner: false,
|
2191
|
+
isWritable: false,
|
2192
|
+
});
|
2193
|
+
custodyOracleAccountMetas.push({
|
2194
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
2195
|
+
isSigner: false,
|
2196
|
+
isWritable: false,
|
2197
|
+
});
|
2198
|
+
}
|
2199
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
2200
|
+
market = _c[_b];
|
2201
|
+
markets.push({
|
2202
|
+
pubkey: market.marketAccount,
|
2203
|
+
isSigner: false,
|
2204
|
+
isWritable: false,
|
2205
|
+
});
|
2206
|
+
}
|
2207
|
+
return [4, this.program.methods
|
2208
|
+
.getLpTokenPrice({})
|
2209
|
+
.accounts({
|
2210
|
+
perpetuals: this.perpetuals.publicKey,
|
2211
|
+
pool: poolConfig.poolAddress,
|
2212
|
+
lpTokenMint: poolConfig.stakedLpTokenMint,
|
2213
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2214
|
+
})
|
2215
|
+
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
2216
|
+
.view()
|
2217
|
+
.catch(function (err) {
|
2218
|
+
console.error(err);
|
2219
|
+
throw err;
|
2220
|
+
})];
|
2221
|
+
case 1: return [2, _d.sent()];
|
2222
|
+
}
|
2223
|
+
});
|
2224
|
+
}); };
|
1862
2225
|
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, nftTradingAccount, nftReferralAccount, nftRebateTokenAccount, privilege, skipBalanceChecks) {
|
1863
2226
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
1864
2227
|
return __awaiter(_this, void 0, void 0, function () {
|
@@ -5622,6 +5985,7 @@ var PerpetualsClient = (function () {
|
|
5622
5985
|
this.useExtOracleAccount = useExtOracleAccount;
|
5623
5986
|
this.postSendTxCallback = opts === null || opts === void 0 ? void 0 : opts.postSendTxCallback;
|
5624
5987
|
this.txConfirmationCommitment = (_a = opts === null || opts === void 0 ? void 0 : opts.txConfirmationCommitment) !== null && _a !== void 0 ? _a : 'processed';
|
5988
|
+
this.viewHelper = new ViewHelper_1.ViewHelper(this);
|
5625
5989
|
anchor_1.BN.prototype.toJSON = function () {
|
5626
5990
|
return this.toString(10);
|
5627
5991
|
};
|