@haven-fi/solauto-sdk 1.0.627 → 1.0.628
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/README.md +39 -81
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/instructionUtils.d.ts +15 -0
- package/dist/utils/instructionUtils.d.ts.map +1 -0
- package/dist/utils/instructionUtils.js +121 -0
- package/package.json +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/instructionUtils.ts +181 -0
- package/tests/transactions/shared.ts +22 -66
package/README.md
CHANGED
@@ -2,36 +2,14 @@
|
|
2
2
|
|
3
3
|
Solauto is a program on the Solana blockchain that lets you manage leveraged longs & shorts on auto-pilot to maximize your gains and eliminate the risk of liquidation. The typescript SDK is made for interacting with the Solauto program. This SDK provides tools for managing, & reading Solauto state data, as well as executing transactions.
|
4
4
|
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
```bash
|
8
|
-
npm install @haven-fi/solauto-sdk
|
9
|
-
# or
|
10
|
-
yarn add @haven-fi/solauto-sdk
|
11
|
-
# or
|
12
|
-
pnpm add @haven-fi/solauto-sdk
|
13
|
-
```
|
14
|
-
|
15
5
|
## Basic Usage
|
16
6
|
|
17
7
|
```typescript
|
18
8
|
import { PublicKey } from "@solana/web3.js";
|
19
|
-
import
|
20
|
-
getClient,
|
21
|
-
LendingPlatform,
|
22
|
-
USDC,
|
23
|
-
SolautoSettingsParametersInpArgs,
|
24
|
-
maxBoostToBps,
|
25
|
-
maxRepayToBps,
|
26
|
-
fetchTokenPrices,
|
27
|
-
TransactionItem,
|
28
|
-
solautoAction,
|
29
|
-
RebalanceTxBuilder,
|
30
|
-
TransactionsManager,
|
31
|
-
} from "@haven-fi/solauto-sdk";
|
9
|
+
import * as solauto from "@haven-fi/solauto-sdk";
|
32
10
|
|
33
11
|
// Initialize the client
|
34
|
-
const client = getClient(LendingPlatform.MARGINFI, {
|
12
|
+
const client = solauto.getClient(solauto.LendingPlatform.MARGINFI, {
|
35
13
|
signer: yourSigner,
|
36
14
|
rpcUrl: "[YOUR_RPC_URL]",
|
37
15
|
});
|
@@ -50,66 +28,46 @@ await client.initialize({
|
|
50
28
|
// Open a position with custom settings
|
51
29
|
const [maxLtvBps, liqThresholdBps] =
|
52
30
|
await client.pos.maxLtvAndLiqThresholdBps();
|
53
|
-
const settings: SolautoSettingsParametersInpArgs = {
|
54
|
-
boostToBps: maxBoostToBps(maxLtvBps, liqThresholdBps),
|
31
|
+
const settings: solauto.SolautoSettingsParametersInpArgs = {
|
32
|
+
boostToBps: solauto.maxBoostToBps(maxLtvBps, liqThresholdBps),
|
55
33
|
boostGap: 50,
|
56
|
-
repayToBps: maxRepayToBps(maxLtvBps, liqThresholdBps),
|
34
|
+
repayToBps: solauto.maxRepayToBps(maxLtvBps, liqThresholdBps),
|
57
35
|
repayGap: 50,
|
58
36
|
};
|
59
37
|
|
60
|
-
const
|
61
|
-
|
62
|
-
const
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
transactionItems
|
94
|
-
new TransactionItem(
|
95
|
-
async () => ({
|
96
|
-
tx: client.protocolInteractionIx(
|
97
|
-
solautoAction("Withdraw", [{ __kind: "All" }])
|
98
|
-
),
|
99
|
-
}),
|
100
|
-
"withdraw"
|
101
|
-
)
|
102
|
-
);
|
103
|
-
|
104
|
-
transactionItems.push(
|
105
|
-
new TransactionItem(
|
106
|
-
async () => ({
|
107
|
-
tx: client.closePositionIx(),
|
108
|
-
}),
|
109
|
-
"close position"
|
110
|
-
)
|
38
|
+
const supplyUsdToDeposit = 100;
|
39
|
+
const debtUsdToBorrow = 60;
|
40
|
+
const [supplyPrice, debtPrice] = await solauto.fetchTokenPrices([
|
41
|
+
supplyMint,
|
42
|
+
debtMint,
|
43
|
+
]);
|
44
|
+
|
45
|
+
const transactionItems = [
|
46
|
+
// Open position
|
47
|
+
solauto.openSolautoPosition(client, settings),
|
48
|
+
// Deposit supply (SOL) transaction
|
49
|
+
solauto.deposit(
|
50
|
+
client,
|
51
|
+
toBaseUnit(
|
52
|
+
supplyUsdToDeposit / supplyPrice,
|
53
|
+
client.pos.supplyMintInfo().decimals
|
54
|
+
)
|
55
|
+
),
|
56
|
+
// Borrow debt (USDC) transaction
|
57
|
+
solauto.borrow(
|
58
|
+
client,
|
59
|
+
toBaseUnit(debtUsdToBorrow / debtPrice, client.pos.debtMintInfo().decimals)
|
60
|
+
),
|
61
|
+
// Rebalance to 0 LTV (repays all debt using collateral)
|
62
|
+
solauto.rebalance(client, 0),
|
63
|
+
// Withdraw remaining supply in position
|
64
|
+
solauto.withdraw(client, "All"),
|
65
|
+
// Close position
|
66
|
+
solauto.closeSolautoPosition(client),
|
67
|
+
];
|
68
|
+
|
69
|
+
// Send all transactions atomically
|
70
|
+
const statuses = await new solauto.TransactionsManager(client).clientSend(
|
71
|
+
transactionItems
|
111
72
|
);
|
112
|
-
|
113
|
-
const txManager = new TransactionsManager(client);
|
114
|
-
const statuses = await txManager.clientSend(transactionItems);
|
115
73
|
```
|
package/dist/utils/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./accountUtils"), exports);
|
18
18
|
__exportStar(require("./generalUtils"), exports);
|
19
|
+
__exportStar(require("./instructionUtils"), exports);
|
19
20
|
__exportStar(require("./jitoUtils"), exports);
|
20
21
|
__exportStar(require("./jupiterUtils"), exports);
|
21
22
|
__exportStar(require("./marginfiUtils"), exports);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { OptionOrNullable } from "@metaplex-foundation/umi";
|
2
|
+
import { DCASettingsInpArgs, SolautoSettingsParametersInpArgs } from "../generated";
|
3
|
+
import { SolautoClient, TransactionItem } from "../services";
|
4
|
+
import { PublicKey } from "@solana/web3.js";
|
5
|
+
export declare function openSolautoPosition(client: SolautoClient, settingParams: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionItem;
|
6
|
+
export declare function closeSolautoPosition(client: SolautoClient): TransactionItem;
|
7
|
+
export declare function updateSolautoPosition(client: SolautoClient, settings: OptionOrNullable<SolautoSettingsParametersInpArgs>, dca: OptionOrNullable<DCASettingsInpArgs>): TransactionItem;
|
8
|
+
export declare function cancelSolautoDca(client: SolautoClient): TransactionItem;
|
9
|
+
export declare function deposit(client: SolautoClient, baseUnitAmount: bigint): TransactionItem;
|
10
|
+
export declare function borrow(client: SolautoClient, baseUnitAmount: bigint): TransactionItem;
|
11
|
+
export declare function withdraw(client: SolautoClient, amount: "All" | bigint): TransactionItem;
|
12
|
+
export declare function repay(client: SolautoClient, amount: "All" | bigint): TransactionItem;
|
13
|
+
export declare function rebalance(client: SolautoClient, targetLiqUtilizationRateBps?: number): TransactionItem;
|
14
|
+
export declare function swapThenDeposit(client: SolautoClient, depositMint: PublicKey, depositAmountBaseUnit: bigint): TransactionItem[];
|
15
|
+
//# sourceMappingURL=instructionUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instructionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/instructionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,aAAa,EAEb,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,gCAAgC,EAC/C,GAAG,CAAC,EAAE,kBAAkB,mBAQzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,mBAOzD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,gBAAgB,CAAC,gCAAgC,CAAC,EAC5D,GAAG,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,mBAY1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,mBAOrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUpE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUnE;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAcrE;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAclE;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,mBAUrC;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,SAAS,EACtB,qBAAqB,EAAE,MAAM,qBA2C9B"}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.openSolautoPosition = openSolautoPosition;
|
4
|
+
exports.closeSolautoPosition = closeSolautoPosition;
|
5
|
+
exports.updateSolautoPosition = updateSolautoPosition;
|
6
|
+
exports.cancelSolautoDca = cancelSolautoDca;
|
7
|
+
exports.deposit = deposit;
|
8
|
+
exports.borrow = borrow;
|
9
|
+
exports.withdraw = withdraw;
|
10
|
+
exports.repay = repay;
|
11
|
+
exports.rebalance = rebalance;
|
12
|
+
exports.swapThenDeposit = swapThenDeposit;
|
13
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
14
|
+
const services_1 = require("../services");
|
15
|
+
const generalUtils_1 = require("./generalUtils");
|
16
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
17
|
+
function openSolautoPosition(client, settingParams, dca) {
|
18
|
+
return new services_1.TransactionItem(async () => ({
|
19
|
+
tx: client.openPositionIx(settingParams, dca),
|
20
|
+
}), "open position");
|
21
|
+
}
|
22
|
+
function closeSolautoPosition(client) {
|
23
|
+
return new services_1.TransactionItem(async () => ({
|
24
|
+
tx: client.closePositionIx(),
|
25
|
+
}), "close position");
|
26
|
+
}
|
27
|
+
function updateSolautoPosition(client, settings, dca) {
|
28
|
+
return new services_1.TransactionItem(async () => ({
|
29
|
+
tx: client.updatePositionIx({
|
30
|
+
positionId: client.positionId,
|
31
|
+
settings,
|
32
|
+
dca,
|
33
|
+
}),
|
34
|
+
}), "update position");
|
35
|
+
}
|
36
|
+
function cancelSolautoDca(client) {
|
37
|
+
return new services_1.TransactionItem(async () => ({
|
38
|
+
tx: client.cancelDCAIx(),
|
39
|
+
}), "cancel DCA");
|
40
|
+
}
|
41
|
+
function deposit(client, baseUnitAmount) {
|
42
|
+
return new services_1.TransactionItem(async () => ({
|
43
|
+
tx: client.protocolInteractionIx({
|
44
|
+
__kind: "Deposit",
|
45
|
+
fields: [baseUnitAmount],
|
46
|
+
}),
|
47
|
+
}), "deposit");
|
48
|
+
}
|
49
|
+
function borrow(client, baseUnitAmount) {
|
50
|
+
return new services_1.TransactionItem(async () => ({
|
51
|
+
tx: client.protocolInteractionIx({
|
52
|
+
__kind: "Borrow",
|
53
|
+
fields: [baseUnitAmount],
|
54
|
+
}),
|
55
|
+
}), "borrow");
|
56
|
+
}
|
57
|
+
function withdraw(client, amount) {
|
58
|
+
return new services_1.TransactionItem(async () => ({
|
59
|
+
tx: client.protocolInteractionIx({
|
60
|
+
__kind: "Withdraw",
|
61
|
+
fields: [
|
62
|
+
amount === "All"
|
63
|
+
? { __kind: "All" }
|
64
|
+
: { __kind: "Some", fields: [amount] },
|
65
|
+
],
|
66
|
+
}),
|
67
|
+
}), "withdraw");
|
68
|
+
}
|
69
|
+
function repay(client, amount) {
|
70
|
+
return new services_1.TransactionItem(async () => ({
|
71
|
+
tx: client.protocolInteractionIx({
|
72
|
+
__kind: "Repay",
|
73
|
+
fields: [
|
74
|
+
amount === "All"
|
75
|
+
? { __kind: "All" }
|
76
|
+
: { __kind: "Some", fields: [amount] },
|
77
|
+
],
|
78
|
+
}),
|
79
|
+
}), "repay");
|
80
|
+
}
|
81
|
+
function rebalance(client, targetLiqUtilizationRateBps) {
|
82
|
+
return new services_1.TransactionItem(async (attemptNum) => await new services_1.RebalanceTxBuilder(client, targetLiqUtilizationRateBps).buildRebalanceTx(attemptNum), "rebalance");
|
83
|
+
}
|
84
|
+
function swapThenDeposit(client, depositMint, depositAmountBaseUnit) {
|
85
|
+
return [
|
86
|
+
new services_1.TransactionItem(async () => {
|
87
|
+
const memeSwap = (0, generalUtils_1.tokenInfo)(client.pos.supplyMint()).isMeme;
|
88
|
+
const swapInput = {
|
89
|
+
inputMint: depositMint,
|
90
|
+
outputMint: client.pos.supplyMint(),
|
91
|
+
amount: depositAmountBaseUnit,
|
92
|
+
exactIn: true,
|
93
|
+
slippageBps: memeSwap ? 300 : 50,
|
94
|
+
};
|
95
|
+
const jupSwapManager = new services_1.JupSwapManager(client.signer);
|
96
|
+
const { setupIx, swapIx, cleanupIx, lookupTableAddresses } = await jupSwapManager.getJupSwapTxData({
|
97
|
+
...swapInput,
|
98
|
+
destinationWallet: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey),
|
99
|
+
wrapAndUnwrapSol: true,
|
100
|
+
});
|
101
|
+
client.contextUpdates.new({
|
102
|
+
type: "jupSwap",
|
103
|
+
value: jupSwapManager.jupQuote,
|
104
|
+
});
|
105
|
+
return {
|
106
|
+
tx: (0, umi_1.transactionBuilder)().add([setupIx, swapIx, cleanupIx]),
|
107
|
+
lookupTableAddresses,
|
108
|
+
orderPrio: -1,
|
109
|
+
};
|
110
|
+
}, "swap"),
|
111
|
+
new services_1.TransactionItem(async () => {
|
112
|
+
const quoteOutAmount = client.contextUpdates.jupSwap?.outAmount;
|
113
|
+
return {
|
114
|
+
tx: (0, umi_1.transactionBuilder)().add(client.protocolInteractionIx({
|
115
|
+
__kind: "Deposit",
|
116
|
+
fields: [BigInt(Math.round(parseInt(quoteOutAmount) * 0.995))],
|
117
|
+
})),
|
118
|
+
};
|
119
|
+
}, "deposit"),
|
120
|
+
];
|
121
|
+
}
|
package/package.json
CHANGED
package/src/utils/index.ts
CHANGED
@@ -0,0 +1,181 @@
|
|
1
|
+
import { OptionOrNullable, transactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import {
|
3
|
+
DCASettingsInpArgs,
|
4
|
+
SolautoSettingsParametersInpArgs,
|
5
|
+
} from "../generated";
|
6
|
+
import {
|
7
|
+
JupSwapManager,
|
8
|
+
RebalanceTxBuilder,
|
9
|
+
SolautoClient,
|
10
|
+
SwapInput,
|
11
|
+
TransactionItem,
|
12
|
+
} from "../services";
|
13
|
+
import { PublicKey } from "@solana/web3.js";
|
14
|
+
import { tokenInfo } from "./generalUtils";
|
15
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
16
|
+
|
17
|
+
export function openSolautoPosition(
|
18
|
+
client: SolautoClient,
|
19
|
+
settingParams: SolautoSettingsParametersInpArgs,
|
20
|
+
dca?: DCASettingsInpArgs
|
21
|
+
) {
|
22
|
+
return new TransactionItem(
|
23
|
+
async () => ({
|
24
|
+
tx: client!.openPositionIx(settingParams, dca),
|
25
|
+
}),
|
26
|
+
"open position"
|
27
|
+
);
|
28
|
+
}
|
29
|
+
|
30
|
+
export function closeSolautoPosition(client: SolautoClient) {
|
31
|
+
return new TransactionItem(
|
32
|
+
async () => ({
|
33
|
+
tx: client.closePositionIx(),
|
34
|
+
}),
|
35
|
+
"close position"
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
export function updateSolautoPosition(
|
40
|
+
client: SolautoClient,
|
41
|
+
settings: OptionOrNullable<SolautoSettingsParametersInpArgs>,
|
42
|
+
dca: OptionOrNullable<DCASettingsInpArgs>
|
43
|
+
) {
|
44
|
+
return new TransactionItem(
|
45
|
+
async () => ({
|
46
|
+
tx: client.updatePositionIx({
|
47
|
+
positionId: client.positionId,
|
48
|
+
settings,
|
49
|
+
dca,
|
50
|
+
}),
|
51
|
+
}),
|
52
|
+
"update position"
|
53
|
+
);
|
54
|
+
}
|
55
|
+
|
56
|
+
export function cancelSolautoDca(client: SolautoClient) {
|
57
|
+
return new TransactionItem(
|
58
|
+
async () => ({
|
59
|
+
tx: client.cancelDCAIx(),
|
60
|
+
}),
|
61
|
+
"cancel DCA"
|
62
|
+
);
|
63
|
+
}
|
64
|
+
|
65
|
+
export function deposit(client: SolautoClient, baseUnitAmount: bigint) {
|
66
|
+
return new TransactionItem(
|
67
|
+
async () => ({
|
68
|
+
tx: client.protocolInteractionIx({
|
69
|
+
__kind: "Deposit",
|
70
|
+
fields: [baseUnitAmount],
|
71
|
+
}),
|
72
|
+
}),
|
73
|
+
"deposit"
|
74
|
+
);
|
75
|
+
}
|
76
|
+
|
77
|
+
export function borrow(client: SolautoClient, baseUnitAmount: bigint) {
|
78
|
+
return new TransactionItem(
|
79
|
+
async () => ({
|
80
|
+
tx: client.protocolInteractionIx({
|
81
|
+
__kind: "Borrow",
|
82
|
+
fields: [baseUnitAmount],
|
83
|
+
}),
|
84
|
+
}),
|
85
|
+
"borrow"
|
86
|
+
);
|
87
|
+
}
|
88
|
+
|
89
|
+
export function withdraw(client: SolautoClient, amount: "All" | bigint) {
|
90
|
+
return new TransactionItem(
|
91
|
+
async () => ({
|
92
|
+
tx: client.protocolInteractionIx({
|
93
|
+
__kind: "Withdraw",
|
94
|
+
fields: [
|
95
|
+
amount === "All"
|
96
|
+
? { __kind: "All" }
|
97
|
+
: { __kind: "Some", fields: [amount] },
|
98
|
+
],
|
99
|
+
}),
|
100
|
+
}),
|
101
|
+
"withdraw"
|
102
|
+
);
|
103
|
+
}
|
104
|
+
|
105
|
+
export function repay(client: SolautoClient, amount: "All" | bigint) {
|
106
|
+
return new TransactionItem(
|
107
|
+
async () => ({
|
108
|
+
tx: client.protocolInteractionIx({
|
109
|
+
__kind: "Repay",
|
110
|
+
fields: [
|
111
|
+
amount === "All"
|
112
|
+
? { __kind: "All" }
|
113
|
+
: { __kind: "Some", fields: [amount] },
|
114
|
+
],
|
115
|
+
}),
|
116
|
+
}),
|
117
|
+
"repay"
|
118
|
+
);
|
119
|
+
}
|
120
|
+
|
121
|
+
export function rebalance(
|
122
|
+
client: SolautoClient,
|
123
|
+
targetLiqUtilizationRateBps?: number
|
124
|
+
) {
|
125
|
+
return new TransactionItem(
|
126
|
+
async (attemptNum) =>
|
127
|
+
await new RebalanceTxBuilder(
|
128
|
+
client,
|
129
|
+
targetLiqUtilizationRateBps
|
130
|
+
).buildRebalanceTx(attemptNum),
|
131
|
+
"rebalance"
|
132
|
+
);
|
133
|
+
}
|
134
|
+
|
135
|
+
export function swapThenDeposit(
|
136
|
+
client: SolautoClient,
|
137
|
+
depositMint: PublicKey,
|
138
|
+
depositAmountBaseUnit: bigint
|
139
|
+
) {
|
140
|
+
return [
|
141
|
+
new TransactionItem(async () => {
|
142
|
+
const memeSwap = tokenInfo(client.pos.supplyMint()).isMeme;
|
143
|
+
const swapInput: SwapInput = {
|
144
|
+
inputMint: depositMint,
|
145
|
+
outputMint: client.pos.supplyMint(),
|
146
|
+
amount: depositAmountBaseUnit,
|
147
|
+
exactIn: true,
|
148
|
+
slippageBps: memeSwap ? 300 : 50,
|
149
|
+
};
|
150
|
+
const jupSwapManager = new JupSwapManager(client.signer);
|
151
|
+
const { setupIx, swapIx, cleanupIx, lookupTableAddresses } =
|
152
|
+
await jupSwapManager.getJupSwapTxData({
|
153
|
+
...swapInput,
|
154
|
+
destinationWallet: toWeb3JsPublicKey(client.signer.publicKey),
|
155
|
+
wrapAndUnwrapSol: true,
|
156
|
+
});
|
157
|
+
|
158
|
+
client.contextUpdates.new({
|
159
|
+
type: "jupSwap",
|
160
|
+
value: jupSwapManager.jupQuote!,
|
161
|
+
});
|
162
|
+
|
163
|
+
return {
|
164
|
+
tx: transactionBuilder().add([setupIx, swapIx, cleanupIx]),
|
165
|
+
lookupTableAddresses,
|
166
|
+
orderPrio: -1,
|
167
|
+
};
|
168
|
+
}, "swap"),
|
169
|
+
new TransactionItem(async () => {
|
170
|
+
const quoteOutAmount = client.contextUpdates.jupSwap?.outAmount;
|
171
|
+
return {
|
172
|
+
tx: transactionBuilder().add(
|
173
|
+
client.protocolInteractionIx({
|
174
|
+
__kind: "Deposit",
|
175
|
+
fields: [BigInt(Math.round(parseInt(quoteOutAmount!) * 0.995))],
|
176
|
+
})
|
177
|
+
),
|
178
|
+
};
|
179
|
+
}, "deposit"),
|
180
|
+
];
|
181
|
+
}
|
@@ -18,6 +18,12 @@ import {
|
|
18
18
|
TransactionItem,
|
19
19
|
TransactionsManager,
|
20
20
|
USDC,
|
21
|
+
deposit,
|
22
|
+
openSolautoPosition,
|
23
|
+
borrow,
|
24
|
+
rebalance,
|
25
|
+
withdraw,
|
26
|
+
closeSolautoPosition,
|
21
27
|
} from "../../src";
|
22
28
|
|
23
29
|
export async function e2eTransactionTest(
|
@@ -51,77 +57,27 @@ export async function e2eTransactionTest(
|
|
51
57
|
repayGap: 50,
|
52
58
|
};
|
53
59
|
|
54
|
-
const
|
55
|
-
|
56
|
-
transactionItems.push(
|
57
|
-
new TransactionItem(async () => {
|
58
|
-
return {
|
59
|
-
tx: client.openPositionIx(settings),
|
60
|
-
};
|
61
|
-
}, "open position")
|
62
|
-
);
|
63
|
-
|
60
|
+
const supplyUsd = 100;
|
61
|
+
const debtUsd = withFlashLoan ? 60 : 10;
|
64
62
|
const [supplyPrice, debtPrice] = await fetchTokenPrices([
|
65
63
|
supplyMint,
|
66
64
|
debtMint,
|
67
65
|
]);
|
68
66
|
|
69
|
-
const
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
);
|
84
|
-
|
85
|
-
const debtUsd = withFlashLoan ? 60 : 10;
|
86
|
-
transactionItems.push(
|
87
|
-
new TransactionItem(async () => {
|
88
|
-
return {
|
89
|
-
tx: client.protocolInteractionIx(
|
90
|
-
solautoAction("Borrow", [
|
91
|
-
toBaseUnit(debtUsd / debtPrice, client.pos.debtMintInfo().decimals),
|
92
|
-
])
|
93
|
-
),
|
94
|
-
};
|
95
|
-
}, "borrow")
|
96
|
-
);
|
97
|
-
|
98
|
-
transactionItems.push(
|
99
|
-
new TransactionItem(
|
100
|
-
async (attemptNum) =>
|
101
|
-
await new RebalanceTxBuilder(client, 0).buildRebalanceTx(attemptNum),
|
102
|
-
"rebalance"
|
103
|
-
)
|
104
|
-
);
|
105
|
-
|
106
|
-
transactionItems.push(
|
107
|
-
new TransactionItem(
|
108
|
-
async () => ({
|
109
|
-
tx: client.protocolInteractionIx(
|
110
|
-
solautoAction("Withdraw", [{ __kind: "All" }])
|
111
|
-
),
|
112
|
-
}),
|
113
|
-
"withdraw"
|
114
|
-
)
|
115
|
-
);
|
116
|
-
|
117
|
-
transactionItems.push(
|
118
|
-
new TransactionItem(
|
119
|
-
async () => ({
|
120
|
-
tx: client.closePositionIx(),
|
121
|
-
}),
|
122
|
-
"close position"
|
123
|
-
)
|
124
|
-
);
|
67
|
+
const transactionItems = [
|
68
|
+
openSolautoPosition(client, settings),
|
69
|
+
deposit(
|
70
|
+
client,
|
71
|
+
toBaseUnit(supplyUsd / supplyPrice, client.pos.supplyMintInfo().decimals)
|
72
|
+
),
|
73
|
+
borrow(
|
74
|
+
client,
|
75
|
+
toBaseUnit(debtUsd / debtPrice, client.pos.debtMintInfo().decimals)
|
76
|
+
),
|
77
|
+
rebalance(client, 0),
|
78
|
+
withdraw(client, "All"),
|
79
|
+
closeSolautoPosition(client),
|
80
|
+
];
|
125
81
|
|
126
82
|
const txManager = new TransactionsManager(client, undefined, "only-simulate");
|
127
83
|
const statuses = await txManager.clientSend(transactionItems);
|