@haven-fi/solauto-sdk 1.0.661 → 1.0.663
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/services/flashLoans/flProviderAggregator.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.d.ts +2 -0
- package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.js +14 -31
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts +0 -1
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +1 -6
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +1 -4
- package/dist/services/solauto/solautoMarginfiClient.d.ts +2 -1
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +20 -7
- package/dist/solautoPosition/solautoPositionEx.d.ts +9 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +56 -29
- package/dist/utils/marginfiUtils.d.ts +3 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +14 -0
- package/dist/utils/numberUtils.d.ts +2 -0
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/numberUtils.js +7 -0
- package/dist/utils/solanaUtils.d.ts +2 -1
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +4 -0
- package/local/logPositions.ts +0 -2
- package/local/txSandbox.ts +13 -7
- package/package.json +1 -1
- package/src/services/flashLoans/flProviderAggregator.ts +3 -1
- package/src/services/flashLoans/marginfiFlProvider.ts +28 -38
- package/src/services/rebalance/rebalanceTxBuilder.ts +6 -19
- package/src/services/solauto/solautoClient.ts +1 -4
- package/src/services/solauto/solautoMarginfiClient.ts +50 -9
- package/src/solautoPosition/solautoPositionEx.ts +104 -46
- package/src/utils/marginfiUtils.ts +19 -1
- package/src/utils/numberUtils.ts +13 -1
- package/src/utils/solanaUtils.ts +10 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"flProviderAggregator.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/flProviderAggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,OAAO,CAAC,kBAAkB,CAAsB;gBAG9C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,UAAU,CAAC,EAAE,UAAU;IAanB,UAAU;IAMV,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAIvD,YAAY,IAAI,MAAM,EAAE;IAKxB,gBAAgB,IAAI,SAAS,EAAE;IAS/B,OAAO,CAAC,UAAU;IAKlB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAI7C,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM;IAI9D,WAAW,CACT,SAAS,EAAE,gBAAgB,EAC3B,gBAAgB,EAAE,SAAS,GAC1B,kBAAkB;IAOrB,UAAU,CAAC,SAAS,EAAE,gBAAgB,GAAG,kBAAkB;
|
1
|
+
{"version":3,"file":"flProviderAggregator.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/flProviderAggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,OAAO,CAAC,kBAAkB,CAAsB;gBAG9C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,UAAU,CAAC,EAAE,UAAU;IAanB,UAAU;IAMV,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAIvD,YAAY,IAAI,MAAM,EAAE;IAKxB,gBAAgB,IAAI,SAAS,EAAE;IAS/B,OAAO,CAAC,UAAU;IAKlB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAI7C,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM;IAI9D,WAAW,CACT,SAAS,EAAE,gBAAgB,EAC3B,gBAAgB,EAAE,SAAS,GAC1B,kBAAkB;IAOrB,UAAU,CAAC,SAAS,EAAE,gBAAgB,GAAG,kBAAkB;CAK5D"}
|
@@ -9,6 +9,8 @@ export declare class MarginfiFlProvider extends FlProviderBase {
|
|
9
9
|
private debtBankLiquiditySource;
|
10
10
|
private supplyImfiAccount;
|
11
11
|
private debtImfiAccount;
|
12
|
+
private supplyRemainingAccounts;
|
13
|
+
private debtRemainingAccounts;
|
12
14
|
initialize(): Promise<void>;
|
13
15
|
private setAvailableBanks;
|
14
16
|
private setIntermediaryAccount;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiFlProvider.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/marginfiFlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAML,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAclC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
1
|
+
{"version":3,"file":"marginfiFlProvider.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/marginfiFlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAML,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAclC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAiBlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,yBAAyB,CAAQ;IACzC,OAAO,CAAC,uBAAuB,CAAQ;IAEvC,OAAO,CAAC,iBAAiB,CAAe;IACxC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,uBAAuB,CAAiB;IAChD,OAAO,CAAC,qBAAqB,CAAiB;IAExC,UAAU;YAiBF,iBAAiB;YA6CjB,sBAAsB;IAsD9B,sBAAsB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAyC3D,gBAAgB,IAAI,SAAS,EAAE;IAY/B,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,WAAW;IAMnB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAI7C,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM;IAc9D,WAAW,CACT,SAAS,EAAE,gBAAgB,EAC3B,gBAAgB,EAAE,SAAS,GAC1B,kBAAkB;IAoCrB,UAAU,CAAC,SAAS,EAAE,gBAAgB,GAAG,kBAAkB;IAgD3D,YAAY,CACV,eAAe,EAAE,SAAS,EAC1B,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,SAAS;CAW3B"}
|
@@ -15,11 +15,11 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
15
15
|
this.existingMarginfiAccounts = await (0, utils_1.getEmptyMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
|
16
16
|
if (this.liquidityBank(generated_1.TokenType.Supply).group.toString() !==
|
17
17
|
this.liquidityBank(generated_1.TokenType.Debt).group.toString()) {
|
18
|
-
this.setIntermediaryAccount([generated_1.TokenType.Supply]);
|
19
|
-
this.setIntermediaryAccount([generated_1.TokenType.Debt]);
|
18
|
+
await this.setIntermediaryAccount([generated_1.TokenType.Supply]);
|
19
|
+
await this.setIntermediaryAccount([generated_1.TokenType.Debt]);
|
20
20
|
}
|
21
21
|
else {
|
22
|
-
this.setIntermediaryAccount([generated_1.TokenType.Supply, generated_1.TokenType.Debt]);
|
22
|
+
await this.setIntermediaryAccount([generated_1.TokenType.Supply, generated_1.TokenType.Debt]);
|
23
23
|
}
|
24
24
|
}
|
25
25
|
async setAvailableBanks() {
|
@@ -52,7 +52,7 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
52
52
|
this.supplyBankLiquiditySource = supplyBanks[0][1];
|
53
53
|
this.debtBankLiquiditySource = debtBanks[0][1];
|
54
54
|
}
|
55
|
-
setIntermediaryAccount(sources) {
|
55
|
+
async setIntermediaryAccount(sources) {
|
56
56
|
const compatibleMarginfiAccounts = this.existingMarginfiAccounts.filter((x) => x.group.toString() == this.liquidityBank(sources[0]).group);
|
57
57
|
const signer = compatibleMarginfiAccounts.length > 0
|
58
58
|
? undefined
|
@@ -66,6 +66,9 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
66
66
|
if (signer) {
|
67
67
|
this.flSigners.push(signer);
|
68
68
|
}
|
69
|
+
const remainingAccounts = accountData
|
70
|
+
? (await Promise.all(accountData.lendingAccount.balances.map((balance) => (0, utils_1.getRemainingAccountsForMarginfiHealthCheck)(this.umi, balance)))).flat()
|
71
|
+
: [];
|
69
72
|
for (const s of sources) {
|
70
73
|
const data = {
|
71
74
|
signer,
|
@@ -75,9 +78,11 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
75
78
|
const supply = s === generated_1.TokenType.Supply;
|
76
79
|
if (supply) {
|
77
80
|
this.supplyImfiAccount = data;
|
81
|
+
this.supplyRemainingAccounts = remainingAccounts;
|
78
82
|
}
|
79
83
|
else {
|
80
84
|
this.debtImfiAccount = data;
|
85
|
+
this.debtRemainingAccounts = remainingAccounts;
|
81
86
|
}
|
82
87
|
(0, utils_1.consoleLog)(`${supply ? "Supply" : "Debt"} iMfi account:`, accountPk.toString());
|
83
88
|
}
|
@@ -172,36 +177,14 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
172
177
|
const associatedBankAccs = (0, utils_1.findMarginfiAccounts)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.publicKey));
|
173
178
|
const marginfiGroup = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.liquidityBank(flashLoan.liquiditySource).group);
|
174
179
|
const iMfiAccount = this.iMfiAccount(flashLoan.liquiditySource);
|
175
|
-
const remainingAccounts =
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
if (x.active) {
|
180
|
-
if (x.bankPk.toString() === bank.publicKey.toString()) {
|
181
|
-
flBankHadPrevBalance = true;
|
182
|
-
}
|
183
|
-
const priceOracle = (0, umi_1.publicKey)(await (0, utils_1.getMarginfiPriceOracle)(this.umi, {
|
184
|
-
pk: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.bankPk),
|
185
|
-
}));
|
186
|
-
remainingAccounts.push(...[
|
187
|
-
{
|
188
|
-
pubkey: x.bankPk,
|
189
|
-
isSigner: false,
|
190
|
-
isWritable: false,
|
191
|
-
},
|
192
|
-
{
|
193
|
-
pubkey: priceOracle,
|
194
|
-
isSigner: false,
|
195
|
-
isWritable: false,
|
196
|
-
},
|
197
|
-
]);
|
198
|
-
}
|
199
|
-
});
|
200
|
-
}
|
180
|
+
const remainingAccounts = flashLoan.liquiditySource === generated_1.TokenType.Supply
|
181
|
+
? this.supplyRemainingAccounts
|
182
|
+
: this.debtRemainingAccounts;
|
183
|
+
let iMfiAccountHadPrevFlBalance = remainingAccounts.find((x) => x.pubkey.toString() === bank.publicKey.toString());
|
201
184
|
return (0, umi_1.transactionBuilder)()
|
202
185
|
.add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
203
186
|
amount: flashLoan.baseUnitAmount,
|
204
|
-
repayAll: !
|
187
|
+
repayAll: !iMfiAccountHadPrevFlBalance,
|
205
188
|
bank: bank.publicKey,
|
206
189
|
bankLiquidityVault: (0, umi_1.publicKey)(associatedBankAccs.liquidityVault),
|
207
190
|
marginfiAccount: (0, umi_1.publicKey)(iMfiAccount.accountPk),
|
@@ -15,7 +15,6 @@ export declare class RebalanceTxBuilder {
|
|
15
15
|
private flashLoanRequirements;
|
16
16
|
private getFlashLoanDetails;
|
17
17
|
private setRebalanceType;
|
18
|
-
private realtimeUsdToEmaUsd;
|
19
18
|
private getInitialRebalanceValues;
|
20
19
|
private setRebalanceDetails;
|
21
20
|
private refreshBeforeRebalance;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AA2BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IARtC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA;IAG9C,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;YAyCd,qBAAqB;IAwCnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAwBnB,sBAAsB;YAyBtB,mBAAmB;IAmEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -114,17 +114,12 @@ class RebalanceTxBuilder {
|
|
114
114
|
this.rebalanceType = generated_1.SolautoRebalanceType.Regular;
|
115
115
|
}
|
116
116
|
}
|
117
|
-
realtimeUsdToEmaUsd(realtimeAmountUsd, mint) {
|
118
|
-
return ((realtimeAmountUsd / (0, utils_1.safeGetPrice)(mint, generated_1.PriceType.Realtime)) *
|
119
|
-
(0, utils_1.safeGetPrice)(mint, generated_1.PriceType.Ema));
|
120
|
-
}
|
121
117
|
getInitialRebalanceValues() {
|
122
118
|
let rebalanceValues = this.getRebalanceValues();
|
123
119
|
if (!rebalanceValues) {
|
124
120
|
return undefined;
|
125
121
|
}
|
126
|
-
|
127
|
-
if (postRebalanceEmaUtilRateBps > this.client.pos.maxBoostToBps) {
|
122
|
+
if (!this.client.pos.rebalanceHelper.validRealtimePricesBoost(rebalanceValues.debtAdjustmentUsd)) {
|
128
123
|
this.priceType = generated_1.PriceType.Ema;
|
129
124
|
rebalanceValues = this.getRebalanceValues();
|
130
125
|
if (!rebalanceValues) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,gCAAgC,EAEhC,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAML,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,iBAAkB,SAAQ,wBAAwB;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,8BAAsB,aAAc,SAAQ,oBAAoB;IACvD,eAAe,EAAG,eAAe,CAAC;IAClC,KAAK,EAAG,UAAU,CAAC;IAEnB,SAAS,EAAG,SAAS,CAAC;IAEtB,GAAG,E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gB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IAsDlE,QAAQ,CAAC,eAAe,IAAI,kBAAkB;IAE9C,WAAW,IAAI,kBAAkB;IAgCjC,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB;IAE5D,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAqFlE,QAAQ,CAAC,WAAW,CAClB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CACtB"}
|
@@ -19,9 +19,6 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
19
19
|
async initialize(args) {
|
20
20
|
await super.initialize(args);
|
21
21
|
const positionId = args.positionId ?? 0;
|
22
|
-
if (positionId === 0 && !args.lpUserAccount) {
|
23
|
-
throw new Error("Self managed position is missing arguments");
|
24
|
-
}
|
25
22
|
this.pos = await (0, solautoPosition_1.getOrCreatePositionEx)(this.umi, this.authority, positionId, this.programId, {
|
26
23
|
supplyMint: args.supplyMint,
|
27
24
|
debtMint: args.debtMint,
|
@@ -30,7 +27,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
30
27
|
lendingPlatform: this.lendingPlatform,
|
31
28
|
lpEnv: this.lpEnv,
|
32
29
|
}, this.contextUpdates);
|
33
|
-
if (this.pos.selfManaged
|
30
|
+
if (this.pos.selfManaged) {
|
34
31
|
await this.pos.refreshPositionState();
|
35
32
|
}
|
36
33
|
this.positionSupplyTa = (0, utils_1.getTokenAccount)(this.pos.publicKey, this.pos.supplyMint);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import { Signer, TransactionBuilder, AccountMeta } from "@metaplex-foundation/umi";
|
3
3
|
import { MarginfiAssetAccounts, RebalanceDetails } from "../../types";
|
4
4
|
import { MarginfiProgramAccounts } from "../../constants";
|
5
5
|
import { DCASettingsInpArgs, LendingPlatform, PriceType, RebalanceStep, SolautoActionArgs, SolautoSettingsParametersInpArgs } from "../../generated";
|
@@ -9,6 +9,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
9
9
|
mfiAccounts: MarginfiProgramAccounts;
|
10
10
|
marginfiAccount: PublicKey | Signer;
|
11
11
|
marginfiAccountPk: PublicKey;
|
12
|
+
healthCheckRemainingAccounts?: AccountMeta[];
|
12
13
|
marginfiGroup: PublicKey;
|
13
14
|
marginfiSupplyAccounts: MarginfiAssetAccounts;
|
14
15
|
marginfiDebtAccounts: MarginfiAssetAccounts;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,kBAAkB,
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,kBAAkB,EAIlB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAuB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,eAAe,EAEf,SAAS,EAET,aAAa,EACb,iBAAiB,EAEjB,gCAAgC,EAOjC,MAAM,iBAAiB,CAAC;AAoBzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMnE,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,kBAA4B;IAE3C,WAAW,EAAG,uBAAuB,CAAC;IAEtC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,4BAA4B,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7C,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAE7B,UAAU,CAAC,IAAI,EAAE,iBAAiB;IA6ExC,mBAAmB,IAAI,MAAM,EAAE;IAO/B,gBAAgB,IAAI,SAAS,EAAE;IAI/B,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,kBAAkB;IAStE,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA0C9B,eAAe,IAAI,kBAAkB;IAYrC,SAAS,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB;IAenD,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUlE,OAAO,CAAC,6BAA6B;IAiFrC,OAAO,CAAC,oCAAoC;IA0D5C,WAAW,CACT,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CA4EtB"}
|
@@ -9,6 +9,9 @@ const generated_1 = require("../../generated");
|
|
9
9
|
const utils_1 = require("../../utils");
|
10
10
|
const marginfi_sdk_1 = require("../../marginfi-sdk");
|
11
11
|
const solautoClient_1 = require("./solautoClient");
|
12
|
+
function isSigner(account) {
|
13
|
+
return "publicKey" in account;
|
14
|
+
}
|
12
15
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
13
16
|
constructor() {
|
14
17
|
super(...arguments);
|
@@ -38,13 +41,16 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
38
41
|
: (0, umi_1.createSignerFromKeypair)(this.umi, this.umi.eddsa.generateKeypair());
|
39
42
|
}
|
40
43
|
}
|
41
|
-
this.marginfiAccountPk =
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if ("publicKey" in this.marginfiAccount) {
|
44
|
+
this.marginfiAccountPk = isSigner(this.marginfiAccount)
|
45
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccount.publicKey)
|
46
|
+
: this.marginfiAccount;
|
47
|
+
if (isSigner(this.marginfiAccount)) {
|
46
48
|
this.otherSigners.push(this.marginfiAccount);
|
47
49
|
}
|
50
|
+
else if (this.pos.selfManaged) {
|
51
|
+
const accountData = await (0, marginfi_sdk_1.fetchMarginfiAccount)(this.umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(this.marginfiAccount));
|
52
|
+
this.healthCheckRemainingAccounts = (await Promise.all(accountData.lendingAccount.balances.map((balance) => (0, utils_1.getRemainingAccountsForMarginfiHealthCheck)(this.umi, balance)))).flat();
|
53
|
+
}
|
48
54
|
this.marginfiSupplyAccounts =
|
49
55
|
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][this.pos.supplyMint.toString()];
|
50
56
|
this.marginfiDebtAccounts =
|
@@ -160,6 +166,13 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
160
166
|
});
|
161
167
|
}
|
162
168
|
case "Borrow": {
|
169
|
+
const remainingAccounts = this.healthCheckRemainingAccounts ?? [];
|
170
|
+
if (!remainingAccounts.find((x) => x.pubkey.toString() === this.marginfiDebtAccounts.bank.toString())) {
|
171
|
+
remainingAccounts.push(...[
|
172
|
+
(0, utils_1.getAccountMeta)(new web3_js_1.PublicKey(this.marginfiDebtAccounts.bank)),
|
173
|
+
(0, utils_1.getAccountMeta)(this.debtPriceOracle),
|
174
|
+
]);
|
175
|
+
}
|
163
176
|
return (0, marginfi_sdk_1.lendingAccountBorrow)(this.umi, {
|
164
177
|
amount: args.fields[0],
|
165
178
|
signer: this.signer,
|
@@ -169,7 +182,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
169
182
|
bank: (0, umi_1.publicKey)(this.marginfiDebtAccounts.bank),
|
170
183
|
bankLiquidityVault: (0, umi_1.publicKey)(this.marginfiDebtAccounts.liquidityVault),
|
171
184
|
bankLiquidityVaultAuthority: (0, umi_1.publicKey)(this.marginfiDebtAccounts.vaultAuthority),
|
172
|
-
});
|
185
|
+
}).addRemainingAccounts(remainingAccounts);
|
173
186
|
}
|
174
187
|
case "Repay": {
|
175
188
|
return (0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
@@ -194,7 +207,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
194
207
|
bank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
195
208
|
bankLiquidityVault: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.liquidityVault),
|
196
209
|
bankLiquidityVaultAuthority: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.vaultAuthority),
|
197
|
-
});
|
210
|
+
}).addRemainingAccounts(this.healthCheckRemainingAccounts ?? []);
|
198
211
|
}
|
199
212
|
}
|
200
213
|
}
|
@@ -39,6 +39,7 @@ export declare abstract class SolautoPositionEx {
|
|
39
39
|
private readonly firstState;
|
40
40
|
protected _supplyPrice?: number;
|
41
41
|
protected _debtPrice?: number;
|
42
|
+
rebalanceHelper: PositionRebalanceHelper;
|
42
43
|
constructor(args: PositionExArgs);
|
43
44
|
abstract lendingPool(): Promise<PublicKey>;
|
44
45
|
get exists(): boolean;
|
@@ -80,7 +81,6 @@ export declare abstract class SolautoPositionEx {
|
|
80
81
|
abstract maxLtvAndLiqThresholdBps(): Promise<[number, number]>;
|
81
82
|
abstract priceOracles(): Promise<PublicKey[]>;
|
82
83
|
get memecoinPosition(): boolean | undefined;
|
83
|
-
private sufficientLiquidityToBoost;
|
84
84
|
eligibleForRebalance(bpsDistanceThreshold?: number): RebalanceAction | undefined;
|
85
85
|
eligibleForRefresh(): boolean;
|
86
86
|
abstract refreshPositionState(priceType?: PriceType): Promise<void>;
|
@@ -94,5 +94,13 @@ export declare abstract class SolautoPositionEx {
|
|
94
94
|
simulateRebalance(unixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): undefined;
|
95
95
|
refetchPositionData(): Promise<void>;
|
96
96
|
}
|
97
|
+
declare class PositionRebalanceHelper {
|
98
|
+
private pos;
|
99
|
+
constructor(pos: SolautoPositionEx);
|
100
|
+
private sufficientLiquidityToBoost;
|
101
|
+
validRealtimePricesBoost(debtAdjustmentUsd: number): boolean;
|
102
|
+
private validBoostFromHere;
|
103
|
+
eligibleForRebalance(bpsDistanceThreshold: number): RebalanceAction | undefined;
|
104
|
+
}
|
97
105
|
export {};
|
98
106
|
//# sourceMappingURL=solautoPositionEx.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EACL,WAAW,EAEX,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,cAAc,
|
1
|
+
{"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EACL,WAAW,EAEX,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,cAAc,EAkBf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,E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AoB,EAAE,MAAM,GAC3B,eAAe,GAAG,SAAS;CA0B/B"}
|
@@ -25,6 +25,7 @@ class SolautoPositionEx {
|
|
25
25
|
this.lpEnv = args.customArgs?.lpEnv ?? "Prod";
|
26
26
|
this._data = args.data;
|
27
27
|
this.firstState = { ...args.data.state };
|
28
|
+
this.rebalanceHelper = new PositionRebalanceHelper(this);
|
28
29
|
}
|
29
30
|
get exists() {
|
30
31
|
return this._data.position !== undefined;
|
@@ -140,36 +141,8 @@ class SolautoPositionEx {
|
|
140
141
|
get memecoinPosition() {
|
141
142
|
return (0, utils_1.tokenInfo)(this.supplyMint).isMeme || (0, utils_1.tokenInfo)(this.debtMint).isMeme;
|
142
143
|
}
|
143
|
-
sufficientLiquidityToBoost() {
|
144
|
-
const limitsUpToDate = this.debtLiquidityUsdAvailable !== 0 ||
|
145
|
-
this.supplyLiquidityUsdDepositable !== 0;
|
146
|
-
if (limitsUpToDate) {
|
147
|
-
const { debtAdjustmentUsd } = (0, rebalance_1.getDebtAdjustment)(this.state.liqThresholdBps, { supplyUsd: this.supplyUsd(), debtUsd: this.debtUsd() }, this.boostToBps, { solauto: 50, lpBorrow: 50, flashLoan: 50 } // TODO: get true data here instead of magic numbers
|
148
|
-
);
|
149
|
-
const sufficientLiquidity = this.debtLiquidityUsdAvailable * 0.95 > debtAdjustmentUsd &&
|
150
|
-
this.supplyLiquidityUsdDepositable * 0.95 > debtAdjustmentUsd;
|
151
|
-
if (!sufficientLiquidity) {
|
152
|
-
(0, utils_1.consoleLog)("Insufficient liquidity to further boost");
|
153
|
-
}
|
154
|
-
return sufficientLiquidity;
|
155
|
-
}
|
156
|
-
return true;
|
157
|
-
}
|
158
144
|
eligibleForRebalance(bpsDistanceThreshold = 0) {
|
159
|
-
|
160
|
-
return undefined;
|
161
|
-
}
|
162
|
-
const realtimeLiqUtilRateBps = this.liqUtilizationRateBps(generated_1.PriceType.Realtime);
|
163
|
-
const emaLiqUtilRateBps = this.liqUtilizationRateBps(generated_1.PriceType.Ema);
|
164
|
-
if (this.repayFromBps - realtimeLiqUtilRateBps <= bpsDistanceThreshold) {
|
165
|
-
return "repay";
|
166
|
-
}
|
167
|
-
else if (realtimeLiqUtilRateBps - this.boostFromBps <= bpsDistanceThreshold ||
|
168
|
-
emaLiqUtilRateBps - this.boostFromBps <= bpsDistanceThreshold) {
|
169
|
-
const sufficientLiquidity = this.sufficientLiquidityToBoost();
|
170
|
-
return sufficientLiquidity ? "boost" : undefined;
|
171
|
-
}
|
172
|
-
return undefined;
|
145
|
+
return this.rebalanceHelper.eligibleForRebalance(bpsDistanceThreshold);
|
173
146
|
}
|
174
147
|
eligibleForRefresh() {
|
175
148
|
if (this.selfManaged)
|
@@ -224,3 +197,57 @@ class SolautoPositionEx {
|
|
224
197
|
}
|
225
198
|
}
|
226
199
|
exports.SolautoPositionEx = SolautoPositionEx;
|
200
|
+
class PositionRebalanceHelper {
|
201
|
+
constructor(pos) {
|
202
|
+
this.pos = pos;
|
203
|
+
}
|
204
|
+
sufficientLiquidityToBoost() {
|
205
|
+
const limitsUpToDate = this.pos.debtLiquidityUsdAvailable !== 0 ||
|
206
|
+
this.pos.supplyLiquidityUsdDepositable !== 0;
|
207
|
+
if (limitsUpToDate) {
|
208
|
+
const { debtAdjustmentUsd } = (0, rebalance_1.getDebtAdjustment)(this.pos.state.liqThresholdBps, { supplyUsd: this.pos.supplyUsd(), debtUsd: this.pos.debtUsd() }, this.pos.boostToBps, { solauto: 50, lpBorrow: 50, flashLoan: 50 } // Overshoot fees
|
209
|
+
);
|
210
|
+
const sufficientLiquidity = this.pos.debtLiquidityUsdAvailable * 0.95 > debtAdjustmentUsd &&
|
211
|
+
this.pos.supplyLiquidityUsdDepositable * 0.95 > debtAdjustmentUsd;
|
212
|
+
if (!sufficientLiquidity) {
|
213
|
+
(0, utils_1.consoleLog)("Insufficient liquidity to further boost");
|
214
|
+
}
|
215
|
+
return sufficientLiquidity;
|
216
|
+
}
|
217
|
+
return true;
|
218
|
+
}
|
219
|
+
validRealtimePricesBoost(debtAdjustmentUsd) {
|
220
|
+
if (this.pos.lendingPlatform !== generated_1.LendingPlatform.Marginfi) {
|
221
|
+
// TODO: LP
|
222
|
+
return true;
|
223
|
+
}
|
224
|
+
const postRebalanceLiqUtilRate = (0, utils_1.getLiqUtilzationRateBps)((0, utils_1.realtimeUsdToEmaUsd)(this.pos.supplyUsd() + debtAdjustmentUsd, this.pos.supplyMint), (0, utils_1.realtimeUsdToEmaUsd)(this.pos.debtUsd() + debtAdjustmentUsd, this.pos.debtMint), this.pos.state.liqThresholdBps);
|
225
|
+
return postRebalanceLiqUtilRate <= this.pos.maxBoostToBps;
|
226
|
+
}
|
227
|
+
validBoostFromHere() {
|
228
|
+
const { debtAdjustmentUsd } = (0, rebalance_1.getDebtAdjustment)(this.pos.state.liqThresholdBps, {
|
229
|
+
supplyUsd: this.pos.supplyUsd(generated_1.PriceType.Realtime),
|
230
|
+
debtUsd: this.pos.debtUsd(generated_1.PriceType.Realtime),
|
231
|
+
}, this.pos.boostToBps, { solauto: 25, lpBorrow: 0, flashLoan: 0 } // Undershoot fees
|
232
|
+
);
|
233
|
+
return this.validRealtimePricesBoost(debtAdjustmentUsd);
|
234
|
+
}
|
235
|
+
eligibleForRebalance(bpsDistanceThreshold) {
|
236
|
+
if (!this.pos.settings || !this.pos.supplyUsd()) {
|
237
|
+
return undefined;
|
238
|
+
}
|
239
|
+
const realtimeLiqUtilRateBps = this.pos.liqUtilizationRateBps(generated_1.PriceType.Realtime);
|
240
|
+
const emaLiqUtilRateBps = this.pos.liqUtilizationRateBps(generated_1.PriceType.Ema);
|
241
|
+
if (this.pos.repayFromBps - realtimeLiqUtilRateBps <=
|
242
|
+
bpsDistanceThreshold) {
|
243
|
+
return "repay";
|
244
|
+
}
|
245
|
+
else if ((realtimeLiqUtilRateBps - this.pos.boostFromBps <= bpsDistanceThreshold ||
|
246
|
+
emaLiqUtilRateBps - this.pos.boostFromBps <= bpsDistanceThreshold) &&
|
247
|
+
this.validBoostFromHere()) {
|
248
|
+
const sufficientLiquidity = this.sufficientLiquidityToBoost();
|
249
|
+
return sufficientLiquidity ? "boost" : undefined;
|
250
|
+
}
|
251
|
+
return undefined;
|
252
|
+
}
|
253
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { Program, Umi } from "@metaplex-foundation/umi";
|
2
|
+
import { AccountMeta, Program, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { ProgramEnv, MarginfiAssetAccounts } from "../types";
|
4
4
|
import { PositionState, PriceType } from "../generated";
|
5
5
|
import { MarginfiBankAccountsMap } from "../constants";
|
6
|
-
import { Bank, MarginfiAccount } from "../marginfi-sdk";
|
6
|
+
import { Balance, Bank, MarginfiAccount } from "../marginfi-sdk";
|
7
7
|
import { ContextUpdates } from "./solautoUtils";
|
8
8
|
export declare function createDynamicMarginfiProgram(env?: ProgramEnv): Program;
|
9
9
|
export declare function umiWithMarginfiProgram(umi: Umi, marginfiEnv?: ProgramEnv): Umi;
|
@@ -22,6 +22,7 @@ interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
|
|
22
22
|
mint: PublicKey;
|
23
23
|
}
|
24
24
|
export declare function findMarginfiAccounts(bank: PublicKey): AllMarginfiAssetAccounts;
|
25
|
+
export declare function getRemainingAccountsForMarginfiHealthCheck(umi: Umi, balance: Balance): Promise<AccountMeta[]>;
|
25
26
|
export declare function calcMarginfiMaxLtvAndLiqThresholdBps(supplyBank: Bank, debtBank: Bank, supplyPrice: number): [number, number];
|
26
27
|
export declare function getMarginfiMaxLtvAndLiqThresholdBps(umi: Umi, marginfiGroup: PublicKey, supply: {
|
27
28
|
mint: PublicKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EA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G;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;CAAE,CAAC;AA2BhE,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE;IAAE,EAAE,CAAC,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAA;CAAE,EAChE,aAAa,CAAC,EAAE,SAAS,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,UAAU,CAAC,EAAE,UAAU,EACvB,cAAc,CAAC,EAAE,cAAc,EAC/B,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CACN;IAAE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GACxE,SAAS,CACZ,CA2KA;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -6,6 +6,7 @@ exports.getAllBankRelatedAccounts = getAllBankRelatedAccounts;
|
|
6
6
|
exports.fetchBankAddresses = fetchBankAddresses;
|
7
7
|
exports.getMarginfiPriceOracle = getMarginfiPriceOracle;
|
8
8
|
exports.findMarginfiAccounts = findMarginfiAccounts;
|
9
|
+
exports.getRemainingAccountsForMarginfiHealthCheck = getRemainingAccountsForMarginfiHealthCheck;
|
9
10
|
exports.calcMarginfiMaxLtvAndLiqThresholdBps = calcMarginfiMaxLtvAndLiqThresholdBps;
|
10
11
|
exports.getMarginfiMaxLtvAndLiqThresholdBps = getMarginfiMaxLtvAndLiqThresholdBps;
|
11
12
|
exports.getEmptyMarginfiAccountsByAuthority = getEmptyMarginfiAccountsByAuthority;
|
@@ -25,6 +26,7 @@ const generalUtils_1 = require("./generalUtils");
|
|
25
26
|
const numberUtils_1 = require("./numberUtils");
|
26
27
|
const accountUtils_1 = require("./accountUtils");
|
27
28
|
const pythUtils_1 = require("./pythUtils");
|
29
|
+
const solanaUtils_1 = require("./solanaUtils");
|
28
30
|
function createDynamicMarginfiProgram(env) {
|
29
31
|
return {
|
30
32
|
name: "marginfi",
|
@@ -119,6 +121,18 @@ function findMarginfiAccounts(bank) {
|
|
119
121
|
}
|
120
122
|
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
121
123
|
}
|
124
|
+
async function getRemainingAccountsForMarginfiHealthCheck(umi, balance) {
|
125
|
+
if (!balance.active) {
|
126
|
+
return [];
|
127
|
+
}
|
128
|
+
const priceOracle = await getMarginfiPriceOracle(umi, {
|
129
|
+
pk: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(balance.bankPk),
|
130
|
+
});
|
131
|
+
return [
|
132
|
+
(0, solanaUtils_1.getAccountMeta)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(balance.bankPk)),
|
133
|
+
(0, solanaUtils_1.getAccountMeta)(priceOracle),
|
134
|
+
];
|
135
|
+
}
|
122
136
|
function calcMarginfiMaxLtvAndLiqThresholdBps(supplyBank, debtBank, supplyPrice) {
|
123
137
|
let maxLtv = (0, numberUtils_1.bytesToI80F48)(supplyBank.config.assetWeightInit.value) /
|
124
138
|
(0, numberUtils_1.bytesToI80F48)(debtBank.config.liabilityWeightInit.value);
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
1
2
|
import { PositionState } from "../generated";
|
2
3
|
import { RoundAction } from "../types";
|
3
4
|
export declare function calcNetWorthUsd(state?: PositionState): number;
|
@@ -23,4 +24,5 @@ export declare function getMaxLiqUtilizationRateBps(maxLtvBps: number, liqThresh
|
|
23
24
|
export declare function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number): number;
|
24
25
|
export declare function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number): number;
|
25
26
|
export declare function maxBoostToBps(maxLtvBps: number, liqThresholdBps: number): number;
|
27
|
+
export declare function realtimeUsdToEmaUsd(realtimeAmountUsd: number, mint: PublicKey): number;
|
26
28
|
//# sourceMappingURL=numberUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,OAAO,EAAE,aAAa,EAAa,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,aAAa,UAEpD;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,UAIlD;AAED,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,aAAa,UAIhD;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,aAAa,UAKjD;AAED,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,aAAa,UAKpD;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,UAKlD;AAED,wBAAgB,sBAAsB,CAAC,KAAK,CAAC,EAAE,aAAa,UAK3D;AAED,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,aAAa,UAI9D;AAED,wBAAgB,0BAA0B,CAAC,KAAK,CAAC,EAAE,aAAa,UAK/D;AAED,wBAAgB,6BAA6B,CAAC,KAAK,CAAC,EAAE,aAAa,UAIlE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,UAE/C;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,MAAM,CAMR;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,WAAW,GAAE,WAAqB,GACjC,MAAM,CAKR;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,EACb,WAAW,GAAE,WAAqB,GACjC,MAAM,CAGR;AAUD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAejE;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAKR;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UASzE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE;AAED,wBAAgB,mBAAmB,CACjC,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,SAAS,UAMhB"}
|
@@ -23,7 +23,10 @@ exports.getMaxLiqUtilizationRateBps = getMaxLiqUtilizationRateBps;
|
|
23
23
|
exports.maxRepayFromBps = maxRepayFromBps;
|
24
24
|
exports.maxRepayToBps = maxRepayToBps;
|
25
25
|
exports.maxBoostToBps = maxBoostToBps;
|
26
|
+
exports.realtimeUsdToEmaUsd = realtimeUsdToEmaUsd;
|
26
27
|
const constants_1 = require("../constants");
|
28
|
+
const generated_1 = require("../generated");
|
29
|
+
const priceUtils_1 = require("./priceUtils");
|
27
30
|
function calcNetWorthUsd(state) {
|
28
31
|
return fromRoundedUsdValue(state?.netWorth.baseAmountUsdValue ?? BigInt(0));
|
29
32
|
}
|
@@ -131,3 +134,7 @@ function maxRepayToBps(maxLtvBps, liqThresholdBps) {
|
|
131
134
|
function maxBoostToBps(maxLtvBps, liqThresholdBps) {
|
132
135
|
return Math.min(maxRepayToBps(maxLtvBps, liqThresholdBps), getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, constants_1.OFFSET_FROM_MAX_LTV));
|
133
136
|
}
|
137
|
+
function realtimeUsdToEmaUsd(realtimeAmountUsd, mint) {
|
138
|
+
return ((realtimeAmountUsd / (0, priceUtils_1.safeGetPrice)(mint, generated_1.PriceType.Realtime)) *
|
139
|
+
(0, priceUtils_1.safeGetPrice)(mint, generated_1.PriceType.Ema));
|
140
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
|
-
import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
2
|
+
import { AccountMeta, AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
3
3
|
import { PriorityFeeSetting, ProgramEnv, TransactionRunType } from "../types";
|
4
4
|
export declare function getSolanaRpcConnection(rpcUrl: string, programId?: PublicKey, lpEnv?: ProgramEnv): [Connection, Umi];
|
5
5
|
export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
|
@@ -9,6 +9,7 @@ export declare function createAssociatedTokenAccountUmiIx(signer: Signer, wallet
|
|
9
9
|
export declare function systemTransferUmiIx(signer: Signer, destination: PublicKey, lamports: bigint): WrappedInstruction;
|
10
10
|
export declare function closeTokenAccountUmiIx(signer: Signer, tokenAccount: PublicKey, authority: PublicKey): WrappedInstruction;
|
11
11
|
export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey, toTa: PublicKey, authority: PublicKey, amount: bigint): WrappedInstruction;
|
12
|
+
export declare function getAccountMeta(pubkey: PublicKey, isSigner?: boolean, isWritable?: boolean): AccountMeta;
|
12
13
|
export declare function getWalletSplBalances(conn: Connection, wallet: PublicKey, tokenMints: PublicKey[]): Promise<bigint[]>;
|
13
14
|
export declare function getAddressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
14
15
|
export declare function addTxOptimizations(umi: Umi, tx: TransactionBuilder, computeUnitPrice?: number, computeUnitLimit?: number): TransactionBuilder;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAe9E,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,SAAS,EACrB,KAAK,CAAC,EAAE,UAAU,GACjB,CAAC,UAAU,EAAE,GAAG,CAAC,CAWnB;AAED,wBAAgB,qBAAqB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E,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBAmB1B;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,CAAC,EAAE,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBA2D1B;AAuBD,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,MAAW,GACvB,OAAO,CAAC,GAAG,CAAC,CAKd;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,EACnC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwC7B;AA+CD,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,eAAe,GAAE,kBAA2C,EAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAoEjC"}
|
@@ -11,6 +11,7 @@ exports.createAssociatedTokenAccountUmiIx = createAssociatedTokenAccountUmiIx;
|
|
11
11
|
exports.systemTransferUmiIx = systemTransferUmiIx;
|
12
12
|
exports.closeTokenAccountUmiIx = closeTokenAccountUmiIx;
|
13
13
|
exports.splTokenTransferUmiIx = splTokenTransferUmiIx;
|
14
|
+
exports.getAccountMeta = getAccountMeta;
|
14
15
|
exports.getWalletSplBalances = getWalletSplBalances;
|
15
16
|
exports.getAddressLookupInputs = getAddressLookupInputs;
|
16
17
|
exports.addTxOptimizations = addTxOptimizations;
|
@@ -75,6 +76,9 @@ function closeTokenAccountUmiIx(signer, tokenAccount, authority) {
|
|
75
76
|
function splTokenTransferUmiIx(signer, fromTa, toTa, authority, amount) {
|
76
77
|
return getWrappedInstruction(signer, (0, spl_token_1.createTransferInstruction)(fromTa, toTa, authority, amount));
|
77
78
|
}
|
79
|
+
function getAccountMeta(pubkey, isSigner = false, isWritable = false) {
|
80
|
+
return { pubkey: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(pubkey), isSigner, isWritable };
|
81
|
+
}
|
78
82
|
async function getWalletSplBalances(conn, wallet, tokenMints) {
|
79
83
|
return await Promise.all(tokenMints.map(async (mint) => {
|
80
84
|
try {
|