@carrot-protocol/http-client 0.2.78-drift-apy-fix-dev-2256d2a → 0.2.78-drift-apy-fix-dev-9ad3029
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/index.d.ts +5 -2
- package/dist/index.js +33 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as anchor from "@coral-xyz/anchor";
|
|
2
2
|
import { Vault, VaultPerformance } from "@carrot-protocol/common";
|
|
3
|
-
import { CheckWalletResponse, ClaimReferralCodeResponse, GetCarrotBoostJitDepositIxnsRequest, GetCarrotBoostJitDepositIxnsResponse, GetCarrotBoostJitWithdrawIxnsRequest, GetCarrotBoostJitWithdrawIxnsResponse, GetLatestPoolApyResponse, GetReferralCodesResponse, HistoricalVaultApyResponse, HistoricalVaultNavResponse, UserPerformanceResponse, UserResponse, VaultHistoricalInterval, VaultOhlcResponse } from "./types";
|
|
3
|
+
import { CheckWalletResponse, ClaimReferralCodeResponse, GetCarrotBoostJitDepositIxnsRequest, GetCarrotBoostJitDepositIxnsResponse, GetCarrotBoostJitWithdrawIxnsRequest, GetCarrotBoostJitWithdrawIxnsResponse, GetLatestPoolApyResponse, GetReferralCodesResponse, HistoricalVaultApyResponse, HistoricalVaultNavResponse, IssueResponse, RedeemResponse, UserPerformanceResponse, UserResponse, VaultHistoricalInterval, VaultOhlcResponse } from "./types";
|
|
4
4
|
export * as Common from "@carrot-protocol/common";
|
|
5
5
|
export * from "./types";
|
|
6
6
|
export declare class Client {
|
|
@@ -17,13 +17,16 @@ export declare class Client {
|
|
|
17
17
|
getHistoricalVaultNav(vault: anchor.web3.PublicKey, interval: VaultHistoricalInterval): Promise<HistoricalVaultNavResponse>;
|
|
18
18
|
getVaultOhlc(vault: anchor.web3.PublicKey): Promise<VaultOhlcResponse>;
|
|
19
19
|
issue(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
|
|
20
|
+
prepareIssue(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN, user: anchor.web3.PublicKey): Promise<IssueResponse>;
|
|
20
21
|
redeem(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
|
|
22
|
+
prepareRedeem(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN, user: anchor.web3.PublicKey): Promise<RedeemResponse>;
|
|
21
23
|
getLatestPoolApy(poolNames: string[]): Promise<GetLatestPoolApyResponse>;
|
|
22
24
|
checkWallet(wallet: anchor.web3.PublicKey): Promise<CheckWalletResponse>;
|
|
23
25
|
claimReferralCode(wallet: anchor.web3.PublicKey, code: string): Promise<ClaimReferralCodeResponse>;
|
|
24
26
|
getReferralCodes(wallet: anchor.web3.PublicKey): Promise<GetReferralCodesResponse>;
|
|
25
27
|
getCarrotBoostJitDepositIxns(request: GetCarrotBoostJitDepositIxnsRequest): Promise<GetCarrotBoostJitDepositIxnsResponse>;
|
|
26
28
|
getCarrotBoostJitWithdrawIxns(request: GetCarrotBoostJitWithdrawIxnsRequest): Promise<GetCarrotBoostJitWithdrawIxnsResponse>;
|
|
27
|
-
|
|
29
|
+
sendSignedTx(signedBase64Tx: string): Promise<string>;
|
|
30
|
+
private signAndSend;
|
|
28
31
|
}
|
|
29
32
|
export declare function prepareUnsignedTx(connection: anchor.web3.Connection, payer: anchor.web3.PublicKey, ixns: anchor.web3.TransactionInstruction[], lutAddr?: anchor.web3.PublicKey, additionalSigner?: anchor.AnchorProvider): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -227,9 +227,14 @@ class Client {
|
|
|
227
227
|
async issue(vault, assetMint, amount) {
|
|
228
228
|
// error if provider is undefined
|
|
229
229
|
requireProvider(this.provider);
|
|
230
|
+
const issueResponse = await this.prepareIssue(vault, assetMint, amount, this.provider.publicKey);
|
|
231
|
+
const txSig = await this.signAndSend(issueResponse.tx);
|
|
232
|
+
return txSig;
|
|
233
|
+
}
|
|
234
|
+
async prepareIssue(vault, assetMint, amount, user) {
|
|
230
235
|
const url = new URL(`${this.baseUrl}/issue`);
|
|
231
236
|
const body = {
|
|
232
|
-
user
|
|
237
|
+
user,
|
|
233
238
|
vault,
|
|
234
239
|
amount,
|
|
235
240
|
assetMint,
|
|
@@ -242,16 +247,21 @@ class Client {
|
|
|
242
247
|
checkResponse(response);
|
|
243
248
|
const responseBody = await response.json();
|
|
244
249
|
const issueResponse = JSON.parse(JSON.stringify(responseBody));
|
|
245
|
-
|
|
246
|
-
return txSig;
|
|
250
|
+
return issueResponse;
|
|
247
251
|
}
|
|
248
252
|
// Redeems assets from a specified vault
|
|
249
253
|
async redeem(vault, assetMint, amount) {
|
|
250
254
|
// error if provider is undefined
|
|
251
255
|
requireProvider(this.provider);
|
|
256
|
+
const redeemResponse = await this.prepareRedeem(vault, assetMint, amount, this.provider.publicKey);
|
|
257
|
+
const txSig = await this.signAndSend(redeemResponse.tx);
|
|
258
|
+
return txSig;
|
|
259
|
+
}
|
|
260
|
+
// Redeems assets from a specified vault
|
|
261
|
+
async prepareRedeem(vault, assetMint, amount, user) {
|
|
252
262
|
const url = new URL(`${this.baseUrl}/redeem`);
|
|
253
263
|
const body = {
|
|
254
|
-
user
|
|
264
|
+
user,
|
|
255
265
|
vault,
|
|
256
266
|
amount,
|
|
257
267
|
assetMint,
|
|
@@ -264,8 +274,7 @@ class Client {
|
|
|
264
274
|
checkResponse(response);
|
|
265
275
|
const responseBody = await response.json();
|
|
266
276
|
const redeemResponse = JSON.parse(JSON.stringify(responseBody));
|
|
267
|
-
|
|
268
|
-
return txSig;
|
|
277
|
+
return redeemResponse;
|
|
269
278
|
}
|
|
270
279
|
async getLatestPoolApy(poolNames) {
|
|
271
280
|
const url = new URL(`${this.baseUrl}/latestPoolApy?poolNames=${poolNames.join(",")}`);
|
|
@@ -374,16 +383,14 @@ class Client {
|
|
|
374
383
|
return getCarrotBoostJitWithdrawIxnsResponse;
|
|
375
384
|
}
|
|
376
385
|
// Sends a signed transaction to the network
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const txBytes = Buffer.from(
|
|
386
|
+
// expects a versioned tx
|
|
387
|
+
async sendSignedTx(signedBase64Tx) {
|
|
388
|
+
// extract txSig for caller
|
|
389
|
+
const txBytes = Buffer.from(signedBase64Tx, "base64");
|
|
381
390
|
const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
382
|
-
const
|
|
383
|
-
const txSig = signedTx.signatures[0];
|
|
384
|
-
const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
|
|
391
|
+
const txSig = tx.signatures[0];
|
|
385
392
|
const sendRequest = {
|
|
386
|
-
tx:
|
|
393
|
+
tx: signedBase64Tx,
|
|
387
394
|
};
|
|
388
395
|
const url = new URL(`${this.baseUrl}/send`);
|
|
389
396
|
const response = await (0, cross_fetch_1.default)(url, {
|
|
@@ -397,6 +404,18 @@ class Client {
|
|
|
397
404
|
}
|
|
398
405
|
return (0, bs58_1.encode)(txSig);
|
|
399
406
|
}
|
|
407
|
+
// Sends a signed transaction to the network
|
|
408
|
+
async signAndSend(base64Tx) {
|
|
409
|
+
// error if provider is undefined
|
|
410
|
+
requireProvider(this.provider);
|
|
411
|
+
const txBytes = Buffer.from(base64Tx, "base64");
|
|
412
|
+
const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
413
|
+
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
414
|
+
const txSig = signedTx.signatures[0];
|
|
415
|
+
const signedBase64Tx = Buffer.from(signedTx.serialize()).toString("base64");
|
|
416
|
+
await this.sendSignedTx(signedBase64Tx);
|
|
417
|
+
return (0, bs58_1.encode)(txSig);
|
|
418
|
+
}
|
|
400
419
|
}
|
|
401
420
|
exports.Client = Client;
|
|
402
421
|
// Prepares an unsigned transaction for submission
|
package/package.json
CHANGED