@carrot-protocol/http-client 0.2.19-dummy-provider-dev-3a94b9e → 0.2.19-dummy-provider-dev-966c49c
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 +1 -1
- package/dist/index.js +15 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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
7
|
constructor(baseUrl: string, provider?: anchor.AnchorProvider);
|
|
8
8
|
index(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -31,22 +31,12 @@ exports.isValidVaultHistoricalApyInterval = isValidVaultHistoricalApyInterval;
|
|
|
31
31
|
exports.prepareUnsignedTx = prepareUnsignedTx;
|
|
32
32
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
33
33
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
34
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
35
34
|
const bs58_1 = require("bs58");
|
|
36
35
|
class Client {
|
|
37
36
|
constructor(baseUrl, provider) {
|
|
38
37
|
this.headers = { "Content-Type": "application/json" };
|
|
39
38
|
this.baseUrl = baseUrl;
|
|
40
|
-
|
|
41
|
-
this.provider = provider;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const kp = anchor.web3.Keypair.generate();
|
|
45
|
-
const wallet = new anchor_1.Wallet(kp);
|
|
46
|
-
const connection = new anchor.web3.Connection("http://localhost:8899", "processed");
|
|
47
|
-
// if no provider is passed in, create a dummy provider, aka read only mode
|
|
48
|
-
this.provider = new anchor.AnchorProvider(connection, wallet, {});
|
|
49
|
-
}
|
|
39
|
+
this.provider = provider;
|
|
50
40
|
}
|
|
51
41
|
async index() {
|
|
52
42
|
const response = await (0, cross_fetch_1.default)(this.baseUrl);
|
|
@@ -115,6 +105,8 @@ class Client {
|
|
|
115
105
|
return body;
|
|
116
106
|
}
|
|
117
107
|
async getUser(vault) {
|
|
108
|
+
// error if provider is undefined
|
|
109
|
+
requireProvider(this.provider);
|
|
118
110
|
const url = new URL(`${this.baseUrl}/user?vault=${vault.toString()}&user=${this.provider.publicKey.toString()}`);
|
|
119
111
|
const response = await (0, cross_fetch_1.default)(url, {
|
|
120
112
|
method: "GET",
|
|
@@ -146,6 +138,8 @@ class Client {
|
|
|
146
138
|
return historicalVaultApyResponse;
|
|
147
139
|
}
|
|
148
140
|
async issue(vault, assetMint, amount) {
|
|
141
|
+
// error if provider is undefined
|
|
142
|
+
requireProvider(this.provider);
|
|
149
143
|
const url = new URL(`${this.baseUrl}/issue`);
|
|
150
144
|
const body = {
|
|
151
145
|
user: this.provider.publicKey,
|
|
@@ -165,6 +159,8 @@ class Client {
|
|
|
165
159
|
return txSig;
|
|
166
160
|
}
|
|
167
161
|
async redeem(vault, assetMint, amount) {
|
|
162
|
+
// error if provider is undefined
|
|
163
|
+
requireProvider(this.provider);
|
|
168
164
|
const url = new URL(`${this.baseUrl}/redeem`);
|
|
169
165
|
const body = {
|
|
170
166
|
user: this.provider.publicKey,
|
|
@@ -184,6 +180,8 @@ class Client {
|
|
|
184
180
|
return txSig;
|
|
185
181
|
}
|
|
186
182
|
async send(base64Tx) {
|
|
183
|
+
// error if provider is undefined
|
|
184
|
+
requireProvider(this.provider);
|
|
187
185
|
const txBytes = Buffer.from(base64Tx, "base64");
|
|
188
186
|
const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
189
187
|
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
@@ -237,3 +235,9 @@ function checkResponse(response) {
|
|
|
237
235
|
throw new Error(`unexpected http status of ${response.status}`);
|
|
238
236
|
}
|
|
239
237
|
}
|
|
238
|
+
function requireProvider(provider) {
|
|
239
|
+
if (provider) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
throw new Error(`provider is undefined`);
|
|
243
|
+
}
|