@carrot-protocol/boost-http-client 0.1.4 → 0.1.5-bundle1-dev-19cfaa8
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.js +6 -6
- package/dist/types.d.ts +4 -1
- package/package.json +1 -1
- package/src/index.ts +18 -6
- package/src/types.ts +4 -1
package/dist/index.js
CHANGED
|
@@ -70,9 +70,9 @@ class Client {
|
|
|
70
70
|
return this.provider.wallet.publicKey;
|
|
71
71
|
}
|
|
72
72
|
// sign and send tx to api for sending to network
|
|
73
|
-
async send(
|
|
73
|
+
async send(unsignedBase64Tx, ...signedBase64Txns) {
|
|
74
74
|
// deserialize into tx obj
|
|
75
|
-
const txBytes = Buffer.from(
|
|
75
|
+
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
76
76
|
const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
77
77
|
// sign tx
|
|
78
78
|
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
@@ -81,7 +81,7 @@ class Client {
|
|
|
81
81
|
const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
|
|
82
82
|
// create request obj
|
|
83
83
|
const sendRequest = {
|
|
84
|
-
|
|
84
|
+
txns: [encodedAndSignedTx, ...signedBase64Txns],
|
|
85
85
|
};
|
|
86
86
|
// send to api
|
|
87
87
|
await handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
@@ -132,7 +132,7 @@ class Client {
|
|
|
132
132
|
async depositLeverage(params) {
|
|
133
133
|
const body = await handleApiCall(() => this.http.post("leverage/deposit", JSON.stringify(params)));
|
|
134
134
|
const depositLeverageResponse = JSON.parse(body);
|
|
135
|
-
const txSig = await this.send(depositLeverageResponse.unsignedBase64Tx);
|
|
135
|
+
const txSig = await this.send(depositLeverageResponse.unsignedBase64Tx, depositLeverageResponse.signedSetBorrowRateBase64Tx);
|
|
136
136
|
return txSig;
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
@@ -143,7 +143,7 @@ class Client {
|
|
|
143
143
|
async modifyLeverage(params) {
|
|
144
144
|
const body = await handleApiCall(() => this.http.post("leverage/modify", JSON.stringify(params)));
|
|
145
145
|
const modifyLeverageResponse = JSON.parse(body);
|
|
146
|
-
const txSig = await this.send(modifyLeverageResponse.unsignedBase64Tx);
|
|
146
|
+
const txSig = await this.send(modifyLeverageResponse.unsignedBase64Tx, modifyLeverageResponse.signedSetBorrowRateBase64Tx);
|
|
147
147
|
return txSig;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
@@ -154,7 +154,7 @@ class Client {
|
|
|
154
154
|
async withdrawLeverage(params) {
|
|
155
155
|
const body = await handleApiCall(() => this.http.post("leverage/withdraw", JSON.stringify(params)));
|
|
156
156
|
const withdrawLeverageResponse = JSON.parse(body);
|
|
157
|
-
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx);
|
|
157
|
+
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.signedSetBorrowRateBase64Tx);
|
|
158
158
|
return txSig;
|
|
159
159
|
}
|
|
160
160
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { web3 } from "@coral-xyz/anchor";
|
|
2
2
|
import Decimal from "decimal.js";
|
|
3
3
|
export interface SendRequest {
|
|
4
|
-
|
|
4
|
+
txns: string[];
|
|
5
5
|
}
|
|
6
6
|
export interface CreateObligationRequest {
|
|
7
7
|
owner: web3.PublicKey;
|
|
@@ -24,6 +24,7 @@ export interface DepositLeverageRequest {
|
|
|
24
24
|
*/
|
|
25
25
|
export interface DepositLeverageResponse {
|
|
26
26
|
unsignedBase64Tx: string;
|
|
27
|
+
signedSetBorrowRateBase64Tx: string;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Request to modify the leverage of an existing position
|
|
@@ -38,6 +39,7 @@ export interface ModifyLeverageRequest {
|
|
|
38
39
|
*/
|
|
39
40
|
export interface ModifyLeverageResponse {
|
|
40
41
|
unsignedBase64Tx: string;
|
|
42
|
+
signedSetBorrowRateBase64Tx: string;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* Request to withdraw from a leveraged position
|
|
@@ -54,6 +56,7 @@ export interface WithdrawLeverageRequest {
|
|
|
54
56
|
*/
|
|
55
57
|
export interface WithdrawLeverageResponse {
|
|
56
58
|
unsignedBase64Tx: string;
|
|
59
|
+
signedSetBorrowRateBase64Tx: string;
|
|
57
60
|
}
|
|
58
61
|
export interface GetObligationResponse {
|
|
59
62
|
netValue: number;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -48,9 +48,12 @@ export class Client {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// sign and send tx to api for sending to network
|
|
51
|
-
private async send(
|
|
51
|
+
private async send(
|
|
52
|
+
unsignedBase64Tx: string,
|
|
53
|
+
...signedBase64Txns: string[]
|
|
54
|
+
): Promise<string> {
|
|
52
55
|
// deserialize into tx obj
|
|
53
|
-
const txBytes = Buffer.from(
|
|
56
|
+
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
54
57
|
const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
55
58
|
|
|
56
59
|
// sign tx
|
|
@@ -64,7 +67,7 @@ export class Client {
|
|
|
64
67
|
|
|
65
68
|
// create request obj
|
|
66
69
|
const sendRequest: SendRequest = {
|
|
67
|
-
|
|
70
|
+
txns: [encodedAndSignedTx, ...signedBase64Txns],
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
// send to api
|
|
@@ -140,7 +143,10 @@ export class Client {
|
|
|
140
143
|
|
|
141
144
|
const depositLeverageResponse: DepositLeverageResponse = JSON.parse(body);
|
|
142
145
|
|
|
143
|
-
const txSig = await this.send(
|
|
146
|
+
const txSig = await this.send(
|
|
147
|
+
depositLeverageResponse.unsignedBase64Tx,
|
|
148
|
+
depositLeverageResponse.signedSetBorrowRateBase64Tx,
|
|
149
|
+
);
|
|
144
150
|
|
|
145
151
|
return txSig;
|
|
146
152
|
}
|
|
@@ -157,7 +163,10 @@ export class Client {
|
|
|
157
163
|
|
|
158
164
|
const modifyLeverageResponse: ModifyLeverageResponse = JSON.parse(body);
|
|
159
165
|
|
|
160
|
-
const txSig = await this.send(
|
|
166
|
+
const txSig = await this.send(
|
|
167
|
+
modifyLeverageResponse.unsignedBase64Tx,
|
|
168
|
+
modifyLeverageResponse.signedSetBorrowRateBase64Tx,
|
|
169
|
+
);
|
|
161
170
|
|
|
162
171
|
return txSig;
|
|
163
172
|
}
|
|
@@ -174,7 +183,10 @@ export class Client {
|
|
|
174
183
|
|
|
175
184
|
const withdrawLeverageResponse: WithdrawLeverageResponse = JSON.parse(body);
|
|
176
185
|
|
|
177
|
-
const txSig = await this.send(
|
|
186
|
+
const txSig = await this.send(
|
|
187
|
+
withdrawLeverageResponse.unsignedBase64Tx,
|
|
188
|
+
withdrawLeverageResponse.signedSetBorrowRateBase64Tx,
|
|
189
|
+
);
|
|
178
190
|
|
|
179
191
|
return txSig;
|
|
180
192
|
}
|
package/src/types.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Decimal from "decimal.js";
|
|
|
3
3
|
|
|
4
4
|
// Represents a request to send a transaction
|
|
5
5
|
export interface SendRequest {
|
|
6
|
-
|
|
6
|
+
txns: string[];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface CreateObligationRequest {
|
|
@@ -30,6 +30,7 @@ export interface DepositLeverageRequest {
|
|
|
30
30
|
*/
|
|
31
31
|
export interface DepositLeverageResponse {
|
|
32
32
|
unsignedBase64Tx: string;
|
|
33
|
+
signedSetBorrowRateBase64Tx: string;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -46,6 +47,7 @@ export interface ModifyLeverageRequest {
|
|
|
46
47
|
*/
|
|
47
48
|
export interface ModifyLeverageResponse {
|
|
48
49
|
unsignedBase64Tx: string;
|
|
50
|
+
signedSetBorrowRateBase64Tx: string;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/**
|
|
@@ -64,6 +66,7 @@ export interface WithdrawLeverageRequest {
|
|
|
64
66
|
*/
|
|
65
67
|
export interface WithdrawLeverageResponse {
|
|
66
68
|
unsignedBase64Tx: string;
|
|
69
|
+
signedSetBorrowRateBase64Tx: string;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
export interface GetObligationResponse {
|