@carrot-protocol/http-client 0.2.19-pyth-oracle-v2-dev-a33436f → 0.2.19
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 +2 -2
- package/dist/index.js +15 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as anchor from "@coral-xyz/anchor";
|
|
|
2
2
|
import { Vault, VaultPerformance } from "@carrot-protocol/common";
|
|
3
3
|
export declare class Client {
|
|
4
4
|
readonly baseUrl: string;
|
|
5
|
-
readonly provider: anchor.AnchorProvider;
|
|
5
|
+
readonly provider: anchor.AnchorProvider | undefined;
|
|
6
6
|
private headers;
|
|
7
|
-
constructor(baseUrl: string, provider
|
|
7
|
+
constructor(baseUrl: string, provider?: anchor.AnchorProvider);
|
|
8
8
|
index(): Promise<void>;
|
|
9
9
|
getVault(vault: anchor.web3.PublicKey, useCache: boolean): Promise<Vault>;
|
|
10
10
|
getVaultPerformance(vault: anchor.web3.PublicKey, useCache: boolean): Promise<VaultPerformance>;
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ class Client {
|
|
|
56
56
|
body.address = vault;
|
|
57
57
|
body.authority = new anchor.web3.PublicKey(body.authority);
|
|
58
58
|
body.shares = new anchor.web3.PublicKey(body.shares);
|
|
59
|
-
body.sharesSupply = new anchor.BN(body.sharesSupply.toString(10)
|
|
59
|
+
body.sharesSupply = new anchor.BN(body.sharesSupply.toString(10));
|
|
60
60
|
body.assets = body.assets.map((asset) => ({
|
|
61
61
|
...asset,
|
|
62
62
|
assetId: Number(asset.assetId),
|
|
@@ -105,6 +105,8 @@ class Client {
|
|
|
105
105
|
return body;
|
|
106
106
|
}
|
|
107
107
|
async getUser(vault) {
|
|
108
|
+
// error if provider is undefined
|
|
109
|
+
requireProvider(this.provider);
|
|
108
110
|
const url = new URL(`${this.baseUrl}/user?vault=${vault.toString()}&user=${this.provider.publicKey.toString()}`);
|
|
109
111
|
const response = await (0, cross_fetch_1.default)(url, {
|
|
110
112
|
method: "GET",
|
|
@@ -136,6 +138,8 @@ class Client {
|
|
|
136
138
|
return historicalVaultApyResponse;
|
|
137
139
|
}
|
|
138
140
|
async issue(vault, assetMint, amount) {
|
|
141
|
+
// error if provider is undefined
|
|
142
|
+
requireProvider(this.provider);
|
|
139
143
|
const url = new URL(`${this.baseUrl}/issue`);
|
|
140
144
|
const body = {
|
|
141
145
|
user: this.provider.publicKey,
|
|
@@ -155,6 +159,8 @@ class Client {
|
|
|
155
159
|
return txSig;
|
|
156
160
|
}
|
|
157
161
|
async redeem(vault, assetMint, amount) {
|
|
162
|
+
// error if provider is undefined
|
|
163
|
+
requireProvider(this.provider);
|
|
158
164
|
const url = new URL(`${this.baseUrl}/redeem`);
|
|
159
165
|
const body = {
|
|
160
166
|
user: this.provider.publicKey,
|
|
@@ -174,6 +180,8 @@ class Client {
|
|
|
174
180
|
return txSig;
|
|
175
181
|
}
|
|
176
182
|
async send(base64Tx) {
|
|
183
|
+
// error if provider is undefined
|
|
184
|
+
requireProvider(this.provider);
|
|
177
185
|
const txBytes = Buffer.from(base64Tx, "base64");
|
|
178
186
|
const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
179
187
|
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
@@ -227,3 +235,9 @@ function checkResponse(response) {
|
|
|
227
235
|
throw new Error(`unexpected http status of ${response.status}`);
|
|
228
236
|
}
|
|
229
237
|
}
|
|
238
|
+
function requireProvider(provider) {
|
|
239
|
+
if (provider) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
throw new Error(`provider is undefined`);
|
|
243
|
+
}
|