@varla/sdk 3.1.0 → 3.2.0
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/CHANGELOG.md +9 -0
- package/dist/leverage/deleverageExecute.d.ts +7 -0
- package/dist/leverage/deleverageExecute.d.ts.map +1 -1
- package/dist/leverage/deleverageExecute.js +16 -8
- package/dist/leverage/deleverageExecute.js.map +1 -1
- package/dist/leverage/execute.d.ts +7 -0
- package/dist/leverage/execute.d.ts.map +1 -1
- package/dist/leverage/execute.js +16 -8
- package/dist/leverage/execute.js.map +1 -1
- package/package.json +1 -1
- package/src/leverage/deleverageExecute.ts +27 -7
- package/src/leverage/execute.ts +27 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @varla-xyz/protocol
|
|
2
2
|
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2cddd41: Add optional asset parameters to leverage and deleverage loops to support asset-specific core borrow and repay calls.
|
|
8
|
+
|
|
9
|
+
- Allow runLeverageLoop to use an optional outputAsset for core borrow steps
|
|
10
|
+
- Allow runDeleverageLoop to use an optional inputAsset for core repay steps
|
|
11
|
+
|
|
3
12
|
## 3.1.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -21,6 +21,13 @@ export type RunDeleverageLoopParams = {
|
|
|
21
21
|
walletClient: Pick<WalletClient, "writeContract">;
|
|
22
22
|
coreAddress: Address;
|
|
23
23
|
account: Address;
|
|
24
|
+
/**
|
|
25
|
+
* Optional repay settlement asset for core repay steps.
|
|
26
|
+
*
|
|
27
|
+
* When provided, repay steps call `VarlaCore.repay(amount, inputAsset)`.
|
|
28
|
+
* When omitted, repay steps call the default `VarlaCore.repay(amount)`.
|
|
29
|
+
*/
|
|
30
|
+
inputAsset?: Address;
|
|
24
31
|
/** Off-chain sell callback. */
|
|
25
32
|
onSellStep: (step: Extract<DeleverageStep, {
|
|
26
33
|
kind: "sell";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleverageExecute.d.ts","sourceRoot":"","sources":["../../src/leverage/deleverageExecute.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"deleverageExecute.d.ts","sourceRoot":"","sources":["../../src/leverage/deleverageExecute.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7E,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,cAAc,CAAC;IAErB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,KAAK,IAAI,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,kBAAkB,GAAG,2BAA2B,CAAC,CAAC;IACnF,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IAClD,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,+BAA+B;IAC/B,UAAU,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;IACrF,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;IAEnC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE;QACtB,IAAI,EAAE,OAAO,CAAC,cAAc,EAAE;YAAE,IAAI,EAAE,UAAU,CAAA;SAAE,CAAC,CAAC;QACpD,IAAI,EAAE,IAAI,CAAC;KACZ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,uBAAuB,CAAC,CA0GlC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
-
import { prepareCoreRepay, prepareCoreWithdraw } from "../actions/core.js";
|
|
2
|
+
import { prepareCoreRepay, prepareCoreRepayWithAsset, prepareCoreWithdraw, } from "../actions/core.js";
|
|
3
3
|
import { sendTx } from "../actions/tx.js";
|
|
4
4
|
import { waitForReceiptWithRetry } from "./receipt.js";
|
|
5
5
|
import { SlippageExceededError } from "./types.js";
|
|
@@ -27,7 +27,7 @@ function sleep(ms) {
|
|
|
27
27
|
* - `startFromStep`: resume from a previously failed step index
|
|
28
28
|
*/
|
|
29
29
|
export async function runDeleverageLoop(params) {
|
|
30
|
-
const { plan, positionId, publicClient, walletClient, coreAddress, account, onSellStep, onProgress, confirmations = 1, maxSlippageBps, receiptRetry, onPostWithdraw, postWithdrawDelayMs = 0, startFromStep = 0, } = params;
|
|
30
|
+
const { plan, positionId, publicClient, walletClient, coreAddress, account, inputAsset, onSellStep, onProgress, confirmations = 1, maxSlippageBps, receiptRetry, onPostWithdraw, postWithdrawDelayMs = 0, startFromStep = 0, } = params;
|
|
31
31
|
const total = plan.steps.length;
|
|
32
32
|
// Track actual collateral proceeds from the most recent sell step.
|
|
33
33
|
let lastSellActualCollateral;
|
|
@@ -76,12 +76,20 @@ export async function runDeleverageLoop(params) {
|
|
|
76
76
|
if (step.kind === "repay") {
|
|
77
77
|
const repayAmount = lastSellActualCollateral ?? step.collateralAmount;
|
|
78
78
|
lastSellActualCollateral = undefined;
|
|
79
|
-
const sim =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
const sim = inputAsset
|
|
80
|
+
? await prepareCoreRepayWithAsset({
|
|
81
|
+
publicClient: publicClient,
|
|
82
|
+
coreAddress,
|
|
83
|
+
account,
|
|
84
|
+
amount: repayAmount,
|
|
85
|
+
inputAsset,
|
|
86
|
+
})
|
|
87
|
+
: await prepareCoreRepay({
|
|
88
|
+
publicClient: publicClient,
|
|
89
|
+
coreAddress,
|
|
90
|
+
account,
|
|
91
|
+
amount: repayAmount,
|
|
92
|
+
});
|
|
85
93
|
const hash = await sendTx({ walletClient: walletClient, request: sim.request });
|
|
86
94
|
await waitForReceiptWithRetry({ publicClient, hash, confirmations, retry: receiptRetry });
|
|
87
95
|
onProgress?.({ completed: i + 1, total, step, hash });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleverageExecute.js","sourceRoot":"","sources":["../../src/leverage/deleverageExecute.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAWpE,OAAO,
|
|
1
|
+
{"version":3,"file":"deleverageExecute.js","sourceRoot":"","sources":["../../src/leverage/deleverageExecute.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAWpE,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAoFnD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,8EAA8E;AAC9E,WAAW;AACX,8EAA8E;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAA+B;IAE/B,MAAM,EACJ,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,UAAU,EACV,aAAa,GAAG,CAAC,EACjB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,mBAAmB,GAAG,CAAC,EACvB,aAAa,GAAG,CAAC,GAClB,GAAG,MAAM,CAAC;IAEX,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAEhC,mEAAmE;IACnE,IAAI,wBAA4C,CAAC;IAEjD,KAAK,IAAI,CAAC,GAAG,aAAa,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC;QAC5B,IAAI,CAAC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D,SAAS;YACX,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,sBAAuB,IAAY,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -18,6 +18,13 @@ export type RunLeverageLoopParams = {
|
|
|
18
18
|
walletClient: Pick<WalletClient, "writeContract">;
|
|
19
19
|
coreAddress: Address;
|
|
20
20
|
account: Address;
|
|
21
|
+
/**
|
|
22
|
+
* Optional borrow output asset for core borrow steps.
|
|
23
|
+
*
|
|
24
|
+
* When provided, borrow steps call `VarlaCore.borrow(amount, outputAsset)`.
|
|
25
|
+
* When omitted, borrow steps call the default `VarlaCore.borrow(amount)`.
|
|
26
|
+
*/
|
|
27
|
+
outputAsset?: Address;
|
|
21
28
|
/**
|
|
22
29
|
* Consumer-provided callback for off-chain token acquisition.
|
|
23
30
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/leverage/execute.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/leverage/execute.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,kBA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AC9B,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAcF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CA+HhC"}
|
package/dist/leverage/execute.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Note: explicit .js extension is required for Node ESM resolution.
|
|
2
|
-
import { prepareCoreBorrow, prepareCoreDeposit } from "../actions/core.js";
|
|
2
|
+
import { prepareCoreBorrow, prepareCoreBorrowWithAsset, prepareCoreDeposit, } from "../actions/core.js";
|
|
3
3
|
import { sendTx } from "../actions/tx.js";
|
|
4
4
|
import { waitForReceiptWithRetry } from "./receipt.js";
|
|
5
5
|
import { SlippageExceededError } from "./types.js";
|
|
@@ -33,7 +33,7 @@ function sleep(ms) {
|
|
|
33
33
|
* - `startFromStep`: resume from a previously failed step index
|
|
34
34
|
*/
|
|
35
35
|
export async function runLeverageLoop(params) {
|
|
36
|
-
const { plan, positionId, publicClient, walletClient, coreAddress, account, onBuyStep, onProgress, confirmations = 1, maxSlippageBps, receiptRetry, onPostBorrow, postBorrowDelayMs = 0, startFromStep = 0, } = params;
|
|
36
|
+
const { plan, positionId, publicClient, walletClient, coreAddress, account, outputAsset, onBuyStep, onProgress, confirmations = 1, maxSlippageBps, receiptRetry, onPostBorrow, postBorrowDelayMs = 0, startFromStep = 0, } = params;
|
|
37
37
|
const results = [];
|
|
38
38
|
const totalSteps = plan.steps.length;
|
|
39
39
|
// Track actual tokens from the most recent buy (for slippage-aware deposits).
|
|
@@ -80,12 +80,20 @@ export async function runLeverageLoop(params) {
|
|
|
80
80
|
continue;
|
|
81
81
|
}
|
|
82
82
|
if (step.kind === "borrow") {
|
|
83
|
-
const sim =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
const sim = outputAsset
|
|
84
|
+
? await prepareCoreBorrowWithAsset({
|
|
85
|
+
publicClient: publicClient,
|
|
86
|
+
coreAddress,
|
|
87
|
+
account,
|
|
88
|
+
amount: step.collateralAmount,
|
|
89
|
+
outputAsset,
|
|
90
|
+
})
|
|
91
|
+
: await prepareCoreBorrow({
|
|
92
|
+
publicClient: publicClient,
|
|
93
|
+
coreAddress,
|
|
94
|
+
account,
|
|
95
|
+
amount: step.collateralAmount,
|
|
96
|
+
});
|
|
89
97
|
const hash = await sendTx({ walletClient: walletClient, request: sim.request });
|
|
90
98
|
await waitForReceiptWithRetry({ publicClient, hash, confirmations, retry: receiptRetry });
|
|
91
99
|
const result = { step, hash };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/leverage/execute.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAYpE,OAAO,
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/leverage/execute.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAYpE,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAQvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAkGnD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,8EAA8E;AAC9E,WAAW;AACX,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;GAmBG;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gBACf,KAAK;aACN,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
import type { Address, Hash, PublicClient, WalletClient } from "viem";
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
prepareCoreRepay,
|
|
14
|
+
prepareCoreRepayWithAsset,
|
|
15
|
+
prepareCoreWithdraw,
|
|
16
|
+
} from "../actions/core.js";
|
|
13
17
|
import { sendTx } from "../actions/tx.js";
|
|
14
18
|
import type { ReceiptRetryOptions } from "./receipt.js";
|
|
15
19
|
import { waitForReceiptWithRetry } from "./receipt.js";
|
|
@@ -32,6 +36,13 @@ export type RunDeleverageLoopParams = {
|
|
|
32
36
|
walletClient: Pick<WalletClient, "writeContract">;
|
|
33
37
|
coreAddress: Address;
|
|
34
38
|
account: Address;
|
|
39
|
+
/**
|
|
40
|
+
* Optional repay settlement asset for core repay steps.
|
|
41
|
+
*
|
|
42
|
+
* When provided, repay steps call `VarlaCore.repay(amount, inputAsset)`.
|
|
43
|
+
* When omitted, repay steps call the default `VarlaCore.repay(amount)`.
|
|
44
|
+
*/
|
|
45
|
+
inputAsset?: Address;
|
|
35
46
|
/** Off-chain sell callback. */
|
|
36
47
|
onSellStep: (step: Extract<DeleverageStep, { kind: "sell" }>) => Promise<SellResult>;
|
|
37
48
|
onProgress?: OnDeleverageProgress;
|
|
@@ -127,6 +138,7 @@ export async function runDeleverageLoop(
|
|
|
127
138
|
walletClient,
|
|
128
139
|
coreAddress,
|
|
129
140
|
account,
|
|
141
|
+
inputAsset,
|
|
130
142
|
onSellStep,
|
|
131
143
|
onProgress,
|
|
132
144
|
confirmations = 1,
|
|
@@ -196,12 +208,20 @@ export async function runDeleverageLoop(
|
|
|
196
208
|
const repayAmount = lastSellActualCollateral ?? step.collateralAmount;
|
|
197
209
|
lastSellActualCollateral = undefined;
|
|
198
210
|
|
|
199
|
-
const sim =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
const sim = inputAsset
|
|
212
|
+
? await prepareCoreRepayWithAsset({
|
|
213
|
+
publicClient: publicClient as any,
|
|
214
|
+
coreAddress,
|
|
215
|
+
account,
|
|
216
|
+
amount: repayAmount,
|
|
217
|
+
inputAsset,
|
|
218
|
+
})
|
|
219
|
+
: await prepareCoreRepay({
|
|
220
|
+
publicClient: publicClient as any,
|
|
221
|
+
coreAddress,
|
|
222
|
+
account,
|
|
223
|
+
amount: repayAmount,
|
|
224
|
+
});
|
|
205
225
|
const hash = await sendTx({ walletClient: walletClient as any, request: sim.request });
|
|
206
226
|
await waitForReceiptWithRetry({ publicClient, hash, confirmations, retry: receiptRetry });
|
|
207
227
|
|
package/src/leverage/execute.ts
CHANGED
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
import type { Address, Hash, PublicClient, WalletClient } from "viem";
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
prepareCoreBorrow,
|
|
15
|
+
prepareCoreBorrowWithAsset,
|
|
16
|
+
prepareCoreDeposit,
|
|
17
|
+
} from "../actions/core.js";
|
|
14
18
|
import { sendTx } from "../actions/tx.js";
|
|
15
19
|
import type { ReceiptRetryOptions } from "./receipt.js";
|
|
16
20
|
import { waitForReceiptWithRetry } from "./receipt.js";
|
|
@@ -37,6 +41,13 @@ export type RunLeverageLoopParams = {
|
|
|
37
41
|
walletClient: Pick<WalletClient, "writeContract">;
|
|
38
42
|
coreAddress: Address;
|
|
39
43
|
account: Address;
|
|
44
|
+
/**
|
|
45
|
+
* Optional borrow output asset for core borrow steps.
|
|
46
|
+
*
|
|
47
|
+
* When provided, borrow steps call `VarlaCore.borrow(amount, outputAsset)`.
|
|
48
|
+
* When omitted, borrow steps call the default `VarlaCore.borrow(amount)`.
|
|
49
|
+
*/
|
|
50
|
+
outputAsset?: Address;
|
|
40
51
|
/**
|
|
41
52
|
* Consumer-provided callback for off-chain token acquisition.
|
|
42
53
|
*
|
|
@@ -154,6 +165,7 @@ export async function runLeverageLoop(
|
|
|
154
165
|
walletClient,
|
|
155
166
|
coreAddress,
|
|
156
167
|
account,
|
|
168
|
+
outputAsset,
|
|
157
169
|
onBuyStep,
|
|
158
170
|
onProgress,
|
|
159
171
|
confirmations = 1,
|
|
@@ -223,12 +235,20 @@ export async function runLeverageLoop(
|
|
|
223
235
|
}
|
|
224
236
|
|
|
225
237
|
if (step.kind === "borrow") {
|
|
226
|
-
const sim =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
238
|
+
const sim = outputAsset
|
|
239
|
+
? await prepareCoreBorrowWithAsset({
|
|
240
|
+
publicClient: publicClient as any,
|
|
241
|
+
coreAddress,
|
|
242
|
+
account,
|
|
243
|
+
amount: step.collateralAmount,
|
|
244
|
+
outputAsset,
|
|
245
|
+
})
|
|
246
|
+
: await prepareCoreBorrow({
|
|
247
|
+
publicClient: publicClient as any,
|
|
248
|
+
coreAddress,
|
|
249
|
+
account,
|
|
250
|
+
amount: step.collateralAmount,
|
|
251
|
+
});
|
|
232
252
|
|
|
233
253
|
const hash = await sendTx({ walletClient: walletClient as any, request: sim.request });
|
|
234
254
|
await waitForReceiptWithRetry({ publicClient, hash, confirmations, retry: receiptRetry });
|