flash-sdk 10.10.6 → 10.100.2-alpha.0
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/dist/CustodyAccount.d.ts +2 -2
- package/dist/MarketAccount.d.ts +2 -2
- package/dist/MarketAccount.js +1 -1
- package/dist/OraclePrice.d.ts +4 -2
- package/dist/OraclePrice.js +23 -4
- package/dist/OrderAccount.d.ts +1 -1
- package/dist/PerpetualsClient.d.ts +385 -4332
- package/dist/PerpetualsClient.js +6254 -4927
- package/dist/PoolAccount.d.ts +3 -0
- package/dist/PoolConfig.d.ts +9 -2
- package/dist/PoolConfig.js +67 -4
- package/dist/PoolConfig.json +87 -4032
- package/dist/PoolDataClient.js +12 -11
- package/dist/PositionAccount.d.ts +6 -3
- package/dist/TokenStakeAccount.d.ts +24 -4
- package/dist/TokenStakeAccount.js +44 -2
- package/dist/TokenVaultAccount.d.ts +1 -0
- package/dist/ViewHelper.d.ts +2 -1
- package/dist/ViewHelper.js +17 -20
- package/dist/backupOracle.d.ts +0 -1
- package/dist/backupOracle.js +26 -5
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +2 -1
- package/dist/idl/perpetuals.d.ts +29203 -11085
- package/dist/idl/perpetuals.js +0 -16293
- package/dist/idl/perpetuals.json +34411 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -3
- package/dist/remoraTokensWithPriceIds.d.ts +13 -0
- package/dist/remoraTokensWithPriceIds.js +265 -0
- package/dist/testPublkey.d.ts +0 -0
- package/dist/testPublkey.js +0 -0
- package/dist/testSize.d.ts +0 -0
- package/dist/testSize.js +0 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/generated.d.ts +2556 -0
- package/dist/types/generated.js +2 -0
- package/dist/types/index.d.ts +52 -144
- package/dist/types/index.js +22 -4
- package/dist/utils/IdlCoder.d.ts +3 -2
- package/dist/utils/IdlCoder.js +4 -2
- package/dist/utils/anchorCpiEvents.d.ts +1 -2
- package/dist/utils/anchorCpiEvents.js +10 -6
- package/dist/utils/getReferralAccounts.d.ts +1 -1
- package/dist/utils/getReferralAccounts.js +3 -8
- package/dist/xstocksTokensWithPriceIds.d.ts +13 -0
- package/dist/xstocksTokensWithPriceIds.js +369 -0
- package/package.json +9 -5
- package/readme.md +37 -3
- package/dist/TradingAccount.d.ts +0 -24
- package/dist/TradingAccount.js +0 -17
- package/dist/idl/fbnft_rewards.d.ts +0 -290
- package/dist/idl/fbnft_rewards.js +0 -292
- package/dist/idl/perp_composability.d.ts +0 -760
- package/dist/idl/perp_composability.js +0 -762
- package/dist/idl/reward_distribution.d.ts +0 -347
- package/dist/idl/reward_distribution.js +0 -349
package/dist/PoolDataClient.js
CHANGED
|
@@ -32,11 +32,10 @@ var PoolDataClient = (function () {
|
|
|
32
32
|
return "continue";
|
|
33
33
|
var custodyAccount = this_1.custodies.find(function (t) { return t.mint.toBase58() === custodyConfig.mintKey.toBase58(); });
|
|
34
34
|
if (custodyAccount) {
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var ownedUsdBnUi = ownedBnUi.multipliedBy(priceBnUi);
|
|
35
|
+
var ownedUsd = pricesMap.get(custodyConfig.symbol).price.getAssetAmountUsd(custodyAccount.assets.owned, custodyConfig.decimals, custodyAccount.tokenAmountMultiplier);
|
|
36
|
+
var ownedUsdBnUi = new bignumber_js_1.default((0, utils_1.nativeToUiDecimals)(ownedUsd, constants_1.USD_DECIMALS, constants_1.USD_DECIMALS));
|
|
38
37
|
if (custodyAccount.isStable) {
|
|
39
|
-
stableCoinAmountBni = stableCoinAmountBni.plus(
|
|
38
|
+
stableCoinAmountBni = stableCoinAmountBni.plus(ownedUsdBnUi);
|
|
40
39
|
}
|
|
41
40
|
totalPoolValueUsdBnUi = totalPoolValueUsdBnUi.plus(ownedUsdBnUi);
|
|
42
41
|
}
|
|
@@ -74,27 +73,29 @@ var PoolDataClient = (function () {
|
|
|
74
73
|
var custodyAccount = this_2.custodies.find(function (t) { return t.mint.toBase58() === custodyConfig.mintKey.toBase58(); });
|
|
75
74
|
if (!custodyAccount)
|
|
76
75
|
return "continue";
|
|
77
|
-
var
|
|
76
|
+
var effectivePrice = pricesMap.get(custodyConfig.symbol).price.withMultiplier(custodyAccount.tokenAmountMultiplier);
|
|
77
|
+
var priceBnUi = new bignumber_js_1.default(effectivePrice.toUiPrice(8));
|
|
78
78
|
var ownedBnUi = new bignumber_js_1.default(custodyAccount.assets.owned.toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
79
|
-
var
|
|
79
|
+
var ownedUsd = pricesMap.get(custodyConfig.symbol).price.getAssetAmountUsd(custodyAccount.assets.owned, custodyConfig.decimals, custodyAccount.tokenAmountMultiplier);
|
|
80
|
+
var ownedUsdBnUi = new bignumber_js_1.default((0, utils_1.nativeToUiDecimals)(ownedUsd, constants_1.USD_DECIMALS, constants_1.USD_DECIMALS));
|
|
80
81
|
var lockedBnUi = new bignumber_js_1.default(custodyAccount.assets.locked.toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
81
82
|
var utilizationBnUi = (custodyAccount.assets.locked.isZero() || custodyAccount.assets.owned.isZero()) ? new bignumber_js_1.default(0) :
|
|
82
83
|
lockedBnUi.dividedBy(ownedBnUi).multipliedBy(100);
|
|
83
|
-
var currentRatioBnUi = totalPoolValueUsd.isZero() ? new bignumber_js_1.default(0) :
|
|
84
|
+
var currentRatioBnUi = totalPoolValueUsd.isZero() ? new bignumber_js_1.default(0) : ownedUsdBnUi.dividedBy(totalPoolValueUsdUi).multipliedBy(100);
|
|
84
85
|
var minRatioBnUi = tokenRatio.min.isZero() ? new bignumber_js_1.default(5) : new bignumber_js_1.default(tokenRatio.min.toString()).div(100);
|
|
85
86
|
var maxRatioBnUi = tokenRatio.max.toString() === '10000' ? new bignumber_js_1.default(95) : new bignumber_js_1.default(tokenRatio.max.toString()).div(100);
|
|
86
87
|
var availableToAddUsdBnUi = currentRatioBnUi.isGreaterThanOrEqualTo(maxRatioBnUi) ?
|
|
87
88
|
new bignumber_js_1.default(0) :
|
|
88
89
|
maxRatioBnUi.minus(currentRatioBnUi).multipliedBy(totalPoolValueUsdUi).div(100);
|
|
89
|
-
var availableToAddAmountBnUi = availableToAddUsdBnUi.dividedBy(
|
|
90
|
+
var availableToAddAmountBnUi = new bignumber_js_1.default(pricesMap.get(custodyConfig.symbol).price.getTokenAmount((0, utils_1.uiDecimalsToNative)(availableToAddUsdBnUi.toFixed(constants_1.USD_DECIMALS, bignumber_js_1.default.ROUND_DOWN), constants_1.USD_DECIMALS), custodyConfig.decimals, custodyAccount.tokenAmountMultiplier).toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
90
91
|
var availableToRemoveUsdUi = minRatioBnUi.isGreaterThanOrEqualTo(currentRatioBnUi) ?
|
|
91
92
|
new bignumber_js_1.default(0) :
|
|
92
93
|
currentRatioBnUi.minus(minRatioBnUi).multipliedBy(totalPoolValueUsdUi).div(100);
|
|
93
|
-
var availableToRemoveAmountBnUi = availableToRemoveUsdUi.dividedBy(
|
|
94
|
+
var availableToRemoveAmountBnUi = new bignumber_js_1.default(pricesMap.get(custodyConfig.symbol).price.getTokenAmount((0, utils_1.uiDecimalsToNative)(availableToRemoveUsdUi.toFixed(constants_1.USD_DECIMALS, bignumber_js_1.default.ROUND_DOWN), constants_1.USD_DECIMALS), custodyConfig.decimals, custodyAccount.tokenAmountMultiplier).toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
94
95
|
var minCapacityUsdBnUi = minRatioBnUi.multipliedBy(totalPoolValueUsdUi).div(100);
|
|
95
|
-
var minCapacityAmountBnUi = minCapacityUsdBnUi.dividedBy(
|
|
96
|
+
var minCapacityAmountBnUi = new bignumber_js_1.default(pricesMap.get(custodyConfig.symbol).price.getTokenAmount((0, utils_1.uiDecimalsToNative)(minCapacityUsdBnUi.toFixed(constants_1.USD_DECIMALS, bignumber_js_1.default.ROUND_DOWN), constants_1.USD_DECIMALS), custodyConfig.decimals, custodyAccount.tokenAmountMultiplier).toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
96
97
|
var maxCapacityUsdBnUi = maxRatioBnUi.multipliedBy(totalPoolValueUsdUi).div(100);
|
|
97
|
-
var maxCapacityAmountBnUi = maxCapacityUsdBnUi.dividedBy(
|
|
98
|
+
var maxCapacityAmountBnUi = new bignumber_js_1.default(pricesMap.get(custodyConfig.symbol).price.getTokenAmount((0, utils_1.uiDecimalsToNative)(maxCapacityUsdBnUi.toFixed(constants_1.USD_DECIMALS, bignumber_js_1.default.ROUND_DOWN), constants_1.USD_DECIMALS), custodyConfig.decimals, custodyAccount.tokenAmountMultiplier).toString()).dividedBy(Math.pow(10, custodyConfig.decimals));
|
|
98
99
|
if (custodyAccount && tokenRatio) {
|
|
99
100
|
custodyDetails.push({
|
|
100
101
|
symbol: custodyConfig.symbol,
|
|
@@ -14,13 +14,16 @@ export declare class PositionAccount implements Position {
|
|
|
14
14
|
sizeAmount: BN;
|
|
15
15
|
lockedAmount: BN;
|
|
16
16
|
lockedUsd: BN;
|
|
17
|
-
|
|
17
|
+
priceImpactUsd: BN;
|
|
18
18
|
collateralUsd: BN;
|
|
19
|
-
|
|
19
|
+
unsettledValueUsd: BN;
|
|
20
20
|
unsettledFeesUsd: BN;
|
|
21
21
|
cumulativeLockFeeSnapshot: BN;
|
|
22
22
|
degenSizeUsd: BN;
|
|
23
|
-
|
|
23
|
+
referencePrice: ContractOraclePrice;
|
|
24
|
+
isActive: boolean;
|
|
25
|
+
buffer: number[];
|
|
26
|
+
priceImpactSet: number;
|
|
24
27
|
sizeDecimals: number;
|
|
25
28
|
lockedDecimals: number;
|
|
26
29
|
collateralDecimals: number;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { TokenStake,
|
|
2
|
+
import { TokenStake, WithdrawRequest } from "./types";
|
|
3
3
|
import { BN } from "@coral-xyz/anchor";
|
|
4
4
|
import { PublicKey } from "@solana/web3.js";
|
|
5
|
+
export interface LockRequestStatus {
|
|
6
|
+
requestId: number;
|
|
7
|
+
lockedAmount: BN;
|
|
8
|
+
withdrawableAmount: BN;
|
|
9
|
+
timeRemaining: BN;
|
|
10
|
+
totalAmount: BN;
|
|
11
|
+
}
|
|
5
12
|
export declare class TokenStakeAccount implements TokenStake {
|
|
6
13
|
owner: PublicKey;
|
|
7
14
|
isInitialized: boolean;
|
|
8
15
|
bump: number;
|
|
9
16
|
level: number;
|
|
10
17
|
withdrawRequestCount: number;
|
|
11
|
-
withdrawRequest:
|
|
18
|
+
withdrawRequest: WithdrawRequest[];
|
|
19
|
+
rebateRate: BN;
|
|
12
20
|
activeStakeAmount: BN;
|
|
13
21
|
updateTimestamp: BN;
|
|
14
22
|
tradeTimestamp: BN;
|
|
@@ -17,6 +25,10 @@ export declare class TokenStakeAccount implements TokenStake {
|
|
|
17
25
|
rewardTokens: BN;
|
|
18
26
|
unclaimedRevenueAmount: BN;
|
|
19
27
|
revenueSnapshot: BN;
|
|
28
|
+
claimableRebateUsd: BN;
|
|
29
|
+
rebateUsdSnapshot: BN;
|
|
30
|
+
rebateDayTimestamp: BN;
|
|
31
|
+
maxRebateUsd: BN;
|
|
20
32
|
padding: BN[];
|
|
21
33
|
constructor(data: {
|
|
22
34
|
owner: PublicKey;
|
|
@@ -24,7 +36,8 @@ export declare class TokenStakeAccount implements TokenStake {
|
|
|
24
36
|
bump: number;
|
|
25
37
|
level: number;
|
|
26
38
|
withdrawRequestCount: number;
|
|
27
|
-
withdrawRequest:
|
|
39
|
+
withdrawRequest: WithdrawRequest[];
|
|
40
|
+
rebateRate: BN;
|
|
28
41
|
activeStakeAmount: BN;
|
|
29
42
|
updateTimestamp: BN;
|
|
30
43
|
tradeTimestamp: BN;
|
|
@@ -33,8 +46,15 @@ export declare class TokenStakeAccount implements TokenStake {
|
|
|
33
46
|
rewardTokens: BN;
|
|
34
47
|
unclaimedRevenueAmount: BN;
|
|
35
48
|
revenueSnapshot: BN;
|
|
36
|
-
|
|
49
|
+
claimableRebateUsd: BN;
|
|
50
|
+
rebateUsdSnapshot: BN;
|
|
51
|
+
rebateDayTimestamp: BN;
|
|
52
|
+
maxRebateUsd: BN;
|
|
37
53
|
});
|
|
38
54
|
static from(decodedData: any): TokenStakeAccount;
|
|
55
|
+
getLockedAmount(): BN;
|
|
56
|
+
getWithdrawableAmount(): BN;
|
|
57
|
+
getRevenueEligibleAmount(): BN;
|
|
58
|
+
getLockStatus(): LockRequestStatus[];
|
|
39
59
|
updateData(newData: Partial<TokenStakeAccount>): void;
|
|
40
60
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenStakeAccount = void 0;
|
|
4
4
|
var anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
var BN_ZERO = new anchor_1.BN(0);
|
|
5
6
|
var TokenStakeAccount = (function () {
|
|
6
7
|
function TokenStakeAccount(data) {
|
|
7
8
|
this.owner = data.owner;
|
|
@@ -10,6 +11,7 @@ var TokenStakeAccount = (function () {
|
|
|
10
11
|
this.level = data.level;
|
|
11
12
|
this.withdrawRequestCount = data.withdrawRequestCount;
|
|
12
13
|
this.withdrawRequest = data.withdrawRequest;
|
|
14
|
+
this.rebateRate = data.rebateRate;
|
|
13
15
|
this.activeStakeAmount = data.activeStakeAmount;
|
|
14
16
|
this.updateTimestamp = data.updateTimestamp;
|
|
15
17
|
this.tradeTimestamp = data.tradeTimestamp;
|
|
@@ -18,7 +20,10 @@ var TokenStakeAccount = (function () {
|
|
|
18
20
|
this.lastRewardEpochCount = data.lastRewardEpochCount;
|
|
19
21
|
this.unclaimedRevenueAmount = data.unclaimedRevenueAmount;
|
|
20
22
|
this.revenueSnapshot = data.revenueSnapshot;
|
|
21
|
-
this.
|
|
23
|
+
this.claimableRebateUsd = data.claimableRebateUsd;
|
|
24
|
+
this.rebateUsdSnapshot = data.rebateUsdSnapshot;
|
|
25
|
+
this.rebateDayTimestamp = data.rebateDayTimestamp;
|
|
26
|
+
this.maxRebateUsd = data.maxRebateUsd;
|
|
22
27
|
}
|
|
23
28
|
TokenStakeAccount.from = function (decodedData) {
|
|
24
29
|
return new TokenStakeAccount({
|
|
@@ -28,6 +33,7 @@ var TokenStakeAccount = (function () {
|
|
|
28
33
|
level: decodedData.level,
|
|
29
34
|
withdrawRequestCount: decodedData.withdrawRequestCount,
|
|
30
35
|
withdrawRequest: decodedData.withdrawRequest,
|
|
36
|
+
rebateRate: new anchor_1.BN(decodedData.rebateRate),
|
|
31
37
|
activeStakeAmount: new anchor_1.BN(decodedData.activeStakeAmount),
|
|
32
38
|
updateTimestamp: new anchor_1.BN(decodedData.updateTimestamp),
|
|
33
39
|
tradeTimestamp: new anchor_1.BN(decodedData.tradeTimestamp),
|
|
@@ -36,9 +42,45 @@ var TokenStakeAccount = (function () {
|
|
|
36
42
|
lastRewardEpochCount: decodedData.lastRewardEpochCount,
|
|
37
43
|
unclaimedRevenueAmount: decodedData.unclaimedRevenueAmount,
|
|
38
44
|
revenueSnapshot: decodedData.revenueSnapshot,
|
|
39
|
-
|
|
45
|
+
claimableRebateUsd: decodedData.claimableRebateUsd,
|
|
46
|
+
rebateUsdSnapshot: new anchor_1.BN(decodedData.rebateUsdSnapshot),
|
|
47
|
+
rebateDayTimestamp: new anchor_1.BN(decodedData.rebateDayTimestamp),
|
|
48
|
+
maxRebateUsd: new anchor_1.BN(decodedData.maxRebateUsd),
|
|
40
49
|
});
|
|
41
50
|
};
|
|
51
|
+
TokenStakeAccount.prototype.getLockedAmount = function () {
|
|
52
|
+
var total = BN_ZERO;
|
|
53
|
+
for (var i = 0; i < this.withdrawRequestCount; i++) {
|
|
54
|
+
total = total.add(new anchor_1.BN(this.withdrawRequest[i].lockedAmount));
|
|
55
|
+
}
|
|
56
|
+
return total;
|
|
57
|
+
};
|
|
58
|
+
TokenStakeAccount.prototype.getWithdrawableAmount = function () {
|
|
59
|
+
var total = BN_ZERO;
|
|
60
|
+
for (var i = 0; i < this.withdrawRequestCount; i++) {
|
|
61
|
+
total = total.add(new anchor_1.BN(this.withdrawRequest[i].withdrawableAmount));
|
|
62
|
+
}
|
|
63
|
+
return total;
|
|
64
|
+
};
|
|
65
|
+
TokenStakeAccount.prototype.getRevenueEligibleAmount = function () {
|
|
66
|
+
return this.activeStakeAmount.add(this.getLockedAmount());
|
|
67
|
+
};
|
|
68
|
+
TokenStakeAccount.prototype.getLockStatus = function () {
|
|
69
|
+
var statuses = [];
|
|
70
|
+
for (var i = 0; i < this.withdrawRequestCount; i++) {
|
|
71
|
+
var req = this.withdrawRequest[i];
|
|
72
|
+
var locked = new anchor_1.BN(req.lockedAmount);
|
|
73
|
+
var withdrawable = new anchor_1.BN(req.withdrawableAmount);
|
|
74
|
+
statuses.push({
|
|
75
|
+
requestId: i,
|
|
76
|
+
lockedAmount: locked,
|
|
77
|
+
withdrawableAmount: withdrawable,
|
|
78
|
+
timeRemaining: new anchor_1.BN(req.timeRemaining),
|
|
79
|
+
totalAmount: locked.add(withdrawable),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return statuses;
|
|
83
|
+
};
|
|
42
84
|
TokenStakeAccount.prototype.updateData = function (newData) {
|
|
43
85
|
Object.assign(this, newData);
|
|
44
86
|
};
|
|
@@ -27,6 +27,7 @@ export declare class TokenVaultAccount implements TokenVault {
|
|
|
27
27
|
revenueAccrued: BN;
|
|
28
28
|
revenueDistributed: BN;
|
|
29
29
|
revenuePaid: BN;
|
|
30
|
+
unlockPeriod: BN;
|
|
30
31
|
padding2: BN[];
|
|
31
32
|
constructor(publicKey: PublicKey, parseData: TokenVault);
|
|
32
33
|
static from(publicKey: PublicKey, parseData: TokenVault): TokenVaultAccount;
|
package/dist/ViewHelper.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PublicKey, RpcResponseAndContext, SimulatedTransactionResponse, Transaction } from "@solana/web3.js";
|
|
2
2
|
import { PerpetualsClient } from "./PerpetualsClient";
|
|
3
|
+
import { AddressLookupTableAccount } from "@solana/web3.js";
|
|
3
4
|
export declare class ViewHelper {
|
|
4
5
|
private perpetualsClient;
|
|
5
6
|
constructor(client: PerpetualsClient);
|
|
6
7
|
decodeLogs<T>(data: RpcResponseAndContext<SimulatedTransactionResponse>, instructionNumber: number, instructionName?: string): T | undefined;
|
|
7
|
-
simulateTransaction(transaction: Transaction, userPublicKey?: PublicKey | undefined): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
|
|
8
|
+
simulateTransaction(transaction: Transaction, addressLookupTableAccounts: AddressLookupTableAccount[], userPublicKey?: PublicKey | undefined): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
|
|
8
9
|
}
|
package/dist/ViewHelper.js
CHANGED
|
@@ -44,11 +44,14 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
44
|
}
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
47
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
51
|
exports.ViewHelper = void 0;
|
|
49
52
|
var web3_js_1 = require("@solana/web3.js");
|
|
50
53
|
var base64_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes/base64");
|
|
51
|
-
var
|
|
54
|
+
var perpetuals_json_1 = __importDefault(require("./idl/perpetuals.json"));
|
|
52
55
|
var IdlCoder_1 = require("./utils/IdlCoder");
|
|
53
56
|
var ViewHelper = (function () {
|
|
54
57
|
function ViewHelper(client) {
|
|
@@ -65,11 +68,11 @@ var ViewHelper = (function () {
|
|
|
65
68
|
throw new Error('View expected return log');
|
|
66
69
|
}
|
|
67
70
|
var returnData = (0, base64_1.decode)(returnLog.slice(returnPrefix_1.length));
|
|
68
|
-
var returnType =
|
|
71
|
+
var returnType = perpetuals_json_1.default.instructions[instructionNumber].returns;
|
|
69
72
|
if (!returnType) {
|
|
70
73
|
throw new Error('View expected return type');
|
|
71
74
|
}
|
|
72
|
-
var coder = IdlCoder_1.IdlCoder.fieldLayout({ type: returnType }, Array.from(__spreadArray(__spreadArray([], ((_a =
|
|
75
|
+
var coder = IdlCoder_1.IdlCoder.fieldLayout({ type: returnType }, Array.from(__spreadArray(__spreadArray([], ((_a = perpetuals_json_1.default.accounts) !== null && _a !== void 0 ? _a : []), true), ((_b = perpetuals_json_1.default.types) !== null && _b !== void 0 ? _b : []), true)));
|
|
73
76
|
return coder.decode(returnData);
|
|
74
77
|
}
|
|
75
78
|
else {
|
|
@@ -82,25 +85,19 @@ var ViewHelper = (function () {
|
|
|
82
85
|
console.log("decode error::", error);
|
|
83
86
|
}
|
|
84
87
|
};
|
|
85
|
-
ViewHelper.prototype.simulateTransaction = function (transaction_1) {
|
|
86
|
-
return __awaiter(this, arguments, void 0, function (transaction, userPublicKey) {
|
|
87
|
-
var
|
|
88
|
+
ViewHelper.prototype.simulateTransaction = function (transaction_1, addressLookupTableAccounts_1) {
|
|
89
|
+
return __awaiter(this, arguments, void 0, function (transaction, addressLookupTableAccounts, userPublicKey) {
|
|
90
|
+
var messageV0, transaction2;
|
|
88
91
|
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
|
89
92
|
return __generator(this, function (_a) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
recentBlockhash: latestBlockhash.blockhash,
|
|
99
|
-
instructions: transaction.instructions,
|
|
100
|
-
}).compileToV0Message(this.perpetualsClient.addressLookupTables);
|
|
101
|
-
transaction2 = new web3_js_1.VersionedTransaction(messageV0);
|
|
102
|
-
return [2, this.perpetualsClient.provider.connection.simulateTransaction(transaction2, { sigVerify: false, replaceRecentBlockhash: true })];
|
|
103
|
-
}
|
|
93
|
+
transaction.feePayer = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.perpetualsClient.provider.publicKey;
|
|
94
|
+
messageV0 = new web3_js_1.TransactionMessage({
|
|
95
|
+
payerKey: this.perpetualsClient.provider.publicKey,
|
|
96
|
+
recentBlockhash: web3_js_1.PublicKey.default.toBase58(),
|
|
97
|
+
instructions: transaction.instructions,
|
|
98
|
+
}).compileToV0Message(addressLookupTableAccounts);
|
|
99
|
+
transaction2 = new web3_js_1.VersionedTransaction(messageV0);
|
|
100
|
+
return [2, this.perpetualsClient.provider.connection.simulateTransaction(transaction2, { sigVerify: false, replaceRecentBlockhash: true })];
|
|
104
101
|
});
|
|
105
102
|
});
|
|
106
103
|
};
|
package/dist/backupOracle.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { PoolConfig } from "./PoolConfig";
|
|
|
4
4
|
import { BackupOracle } from "./types";
|
|
5
5
|
import { Program } from "@coral-xyz/anchor";
|
|
6
6
|
import { Perpetuals } from "./idl/perpetuals";
|
|
7
|
-
export declare const API_ENDPOINT: string;
|
|
8
7
|
export declare const pythPriceServiceConnection: PriceServiceConnection;
|
|
9
8
|
export declare const getPythnetOraclePrices: (program: Program<Perpetuals>, poolConfig: PoolConfig, backupOracleSecretKey: string) => Promise<TransactionInstruction>;
|
|
10
9
|
export declare const getBackupOracleInstruction: (program: Program<Perpetuals>, poolConfig: PoolConfig, backupOracleSecretKey: string, backupCaches: BackupOracle[]) => TransactionInstruction;
|
package/dist/backupOracle.js
CHANGED
|
@@ -40,13 +40,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
var _a;
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.createBackupOracleInstruction = exports.getBackupOracleInstruction = exports.getPythnetOraclePrices = exports.pythPriceServiceConnection =
|
|
43
|
+
exports.createBackupOracleInstruction = exports.getBackupOracleInstruction = exports.getPythnetOraclePrices = exports.pythPriceServiceConnection = void 0;
|
|
44
44
|
var price_service_client_1 = require("@pythnetwork/price-service-client");
|
|
45
45
|
var web3_js_1 = require("@solana/web3.js");
|
|
46
46
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
47
47
|
var bs58_1 = __importDefault(require("bs58"));
|
|
48
48
|
var tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
49
|
-
|
|
49
|
+
var BACKUP_ORACLE_SIZE = 36;
|
|
50
|
+
function encodePermissionlessPythCache(cache) {
|
|
51
|
+
var backupCache = cache.backupCache;
|
|
52
|
+
var buf = Buffer.alloc(4 + backupCache.length * BACKUP_ORACLE_SIZE);
|
|
53
|
+
buf.writeUInt32LE(backupCache.length, 0);
|
|
54
|
+
var offset = 4;
|
|
55
|
+
for (var _i = 0, backupCache_1 = backupCache; _i < backupCache_1.length; _i++) {
|
|
56
|
+
var oracle = backupCache_1[_i];
|
|
57
|
+
buf.writeBigInt64LE(BigInt(oracle.price.toString()), offset);
|
|
58
|
+
offset += 8;
|
|
59
|
+
buf.writeInt32LE(oracle.expo, offset);
|
|
60
|
+
offset += 4;
|
|
61
|
+
buf.writeBigInt64LE(BigInt(oracle.conf.toString()), offset);
|
|
62
|
+
offset += 8;
|
|
63
|
+
buf.writeBigInt64LE(BigInt(oracle.emaPrice.toString()), offset);
|
|
64
|
+
offset += 8;
|
|
65
|
+
buf.writeBigInt64LE(BigInt(oracle.publishTime.toString()), offset);
|
|
66
|
+
offset += 8;
|
|
67
|
+
}
|
|
68
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
69
|
+
}
|
|
70
|
+
var API_ENDPOINT = (_a = process.env.NEXT_PUBLIC_API_ENDPOINT) !== null && _a !== void 0 ? _a : 'https://api.prod.flash.trade';
|
|
50
71
|
exports.pythPriceServiceConnection = new price_service_client_1.PriceServiceConnection('https://hermes.pyth.network', {
|
|
51
72
|
priceFeedRequestConfig: {},
|
|
52
73
|
});
|
|
@@ -88,7 +109,7 @@ var getPythnetOraclePrices = function (program, poolConfig, backupOracleSecretKe
|
|
|
88
109
|
permissionlessPythCache = {
|
|
89
110
|
backupCache: caches_1
|
|
90
111
|
};
|
|
91
|
-
message =
|
|
112
|
+
message = encodePermissionlessPythCache(permissionlessPythCache);
|
|
92
113
|
signature = tweetnacl_1.default.sign.detached(message, backupOracleAccount.secretKey);
|
|
93
114
|
preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
94
115
|
publicKey: backupOracleAccount.publicKey.toBytes(),
|
|
@@ -114,7 +135,7 @@ var getBackupOracleInstruction = function (program, poolConfig, backupOracleSecr
|
|
|
114
135
|
var permissionlessPythCache = {
|
|
115
136
|
backupCache: backupCaches
|
|
116
137
|
};
|
|
117
|
-
var message =
|
|
138
|
+
var message = encodePermissionlessPythCache(permissionlessPythCache);
|
|
118
139
|
var signature = tweetnacl_1.default.sign.detached(message, backupOracleAccount.secretKey);
|
|
119
140
|
var preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
120
141
|
publicKey: backupOracleAccount.publicKey.toBytes(),
|
|
@@ -137,7 +158,7 @@ function createBackupOracleInstruction(poolAddress_1) {
|
|
|
137
158
|
switch (_a.label) {
|
|
138
159
|
case 0:
|
|
139
160
|
_a.trys.push([0, 3, , 4]);
|
|
140
|
-
return [4, fetch("".concat(
|
|
161
|
+
return [4, fetch("".concat(API_ENDPOINT, "/backup-oracle/prices?poolAddress=").concat(poolAddress))];
|
|
141
162
|
case 1: return [4, (_a.sent()).json()];
|
|
142
163
|
case 2:
|
|
143
164
|
backupOracleData = _a.sent();
|
package/dist/constants/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.METAPLEX_PROGRAM_ID = exports.DAY_SECONDS = exports.BN_ONE = exports.BN_ZERO = exports.ORACLE_EXPONENT = exports.RATE_POWER = exports.RATE_DECIMALS = exports.FAF_DECIMALS = exports.LP_DECIMALS = exports.BPS_POWER = exports.BPS_DECIMALS = exports.USD_DECIMALS = exports.PERCENTAGE_DECIMALS = void 0;
|
|
3
|
+
exports.PYTH_LAZER_PROGRAM_ID = exports.METAPLEX_PROGRAM_ID = exports.DAY_SECONDS = exports.BN_ONE = exports.BN_ZERO = exports.ORACLE_EXPONENT = exports.RATE_POWER = exports.RATE_DECIMALS = exports.FAF_DECIMALS = exports.LP_DECIMALS = exports.BPS_POWER = exports.BPS_DECIMALS = exports.USD_DECIMALS = exports.PERCENTAGE_DECIMALS = void 0;
|
|
4
4
|
var web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
var bn_js_1 = require("bn.js");
|
|
6
6
|
exports.PERCENTAGE_DECIMALS = 4;
|
|
@@ -16,3 +16,4 @@ exports.BN_ZERO = new bn_js_1.BN(0);
|
|
|
16
16
|
exports.BN_ONE = new bn_js_1.BN(1);
|
|
17
17
|
exports.DAY_SECONDS = new bn_js_1.BN(3600);
|
|
18
18
|
exports.METAPLEX_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
19
|
+
exports.PYTH_LAZER_PROGRAM_ID = new web3_js_1.PublicKey("pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt");
|