wasabi-solana-ts 1.2.5 → 1.2.7-regular-interest
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/error-handling/titan.d.ts +757 -0
- package/dist/error-handling/titan.js +759 -0
- package/dist/error-handling/transactionErrorHandling.js +31 -6
- package/dist/idl/wasabi_solana.d.ts +41 -55
- package/dist/idl/wasabi_solana.json +45 -59
- package/dist/utils/utils.d.ts +0 -1
- package/dist/utils/utils.js +22 -20
- package/package.json +1 -1
- package/src/idl/wasabi_solana.json +45 -59
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getFailingSwapProgram = exports.matchError = exports.parseErrorLogs = exports.parseSimulationError = exports.parseError = exports.parseSendTransactionError = exports.SimulationError = void 0;
|
|
27
27
|
const jupiter_1 = require("./jupiter");
|
|
28
|
+
const titan_1 = require("./titan");
|
|
28
29
|
const web3_js_1 = require("@solana/web3.js");
|
|
29
30
|
const spl_token_1 = require("@solana/spl-token");
|
|
30
31
|
const idl = __importStar(require("../idl/wasabi_solana.json"));
|
|
@@ -52,6 +53,10 @@ const jupiterProgramId = 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4';
|
|
|
52
53
|
const jupiterExpectedErrors = [
|
|
53
54
|
6001 // SlippageToleranceExceeded
|
|
54
55
|
];
|
|
56
|
+
const titanProgramId = 'T1TANpTeScyeqVzzgNViGDNrkQ6qHz9KrSBS4aNXvGT';
|
|
57
|
+
const titanExpectedErrors = [
|
|
58
|
+
6008 // LessThanMinimumAmountOut
|
|
59
|
+
];
|
|
55
60
|
//@ts-ignore
|
|
56
61
|
const raydiumErrors = [
|
|
57
62
|
6028, // Invalid first tick array
|
|
@@ -81,6 +86,18 @@ const jupiterErrorIndex = jupiter_1.IDL.errors.reduce((acc, error) => {
|
|
|
81
86
|
const findJupiterError = (code) => {
|
|
82
87
|
return jupiterErrorIndex[code];
|
|
83
88
|
};
|
|
89
|
+
const titanErrorIndex = titan_1.IDL.errors.reduce((acc, error) => {
|
|
90
|
+
const expected = titanExpectedErrors.includes(error.code);
|
|
91
|
+
acc[error.code] = {
|
|
92
|
+
...error,
|
|
93
|
+
expected,
|
|
94
|
+
program: 'Titan'
|
|
95
|
+
};
|
|
96
|
+
return acc;
|
|
97
|
+
}, {});
|
|
98
|
+
const findTitanError = (code) => {
|
|
99
|
+
return titanErrorIndex[code];
|
|
100
|
+
};
|
|
84
101
|
const parseSendTransactionError = (error, transaction) => {
|
|
85
102
|
const message = error.transactionError.message;
|
|
86
103
|
// Parse error messages like: "Transaction simulation failed: Error processing Instruction 3: custom program error: 0x1771"
|
|
@@ -108,6 +125,9 @@ const parseError = (instructionNumber, errorCode, transaction) => {
|
|
|
108
125
|
else if (programId === jupiterProgramId) {
|
|
109
126
|
return findJupiterError(errorCode);
|
|
110
127
|
}
|
|
128
|
+
else if (programId === titanProgramId) {
|
|
129
|
+
return findTitanError(errorCode);
|
|
130
|
+
}
|
|
111
131
|
return undefined;
|
|
112
132
|
};
|
|
113
133
|
exports.parseError = parseError;
|
|
@@ -153,14 +173,19 @@ const parseErrorLogs = (logs) => {
|
|
|
153
173
|
}
|
|
154
174
|
const match = log.match(/^Program ([a-zA-Z0-9]+) failed: (?:.*?): (0x[0-9a-fA-F]+)$/);
|
|
155
175
|
if (match) {
|
|
156
|
-
|
|
157
|
-
|
|
176
|
+
const [_, failingProgramId, errorHex] = match;
|
|
177
|
+
const errorCode = parseInt(errorHex);
|
|
178
|
+
if (failingProgramId.localeCompare(jupiterProgramId) === 0) {
|
|
179
|
+
return findJupiterError(errorCode);
|
|
180
|
+
}
|
|
181
|
+
else if (failingProgramId.localeCompare(titanProgramId) === 0) {
|
|
182
|
+
return findTitanError(errorCode);
|
|
158
183
|
}
|
|
159
|
-
else if (
|
|
160
|
-
return findWasabiError(
|
|
184
|
+
else if (failingProgramId.localeCompare(wasabiProgramId) === 0) {
|
|
185
|
+
return findWasabiError(errorCode);
|
|
161
186
|
}
|
|
162
|
-
else if (
|
|
163
|
-
return parseSystemError(
|
|
187
|
+
else if (failingProgramId.localeCompare(web3_js_1.SystemProgram.programId.toBase58())) {
|
|
188
|
+
return parseSystemError(errorCode, web3_js_1.SystemProgram.programId.toBase58());
|
|
164
189
|
}
|
|
165
190
|
}
|
|
166
191
|
}
|
|
@@ -7699,16 +7699,16 @@ export type WasabiSolana = {
|
|
|
7699
7699
|
];
|
|
7700
7700
|
},
|
|
7701
7701
|
{
|
|
7702
|
-
"name": "
|
|
7702
|
+
"name": "recordLongInterest";
|
|
7703
7703
|
"discriminator": [
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7704
|
+
101,
|
|
7705
|
+
57,
|
|
7706
|
+
251,
|
|
7707
|
+
97,
|
|
7708
|
+
19,
|
|
7709
|
+
118,
|
|
7710
|
+
203,
|
|
7711
|
+
222
|
|
7712
7712
|
];
|
|
7713
7713
|
"accounts": [
|
|
7714
7714
|
{
|
|
@@ -7722,25 +7722,16 @@ export type WasabiSolana = {
|
|
|
7722
7722
|
"name": "permission";
|
|
7723
7723
|
},
|
|
7724
7724
|
{
|
|
7725
|
-
"name": "
|
|
7726
|
-
"writable": true;
|
|
7727
|
-
"relations": [
|
|
7728
|
-
"position"
|
|
7729
|
-
];
|
|
7730
|
-
},
|
|
7731
|
-
{
|
|
7732
|
-
"name": "vault";
|
|
7725
|
+
"name": "pool";
|
|
7733
7726
|
"writable": true;
|
|
7734
|
-
"relations": [
|
|
7735
|
-
"lpVault"
|
|
7736
|
-
];
|
|
7737
7727
|
},
|
|
7738
7728
|
{
|
|
7739
7729
|
"name": "position";
|
|
7740
7730
|
"writable": true;
|
|
7741
7731
|
},
|
|
7742
7732
|
{
|
|
7743
|
-
"name": "
|
|
7733
|
+
"name": "lpVault";
|
|
7734
|
+
"writable": true;
|
|
7744
7735
|
"relations": [
|
|
7745
7736
|
"position"
|
|
7746
7737
|
];
|
|
@@ -7798,9 +7789,6 @@ export type WasabiSolana = {
|
|
|
7798
7789
|
}
|
|
7799
7790
|
];
|
|
7800
7791
|
};
|
|
7801
|
-
},
|
|
7802
|
-
{
|
|
7803
|
-
"name": "tokenProgram";
|
|
7804
7792
|
}
|
|
7805
7793
|
];
|
|
7806
7794
|
"args": [
|
|
@@ -7811,16 +7799,16 @@ export type WasabiSolana = {
|
|
|
7811
7799
|
];
|
|
7812
7800
|
},
|
|
7813
7801
|
{
|
|
7814
|
-
"name": "
|
|
7802
|
+
"name": "recordShortInterest";
|
|
7815
7803
|
"discriminator": [
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7804
|
+
54,
|
|
7805
|
+
196,
|
|
7806
|
+
121,
|
|
7807
|
+
111,
|
|
7820
7808
|
120,
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7809
|
+
233,
|
|
7810
|
+
41,
|
|
7811
|
+
104
|
|
7824
7812
|
];
|
|
7825
7813
|
"accounts": [
|
|
7826
7814
|
{
|
|
@@ -7834,26 +7822,19 @@ export type WasabiSolana = {
|
|
|
7834
7822
|
"name": "permission";
|
|
7835
7823
|
},
|
|
7836
7824
|
{
|
|
7837
|
-
"name": "
|
|
7825
|
+
"name": "pool";
|
|
7838
7826
|
"writable": true;
|
|
7839
|
-
"relations": [
|
|
7840
|
-
"position"
|
|
7841
|
-
];
|
|
7842
|
-
},
|
|
7843
|
-
{
|
|
7844
|
-
"name": "vault";
|
|
7845
|
-
"writable": true;
|
|
7846
|
-
"relations": [
|
|
7847
|
-
"lpVault"
|
|
7848
|
-
];
|
|
7849
7827
|
},
|
|
7850
7828
|
{
|
|
7851
7829
|
"name": "position";
|
|
7852
7830
|
"writable": true;
|
|
7853
7831
|
},
|
|
7854
7832
|
{
|
|
7855
|
-
"name": "
|
|
7833
|
+
"name": "lpVault";
|
|
7856
7834
|
"writable": true;
|
|
7835
|
+
"relations": [
|
|
7836
|
+
"position"
|
|
7837
|
+
];
|
|
7857
7838
|
},
|
|
7858
7839
|
{
|
|
7859
7840
|
"name": "currencyVault";
|
|
@@ -7866,20 +7847,22 @@ export type WasabiSolana = {
|
|
|
7866
7847
|
"name": "collateralVault";
|
|
7867
7848
|
"writable": true;
|
|
7868
7849
|
"relations": [
|
|
7869
|
-
"pool"
|
|
7850
|
+
"pool",
|
|
7851
|
+
"position"
|
|
7870
7852
|
];
|
|
7871
7853
|
},
|
|
7872
7854
|
{
|
|
7873
|
-
"name": "
|
|
7855
|
+
"name": "vault";
|
|
7856
|
+
"writable": true;
|
|
7874
7857
|
"relations": [
|
|
7875
|
-
"
|
|
7858
|
+
"lpVault"
|
|
7876
7859
|
];
|
|
7877
7860
|
},
|
|
7861
|
+
{
|
|
7862
|
+
"name": "currency";
|
|
7863
|
+
},
|
|
7878
7864
|
{
|
|
7879
7865
|
"name": "collateral";
|
|
7880
|
-
"relations": [
|
|
7881
|
-
"position"
|
|
7882
|
-
];
|
|
7883
7866
|
},
|
|
7884
7867
|
{
|
|
7885
7868
|
"name": "debtController";
|
|
@@ -12183,11 +12166,6 @@ export type WasabiSolana = {
|
|
|
12183
12166
|
},
|
|
12184
12167
|
{
|
|
12185
12168
|
"code": 6041;
|
|
12186
|
-
"name": "invalidInterestAmount";
|
|
12187
|
-
"msg": "Invalid interest amount";
|
|
12188
|
-
},
|
|
12189
|
-
{
|
|
12190
|
-
"code": 6042;
|
|
12191
12169
|
"name": "maxInterestExceeded";
|
|
12192
12170
|
"msg": "Interest payment exceeds maximum interest";
|
|
12193
12171
|
}
|
|
@@ -12607,6 +12585,10 @@ export type WasabiSolana = {
|
|
|
12607
12585
|
"name": "id";
|
|
12608
12586
|
"type": "pubkey";
|
|
12609
12587
|
},
|
|
12588
|
+
{
|
|
12589
|
+
"name": "trader";
|
|
12590
|
+
"type": "pubkey";
|
|
12591
|
+
},
|
|
12610
12592
|
{
|
|
12611
12593
|
"name": "interestPaid";
|
|
12612
12594
|
"type": "u64";
|
|
@@ -12622,6 +12604,10 @@ export type WasabiSolana = {
|
|
|
12622
12604
|
{
|
|
12623
12605
|
"name": "downPaymentReduced";
|
|
12624
12606
|
"type": "u64";
|
|
12607
|
+
},
|
|
12608
|
+
{
|
|
12609
|
+
"name": "isLong";
|
|
12610
|
+
"type": "bool";
|
|
12625
12611
|
}
|
|
12626
12612
|
];
|
|
12627
12613
|
};
|
|
@@ -7693,16 +7693,16 @@
|
|
|
7693
7693
|
]
|
|
7694
7694
|
},
|
|
7695
7695
|
{
|
|
7696
|
-
"name": "
|
|
7696
|
+
"name": "record_long_interest",
|
|
7697
7697
|
"discriminator": [
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7698
|
+
101,
|
|
7699
|
+
57,
|
|
7700
|
+
251,
|
|
7701
|
+
97,
|
|
7702
|
+
19,
|
|
7703
|
+
118,
|
|
7704
|
+
203,
|
|
7705
|
+
222
|
|
7706
7706
|
],
|
|
7707
7707
|
"accounts": [
|
|
7708
7708
|
{
|
|
@@ -7716,25 +7716,16 @@
|
|
|
7716
7716
|
"name": "permission"
|
|
7717
7717
|
},
|
|
7718
7718
|
{
|
|
7719
|
-
"name": "
|
|
7720
|
-
"writable": true
|
|
7721
|
-
"relations": [
|
|
7722
|
-
"position"
|
|
7723
|
-
]
|
|
7724
|
-
},
|
|
7725
|
-
{
|
|
7726
|
-
"name": "vault",
|
|
7727
|
-
"writable": true,
|
|
7728
|
-
"relations": [
|
|
7729
|
-
"lp_vault"
|
|
7730
|
-
]
|
|
7719
|
+
"name": "pool",
|
|
7720
|
+
"writable": true
|
|
7731
7721
|
},
|
|
7732
7722
|
{
|
|
7733
7723
|
"name": "position",
|
|
7734
7724
|
"writable": true
|
|
7735
7725
|
},
|
|
7736
7726
|
{
|
|
7737
|
-
"name": "
|
|
7727
|
+
"name": "lp_vault",
|
|
7728
|
+
"writable": true,
|
|
7738
7729
|
"relations": [
|
|
7739
7730
|
"position"
|
|
7740
7731
|
]
|
|
@@ -7792,9 +7783,6 @@
|
|
|
7792
7783
|
}
|
|
7793
7784
|
]
|
|
7794
7785
|
}
|
|
7795
|
-
},
|
|
7796
|
-
{
|
|
7797
|
-
"name": "token_program"
|
|
7798
7786
|
}
|
|
7799
7787
|
],
|
|
7800
7788
|
"args": [
|
|
@@ -7805,16 +7793,16 @@
|
|
|
7805
7793
|
]
|
|
7806
7794
|
},
|
|
7807
7795
|
{
|
|
7808
|
-
"name": "
|
|
7796
|
+
"name": "record_short_interest",
|
|
7809
7797
|
"discriminator": [
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7798
|
+
54,
|
|
7799
|
+
196,
|
|
7800
|
+
121,
|
|
7801
|
+
111,
|
|
7814
7802
|
120,
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7803
|
+
233,
|
|
7804
|
+
41,
|
|
7805
|
+
104
|
|
7818
7806
|
],
|
|
7819
7807
|
"accounts": [
|
|
7820
7808
|
{
|
|
@@ -7828,26 +7816,19 @@
|
|
|
7828
7816
|
"name": "permission"
|
|
7829
7817
|
},
|
|
7830
7818
|
{
|
|
7831
|
-
"name": "
|
|
7832
|
-
"writable": true
|
|
7833
|
-
"relations": [
|
|
7834
|
-
"position"
|
|
7835
|
-
]
|
|
7836
|
-
},
|
|
7837
|
-
{
|
|
7838
|
-
"name": "vault",
|
|
7839
|
-
"writable": true,
|
|
7840
|
-
"relations": [
|
|
7841
|
-
"lp_vault"
|
|
7842
|
-
]
|
|
7819
|
+
"name": "pool",
|
|
7820
|
+
"writable": true
|
|
7843
7821
|
},
|
|
7844
7822
|
{
|
|
7845
7823
|
"name": "position",
|
|
7846
7824
|
"writable": true
|
|
7847
7825
|
},
|
|
7848
7826
|
{
|
|
7849
|
-
"name": "
|
|
7850
|
-
"writable": true
|
|
7827
|
+
"name": "lp_vault",
|
|
7828
|
+
"writable": true,
|
|
7829
|
+
"relations": [
|
|
7830
|
+
"position"
|
|
7831
|
+
]
|
|
7851
7832
|
},
|
|
7852
7833
|
{
|
|
7853
7834
|
"name": "currency_vault",
|
|
@@ -7860,20 +7841,22 @@
|
|
|
7860
7841
|
"name": "collateral_vault",
|
|
7861
7842
|
"writable": true,
|
|
7862
7843
|
"relations": [
|
|
7863
|
-
"pool"
|
|
7844
|
+
"pool",
|
|
7845
|
+
"position"
|
|
7864
7846
|
]
|
|
7865
7847
|
},
|
|
7866
7848
|
{
|
|
7867
|
-
"name": "
|
|
7849
|
+
"name": "vault",
|
|
7850
|
+
"writable": true,
|
|
7868
7851
|
"relations": [
|
|
7869
|
-
"
|
|
7852
|
+
"lp_vault"
|
|
7870
7853
|
]
|
|
7871
7854
|
},
|
|
7872
7855
|
{
|
|
7873
|
-
"name": "
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7856
|
+
"name": "currency"
|
|
7857
|
+
},
|
|
7858
|
+
{
|
|
7859
|
+
"name": "collateral"
|
|
7877
7860
|
},
|
|
7878
7861
|
{
|
|
7879
7862
|
"name": "debt_controller",
|
|
@@ -12177,11 +12160,6 @@
|
|
|
12177
12160
|
},
|
|
12178
12161
|
{
|
|
12179
12162
|
"code": 6041,
|
|
12180
|
-
"name": "InvalidInterestAmount",
|
|
12181
|
-
"msg": "Invalid interest amount"
|
|
12182
|
-
},
|
|
12183
|
-
{
|
|
12184
|
-
"code": 6042,
|
|
12185
12163
|
"name": "MaxInterestExceeded",
|
|
12186
12164
|
"msg": "Interest payment exceeds maximum interest"
|
|
12187
12165
|
}
|
|
@@ -12601,6 +12579,10 @@
|
|
|
12601
12579
|
"name": "id",
|
|
12602
12580
|
"type": "pubkey"
|
|
12603
12581
|
},
|
|
12582
|
+
{
|
|
12583
|
+
"name": "trader",
|
|
12584
|
+
"type": "pubkey"
|
|
12585
|
+
},
|
|
12604
12586
|
{
|
|
12605
12587
|
"name": "interest_paid",
|
|
12606
12588
|
"type": "u64"
|
|
@@ -12616,6 +12598,10 @@
|
|
|
12616
12598
|
{
|
|
12617
12599
|
"name": "down_payment_reduced",
|
|
12618
12600
|
"type": "u64"
|
|
12601
|
+
},
|
|
12602
|
+
{
|
|
12603
|
+
"name": "is_long",
|
|
12604
|
+
"type": "bool"
|
|
12619
12605
|
}
|
|
12620
12606
|
]
|
|
12621
12607
|
}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export declare function getPermission(program: Program<WasabiSolana>, admin: Pub
|
|
|
26
26
|
export declare function uiAmountToAmount(uiAmount: number, decimals: number): BN;
|
|
27
27
|
export declare function amountToUiAmount(amount: BN, decimals: number): number;
|
|
28
28
|
export declare function getTokenProgram(connection: Connection, mint: PublicKey, mintCache?: TokenMintCache): Promise<PublicKey | null>;
|
|
29
|
-
export declare function getTokenProgramAndDecimals(connection: Connection, mint: PublicKey): Promise<[PublicKey, number] | null>;
|
|
30
29
|
export declare const PDA: {
|
|
31
30
|
getLongPool(collateral: PublicKey, currency: PublicKey): PublicKey;
|
|
32
31
|
getShortPool(collateral: PublicKey, currency: PublicKey): PublicKey;
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.PDA = exports.SEED_PREFIX = exports.METADATA_PROGRAM_ID = exports.WASABI_PROGRAM_ID = exports.SOL_MINT = void 0;
|
|
4
7
|
exports.getPermission = getPermission;
|
|
5
8
|
exports.uiAmountToAmount = uiAmountToAmount;
|
|
6
9
|
exports.amountToUiAmount = amountToUiAmount;
|
|
7
10
|
exports.getTokenProgram = getTokenProgram;
|
|
8
|
-
exports.getTokenProgramAndDecimals = getTokenProgramAndDecimals;
|
|
9
11
|
exports.getMintInfo = getMintInfo;
|
|
10
12
|
exports.getMetaplexMetadata = getMetaplexMetadata;
|
|
11
13
|
exports.getMaxWithdraw = getMaxWithdraw;
|
|
@@ -37,6 +39,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
37
39
|
const spl_token_1 = require("@solana/spl-token");
|
|
38
40
|
const js_1 = require("@metaplex-foundation/js");
|
|
39
41
|
const TokenMintCache_1 = require("../cache/TokenMintCache");
|
|
42
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
40
43
|
exports.SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111111');
|
|
41
44
|
exports.WASABI_PROGRAM_ID = new web3_js_1.PublicKey('spicyTHtbmarmUxwFSHYpA8G4uP2nRNq38RReMpoZ9c');
|
|
42
45
|
exports.METADATA_PROGRAM_ID = new web3_js_1.PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
|
|
@@ -61,6 +64,18 @@ function findProgramAddress(seeds, programId) {
|
|
|
61
64
|
const [publicKey] = web3_js_1.PublicKey.findProgramAddressSync(seeds, programId);
|
|
62
65
|
return publicKey;
|
|
63
66
|
}
|
|
67
|
+
const tokenAccountCache = new node_cache_1.default({ stdTTL: 5 * 60 }); // 5 minutes TTL
|
|
68
|
+
const getTokenAccountCached = async (connection, address) => {
|
|
69
|
+
const cached = tokenAccountCache.get(address.toString());
|
|
70
|
+
if (cached) {
|
|
71
|
+
return cached;
|
|
72
|
+
}
|
|
73
|
+
const accountInfo = await connection.getAccountInfo(address);
|
|
74
|
+
if (accountInfo) {
|
|
75
|
+
tokenAccountCache.set(address.toString(), accountInfo);
|
|
76
|
+
}
|
|
77
|
+
return accountInfo;
|
|
78
|
+
};
|
|
64
79
|
async function getPermission(program, admin) {
|
|
65
80
|
let permission;
|
|
66
81
|
const superAdmin = exports.PDA.getSuperAdmin();
|
|
@@ -86,19 +101,6 @@ async function getTokenProgram(connection, mint, mintCache) {
|
|
|
86
101
|
const mintInfo = await mintCache.getAccount(mint);
|
|
87
102
|
return mintInfo.program;
|
|
88
103
|
}
|
|
89
|
-
async function getTokenProgramAndDecimals(connection, mint) {
|
|
90
|
-
const mintInfo = await connection.getAccountInfo(mint);
|
|
91
|
-
if (!mintInfo) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
if (mintInfo.owner.equals(spl_token_1.TOKEN_PROGRAM_ID) || mintInfo.owner.equals(spl_token_1.TOKEN_2022_PROGRAM_ID)) {
|
|
95
|
-
const mintDecimals = spl_token_1.MintLayout.decode(mintInfo.data).decimals;
|
|
96
|
-
return [mintInfo.owner, mintDecimals];
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
104
|
exports.PDA = {
|
|
103
105
|
getLongPool(collateral, currency) {
|
|
104
106
|
return findProgramAddress([
|
|
@@ -326,7 +328,7 @@ function isNativeMint(mint) {
|
|
|
326
328
|
async function createAtaIfNeeded(connection, owner, mint, ata, tokenProgram, payer) {
|
|
327
329
|
if (isNativeMint(mint))
|
|
328
330
|
return null;
|
|
329
|
-
const account = await connection
|
|
331
|
+
const account = await getTokenAccountCached(connection, ata);
|
|
330
332
|
if (!account) {
|
|
331
333
|
return (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer ? payer : owner, ata, owner, mint, tokenProgram);
|
|
332
334
|
}
|
|
@@ -339,7 +341,7 @@ async function createWrapSolInstruction(connection, owner, amount, includeCleanu
|
|
|
339
341
|
? [spl_token_1.NATIVE_MINT_2022, spl_token_1.TOKEN_2022_PROGRAM_ID]
|
|
340
342
|
: [spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID];
|
|
341
343
|
const ownerWrappedSolAta = (0, spl_token_1.getAssociatedTokenAddressSync)(nativeMint, owner, false, tokenProgram);
|
|
342
|
-
const ownerWrappedSolAccount = await connection
|
|
344
|
+
const ownerWrappedSolAccount = await getTokenAccountCached(connection, ownerWrappedSolAta);
|
|
343
345
|
if (!ownerWrappedSolAccount) {
|
|
344
346
|
setupIx.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, ownerWrappedSolAta, owner, nativeMint, tokenProgram));
|
|
345
347
|
if (includeCleanupIx) {
|
|
@@ -364,7 +366,7 @@ async function createUnwrapSolInstructionWithPayer(connection, payer, owner, use
|
|
|
364
366
|
? [spl_token_1.NATIVE_MINT_2022, spl_token_1.TOKEN_2022_PROGRAM_ID]
|
|
365
367
|
: [spl_token_1.NATIVE_MINT, spl_token_1.TOKEN_PROGRAM_ID];
|
|
366
368
|
const ownerWrappedSolAta = (0, spl_token_1.getAssociatedTokenAddressSync)(nativeMint, owner, false, tokenProgram);
|
|
367
|
-
const ownerWrappedSolAccount = await connection
|
|
369
|
+
const ownerWrappedSolAccount = await getTokenAccountCached(connection, ownerWrappedSolAta);
|
|
368
370
|
if (!ownerWrappedSolAccount) {
|
|
369
371
|
setupIx.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(payer, ownerWrappedSolAta, owner, nativeMint, tokenProgram));
|
|
370
372
|
}
|
|
@@ -401,7 +403,7 @@ async function handleMint(connection, mint, options) {
|
|
|
401
403
|
}
|
|
402
404
|
if (options.owner) {
|
|
403
405
|
const userAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, options.owner, true, tokenProgram);
|
|
404
|
-
const userTokenAccount = await connection
|
|
406
|
+
const userTokenAccount = await getTokenAccountCached(connection, userAta);
|
|
405
407
|
if (!userTokenAccount) {
|
|
406
408
|
instructions.setupIx.push((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(options.owner, userAta, options.owner, mint, tokenProgram));
|
|
407
409
|
}
|
|
@@ -501,7 +503,7 @@ async function handleOpenTokenAccounts({ program, owner, downPayment, fee, mintC
|
|
|
501
503
|
setupIx.push((0, spl_token_1.createSyncNativeInstruction)(ownerPaymentAta, paymentTokenProgram));
|
|
502
504
|
cleanupIx.push((0, spl_token_1.createCloseAccountInstruction)(ownerPaymentAta, owner, owner, [], paymentTokenProgram));
|
|
503
505
|
}
|
|
504
|
-
const ownerPaymentAtaInfo = await program.provider.connection
|
|
506
|
+
const ownerPaymentAtaInfo = await getTokenAccountCached(program.provider.connection, ownerPaymentAta);
|
|
505
507
|
if (!ownerPaymentAtaInfo) {
|
|
506
508
|
setupIx = [
|
|
507
509
|
(0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, ownerPaymentAta, owner, paymentMint, paymentTokenProgram),
|
|
@@ -529,7 +531,7 @@ async function handleCloseTokenAccounts(config, poolAccount) {
|
|
|
529
531
|
const payoutTokenProgram = poolAccount.isLongPool ? currencyTokenProgram : collateralTokenProgram;
|
|
530
532
|
const payoutIsSol = payoutMint.equals(spl_token_1.NATIVE_MINT);
|
|
531
533
|
const ownerPayoutAta = (0, spl_token_1.getAssociatedTokenAddressSync)(payoutMint, config.owner, false, payoutTokenProgram);
|
|
532
|
-
const ownerPayoutAtaInfo = await config.program.provider.connection
|
|
534
|
+
const ownerPayoutAtaInfo = await getTokenAccountCached(config.program.provider.connection, ownerPayoutAta);
|
|
533
535
|
const setupIx = [];
|
|
534
536
|
const cleanupIx = [];
|
|
535
537
|
if (!ownerPayoutAtaInfo) {
|