@haven-fi/solauto-sdk 1.0.199 → 1.0.200
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +1 -0
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +5 -8
- package/dist/utils/accountUtils.d.ts +1 -1
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +2 -2
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +3 -3
- package/src/clients/solautoMarginfiClient.ts +9 -18
- package/src/utils/accountUtils.ts +2 -2
@@ -9,6 +9,7 @@ import { ReferralStateManager } from "./referralStateManager";
|
|
9
9
|
import { TxHandler } from "./txHandler";
|
10
10
|
import { QuoteResponse } from "@jup-ag/api";
|
11
11
|
export interface SolautoClientArgs {
|
12
|
+
new?: boolean;
|
12
13
|
authority?: PublicKey;
|
13
14
|
positionId?: number;
|
14
15
|
signer?: Signer;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,MAAM,EACN,kBAAkB,EAOnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAEhC,sBAAsB,EAMvB,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS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G,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IA0BrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IAwDlE,eAAe,IAAI,kBAAkB;IAYrC,WAAW,IAAI,kBAAkB;IAgCjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -38,7 +38,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
38
38
|
this.selfManaged = this.positionId === 0;
|
39
39
|
this.lendingPlatform = lendingPlatform;
|
40
40
|
this.solautoPosition = (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
|
41
|
-
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" });
|
41
|
+
this.solautoPositionData = !args.new ? await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" }) : null;
|
42
42
|
this.solautoPositionState = this.solautoPositionData?.state;
|
43
43
|
this.maxLtvBps = undefined;
|
44
44
|
this.liqThresholdBps = undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","s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B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IA6D1C,8BAA8B;IA0CpC,eAAe,IAAI,SAAS;IAI5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAUzB,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0BvE,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA8C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAqErB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA6ClE"}
|
@@ -12,7 +12,6 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
12
12
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
15
|
-
const utils_1 = require("../utils");
|
16
15
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
17
16
|
constructor() {
|
18
17
|
super(...arguments);
|
@@ -30,13 +29,15 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
30
29
|
this.marginfiAccountSeedIdx = (0, generalUtils_1.generateRandomU64)();
|
31
30
|
this.marginfiAccount = this.solautoPositionData
|
32
31
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.protocolAccount)
|
33
|
-
:
|
32
|
+
: (0, accountUtils_1.getMarginfiAccountPDA)(this.solautoPosition, this.marginfiAccountSeedIdx);
|
34
33
|
}
|
35
34
|
this.marginfiAccountPk =
|
36
35
|
"publicKey" in this.marginfiAccount
|
37
36
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccount.publicKey)
|
38
37
|
: this.marginfiAccount;
|
39
|
-
const marginfiAccountData =
|
38
|
+
const marginfiAccountData = !args.new
|
39
|
+
? await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(this.umi, (0, umi_1.publicKey)(this.marginfiAccountPk), { commitment: "confirmed" })
|
40
|
+
: null;
|
40
41
|
this.marginfiGroup = new web3_js_1.PublicKey(marginfiAccountData
|
41
42
|
? marginfiAccountData.group.toString()
|
42
43
|
: (args.marginfiGroup ?? marginfiAccounts_1.DEFAULT_MARGINFI_GROUP));
|
@@ -44,7 +45,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
44
45
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.supplyMint.toString()];
|
45
46
|
this.marginfiDebtAccounts =
|
46
47
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.debtMint.toString()];
|
47
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
48
|
+
// TODO: Don't dynamically pull oracle from bank until Marginfi sorts out their price oracle issues.
|
48
49
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
49
50
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
50
51
|
// publicKey(this.marginfiDebtAccounts.bank),
|
@@ -53,10 +54,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
53
54
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
54
55
|
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
55
56
|
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
56
|
-
if (!this.solautoPositionState) {
|
57
|
-
const result = await this.maxLtvAndLiqThresholdBps();
|
58
|
-
this.solautoPositionState = (0, utils_1.createFakePositionState)({ mint: this.supplyMint }, { mint: this.debtMint }, result ? result[0] : 0, result ? result[1] : 0);
|
59
|
-
}
|
60
57
|
if (!this.initialized) {
|
61
58
|
await this.setIntermediaryMarginfiDetails();
|
62
59
|
}
|
@@ -7,5 +7,5 @@ export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKe
|
|
7
7
|
export declare function getTokenAccountData(umi: Umi, tokenAccount: PublicKey): Promise<import("@solana/spl-token").RawAccount | undefined>;
|
8
8
|
export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): PublicKey;
|
9
9
|
export declare function getReferralState(authority: PublicKey): PublicKey;
|
10
|
-
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint):
|
10
|
+
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint): PublicKey;
|
11
11
|
//# sourceMappingURL=accountUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;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B,EAAE,MAAM,aAa/B"}
|
@@ -47,11 +47,11 @@ function getReferralState(authority) {
|
|
47
47
|
const [ReferralState, _] = web3_js_1.PublicKey.findProgramAddressSync([strBuffer, authority.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
48
48
|
return ReferralState;
|
49
49
|
}
|
50
|
-
|
50
|
+
function getMarginfiAccountPDA(solautoPositionAccount, marginfiAccountSeedIdx) {
|
51
51
|
const seeds = [
|
52
52
|
solautoPositionAccount.toBuffer(),
|
53
53
|
bufferFromU64(marginfiAccountSeedIdx),
|
54
54
|
];
|
55
|
-
const [marginfiAccount, _] =
|
55
|
+
const [marginfiAccount, _] = web3_js_1.PublicKey.findProgramAddressSync(seeds, new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
56
56
|
return marginfiAccount;
|
57
57
|
}
|
package/package.json
CHANGED
@@ -39,7 +39,6 @@ import {
|
|
39
39
|
getTokenAccount,
|
40
40
|
} from "../utils/accountUtils";
|
41
41
|
import { SOLAUTO_FEES_WALLET } from "../constants/generalAccounts";
|
42
|
-
import { JupSwapDetails } from "../utils/jupiterUtils";
|
43
42
|
import {
|
44
43
|
getWrappedInstruction,
|
45
44
|
splTokenTransferUmiIx,
|
@@ -56,6 +55,7 @@ import { TxHandler } from "./txHandler";
|
|
56
55
|
import { QuoteResponse } from "@jup-ag/api";
|
57
56
|
|
58
57
|
export interface SolautoClientArgs {
|
58
|
+
new?: boolean;
|
59
59
|
authority?: PublicKey;
|
60
60
|
positionId?: number;
|
61
61
|
signer?: Signer;
|
@@ -133,11 +133,11 @@ export abstract class SolautoClient extends TxHandler {
|
|
133
133
|
this.authority,
|
134
134
|
this.positionId
|
135
135
|
);
|
136
|
-
this.solautoPositionData = await safeFetchSolautoPosition(
|
136
|
+
this.solautoPositionData = !args.new ? await safeFetchSolautoPosition(
|
137
137
|
this.umi,
|
138
138
|
publicKey(this.solautoPosition),
|
139
139
|
{ commitment: "confirmed" }
|
140
|
-
);
|
140
|
+
) : null;
|
141
141
|
this.solautoPositionState = this.solautoPositionData?.state;
|
142
142
|
|
143
143
|
this.maxLtvBps = undefined;
|
@@ -96,7 +96,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
96
96
|
this.marginfiAccountSeedIdx = generateRandomU64();
|
97
97
|
this.marginfiAccount = this.solautoPositionData
|
98
98
|
? toWeb3JsPublicKey(this.solautoPositionData.position.protocolAccount)
|
99
|
-
:
|
99
|
+
: getMarginfiAccountPDA(
|
100
100
|
this.solautoPosition,
|
101
101
|
this.marginfiAccountSeedIdx
|
102
102
|
);
|
@@ -106,11 +106,13 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
106
106
|
? toWeb3JsPublicKey(this.marginfiAccount.publicKey)
|
107
107
|
: this.marginfiAccount;
|
108
108
|
|
109
|
-
const marginfiAccountData =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
const marginfiAccountData = !args.new
|
110
|
+
? await safeFetchMarginfiAccount(
|
111
|
+
this.umi,
|
112
|
+
publicKey(this.marginfiAccountPk),
|
113
|
+
{ commitment: "confirmed" }
|
114
|
+
)
|
115
|
+
: null;
|
114
116
|
this.marginfiGroup = new PublicKey(
|
115
117
|
marginfiAccountData
|
116
118
|
? marginfiAccountData.group.toString()
|
@@ -126,29 +128,18 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
126
128
|
this.debtMint.toString()
|
127
129
|
]!;
|
128
130
|
|
129
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
131
|
+
// TODO: Don't dynamically pull oracle from bank until Marginfi sorts out their price oracle issues.
|
130
132
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
131
133
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
132
134
|
// publicKey(this.marginfiDebtAccounts.bank),
|
133
135
|
// ]);
|
134
136
|
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
135
137
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
136
|
-
|
137
138
|
this.supplyPriceOracle = new PublicKey(
|
138
139
|
this.marginfiSupplyAccounts.priceOracle
|
139
140
|
);
|
140
141
|
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
141
142
|
|
142
|
-
if (!this.solautoPositionState) {
|
143
|
-
const result = await this.maxLtvAndLiqThresholdBps()!;
|
144
|
-
this.solautoPositionState = createFakePositionState(
|
145
|
-
{ mint: this.supplyMint },
|
146
|
-
{ mint: this.debtMint },
|
147
|
-
result ? result[0] : 0,
|
148
|
-
result ? result[1] : 0
|
149
|
-
);
|
150
|
-
}
|
151
|
-
|
152
143
|
if (!this.initialized) {
|
153
144
|
await this.setIntermediaryMarginfiDetails();
|
154
145
|
}
|
@@ -60,7 +60,7 @@ export function getReferralState(authority: PublicKey) {
|
|
60
60
|
return ReferralState;
|
61
61
|
}
|
62
62
|
|
63
|
-
export
|
63
|
+
export function getMarginfiAccountPDA(
|
64
64
|
solautoPositionAccount: PublicKey,
|
65
65
|
marginfiAccountSeedIdx: bigint
|
66
66
|
) {
|
@@ -69,7 +69,7 @@ export async function getMarginfiAccountPDA(
|
|
69
69
|
bufferFromU64(marginfiAccountSeedIdx),
|
70
70
|
];
|
71
71
|
|
72
|
-
const [marginfiAccount, _] =
|
72
|
+
const [marginfiAccount, _] = PublicKey.findProgramAddressSync(
|
73
73
|
seeds,
|
74
74
|
new PublicKey(SOLAUTO_PROGRAM_ID)
|
75
75
|
);
|