@haven-fi/solauto-sdk 1.0.85 → 1.0.87
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,9 @@ import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
|
4
4
|
import { ReferralState } from "../generated";
|
5
5
|
import { TxHandler } from "./txHandler";
|
6
6
|
interface ReferralStateManagerArgs {
|
7
|
-
referralAuthority?: PublicKey;
|
8
7
|
signer?: Signer;
|
9
8
|
wallet?: WalletAdapter;
|
9
|
+
referralAuthority?: PublicKey;
|
10
10
|
}
|
11
11
|
export declare class ReferralStateManager extends TxHandler {
|
12
12
|
localTest?: boolean | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"referralStateManager.d.ts","sourceRoot":"","sources":["../../src/clients/referralStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,MAAM,EAAkB,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,aAAa,EAAyB,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAA2C,aAAa,EAAgD,MAAM,cAAc,CAAC;AAEpI,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,wBAAwB;IAC9B,
|
1
|
+
{"version":3,"file":"referralStateManager.d.ts","sourceRoot":"","sources":["../../src/clients/referralStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,MAAM,EAAkB,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,aAAa,EAAyB,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAA2C,aAAa,EAAgD,MAAM,cAAc,CAAC;AAEpI,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,wBAAwB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,iBAAiB,CAAC,EAAE,SAAS,CAAC;CACjC;AAED,qBAAa,oBAAqB,SAAQ,SAAS;IAQN,SAAS,CAAC,EAAE,OAAO;IAPrD,GAAG,EAAG,GAAG,CAAC;IACV,MAAM,EAAG,MAAM,CAAC;IAEhB,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAC1B,iBAAiB,EAAG,aAAa,GAAG,IAAI,CAAC;gBAEpC,YAAY,EAAE,MAAM,EAAS,SAAS,CAAC,EAAE,OAAO,YAAA;IAStD,UAAU,CAAC,IAAI,EAAE,wBAAwB;IAe/C,mBAAmB,IAAI,MAAM,EAAE;IAI/B,sBAAsB,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAiBrH,mBAAmB,CAAC,YAAY,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAwB3D,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAC5C"}
|
@@ -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,
|
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,EAAyB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,qBAAqB,CAU3E;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,IAAI,EAAE;IACJ,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA+D3B;AAED,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CACR;IAAE,eAAe,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,CAC/E,CA6CA;AAgED,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
|
package/package.json
CHANGED
@@ -4,13 +4,13 @@ import { publicKey, Signer, signerIdentity, TransactionBuilder, Umi } from "@met
|
|
4
4
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
5
5
|
import { WalletAdapter, walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
6
6
|
import { claimReferralFees, createSolautoProgram, ReferralState, safeFetchReferralState, updateReferralStates } from "../generated";
|
7
|
-
import { getReferralState,
|
7
|
+
import { getReferralState, getTokenAccount } from "../utils";
|
8
8
|
import { TxHandler } from "./txHandler";
|
9
9
|
|
10
10
|
interface ReferralStateManagerArgs {
|
11
|
-
referralAuthority?: PublicKey;
|
12
11
|
signer?: Signer;
|
13
12
|
wallet?: WalletAdapter;
|
13
|
+
referralAuthority?: PublicKey;
|
14
14
|
}
|
15
15
|
|
16
16
|
export class ReferralStateManager extends TxHandler {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
2
|
+
import { publicKey, RpcAccount, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
5
|
Bank,
|
@@ -23,6 +23,7 @@ import { PositionState, PositionTokenUsage } from "../generated";
|
|
23
23
|
import { USD_DECIMALS } from "../constants/generalAccounts";
|
24
24
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
25
25
|
import { currentUnixSecondsSolana } from "./solanaUtils";
|
26
|
+
import { getSolautoPositionAccount } from "./accountUtils";
|
26
27
|
|
27
28
|
export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
28
29
|
for (const key in MARGINFI_ACCOUNTS) {
|
@@ -94,7 +95,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
94
95
|
BigInt(
|
95
96
|
Math.round(
|
96
97
|
bytesToI80F48(supply.bank!.totalAssetShares.value) *
|
97
|
-
|
98
|
+
bytesToI80F48(supply.bank!.assetShareValue.value)
|
98
99
|
)
|
99
100
|
),
|
100
101
|
supply.bank!.mintDecimals
|
@@ -190,7 +191,7 @@ async function getTokenUsage(
|
|
190
191
|
amountCanBeUsed = isAsset
|
191
192
|
? Number(bank.config.depositLimit) - totalDeposited
|
192
193
|
: totalDeposited -
|
193
|
-
|
194
|
+
bytesToI80F48(bank.totalLiabilityShares.value) * liabilityShareValue;
|
194
195
|
}
|
195
196
|
|
196
197
|
return {
|
@@ -200,22 +201,22 @@ async function getTokenUsage(
|
|
200
201
|
baseUnit: BigInt(Math.round(amountUsed)),
|
201
202
|
baseAmountUsdValue: bank
|
202
203
|
? toBaseUnit(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
204
|
+
fromBaseUnit(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
|
205
|
+
marketPrice,
|
206
|
+
USD_DECIMALS
|
207
|
+
)
|
207
208
|
: BigInt(0),
|
208
209
|
},
|
209
210
|
amountCanBeUsed: {
|
210
211
|
baseUnit: BigInt(Math.round(amountCanBeUsed)),
|
211
212
|
baseAmountUsdValue: bank
|
212
213
|
? toBaseUnit(
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
214
|
+
fromBaseUnit(
|
215
|
+
BigInt(Math.round(amountCanBeUsed)),
|
216
|
+
bank.mintDecimals
|
217
|
+
) * marketPrice,
|
218
|
+
USD_DECIMALS
|
219
|
+
)
|
219
220
|
: BigInt(0),
|
220
221
|
},
|
221
222
|
baseAmountMarketPriceUsd: toBaseUnit(marketPrice, USD_DECIMALS),
|
@@ -242,16 +243,16 @@ export async function getMarginfiAccountPositionState(
|
|
242
243
|
let supplyBank: Bank | null =
|
243
244
|
supplyMint && supplyMint !== PublicKey.default
|
244
245
|
? await safeFetchBank(
|
245
|
-
|
246
|
-
|
247
|
-
|
246
|
+
umi,
|
247
|
+
publicKey(MARGINFI_ACCOUNTS[supplyMint.toString()].bank)
|
248
|
+
)
|
248
249
|
: null;
|
249
250
|
let debtBank: Bank | null =
|
250
251
|
debtMint && debtMint !== PublicKey.default
|
251
252
|
? await safeFetchBank(
|
252
|
-
|
253
|
-
|
254
|
-
|
253
|
+
umi,
|
254
|
+
publicKey(MARGINFI_ACCOUNTS[debtMint.toString()].bank)
|
255
|
+
)
|
255
256
|
: null;
|
256
257
|
|
257
258
|
let supplyUsage: PositionTokenUsage | undefined = undefined;
|