@haven-fi/solauto-sdk 1.0.759 → 1.0.761
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/solauto/txHandler.d.ts +3 -3
- package/dist/services/solauto/txHandler.d.ts.map +1 -1
- package/dist/services/solauto/txHandler.js +4 -0
- package/dist/services/transactions/manager/transactionsManager.js +1 -1
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +3 -1
- package/local/txSandbox.ts +72 -19
- package/package.json +1 -1
- package/src/services/solauto/txHandler.ts +5 -3
- package/src/services/transactions/manager/transactionsManager.ts +1 -1
- package/src/utils/generalUtils.ts +12 -2
@@ -10,7 +10,7 @@ export interface TxHandlerProps {
|
|
10
10
|
programId?: PublicKey;
|
11
11
|
lpEnv?: ProgramEnv;
|
12
12
|
}
|
13
|
-
export declare
|
13
|
+
export declare class TxHandler {
|
14
14
|
rpcUrl: string;
|
15
15
|
showLogs: boolean;
|
16
16
|
programId: PublicKey;
|
@@ -21,7 +21,7 @@ export declare abstract class TxHandler {
|
|
21
21
|
otherSigners: Signer[];
|
22
22
|
constructor(props: TxHandlerProps);
|
23
23
|
log(...args: any[]): void;
|
24
|
-
|
25
|
-
|
24
|
+
defaultLookupTables(): string[];
|
25
|
+
resetLiveTxUpdates(success?: boolean): void;
|
26
26
|
}
|
27
27
|
//# sourceMappingURL=txHandler.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAkB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,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GAAG,MAAM,WAErE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAC5B,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,EAAE,GACV,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAInB"}
|
@@ -116,7 +116,9 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
116
116
|
.then(resolve)
|
117
117
|
.catch((error) => {
|
118
118
|
attemptNum++;
|
119
|
-
|
119
|
+
console.log(error.name, error.message);
|
120
|
+
console.log(errorsToThrow?.length, (errorsToThrow ?? []).some((errorType) => error instanceof errorType));
|
121
|
+
if (errorsToThrow?.length &&
|
120
122
|
errorsToThrow.some((errorType) => error instanceof errorType)) {
|
121
123
|
reject(error);
|
122
124
|
return;
|
package/local/txSandbox.ts
CHANGED
@@ -1,28 +1,41 @@
|
|
1
1
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
2
|
-
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
2
|
+
import { createSignerFromKeypair, publicKey } from "@metaplex-foundation/umi";
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
|
+
bytesToI80F48,
|
5
6
|
ClientTransactionsManager,
|
6
7
|
consoleLog,
|
8
|
+
fetchBank,
|
9
|
+
fetchMarginfiAccount,
|
10
|
+
fromBaseUnit,
|
11
|
+
getBankLiquidityAvailableBaseUnit,
|
7
12
|
getBatches,
|
8
13
|
getClient,
|
14
|
+
getMarginfiAccounts,
|
9
15
|
getPositionExBulk,
|
10
16
|
getSolanaRpcConnection,
|
11
17
|
getSolautoManagedPositions,
|
18
|
+
lendingAccountDeposit,
|
12
19
|
LendingPlatform,
|
13
20
|
LOCAL_IRONFORGE_API_URL,
|
14
21
|
PriceType,
|
15
22
|
PriorityFeeSetting,
|
16
23
|
ProgramEnv,
|
17
24
|
rebalance,
|
25
|
+
SOLAUTO_MANAGER,
|
18
26
|
SOLAUTO_PROD_PROGRAM,
|
19
27
|
SOLAUTO_TEST_PROGRAM,
|
20
28
|
SolautoClient,
|
29
|
+
toBaseUnit,
|
21
30
|
TransactionItem,
|
31
|
+
TransactionsManager,
|
32
|
+
TxHandler,
|
33
|
+
USDC,
|
22
34
|
} from "../src";
|
23
35
|
import { getSecretKey } from "./shared";
|
36
|
+
import { getTokenAccount, tokenInfo } from "../dist";
|
24
37
|
|
25
|
-
const payForTransaction =
|
38
|
+
const payForTransaction = true;
|
26
39
|
const testProgram = false;
|
27
40
|
const lpEnv: ProgramEnv = "Prod";
|
28
41
|
|
@@ -38,26 +51,66 @@ const signer = createSignerFromKeypair(
|
|
38
51
|
);
|
39
52
|
|
40
53
|
export async function main() {
|
41
|
-
const
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
});
|
54
|
+
const USDC_MINT = new PublicKey(USDC);
|
55
|
+
const group = new PublicKey("DQ2jqDJw9uzTwttf6h6r217BQ7kws3jZbJXDkfbCJa1q");
|
56
|
+
const accounts =
|
57
|
+
getMarginfiAccounts("Prod").bankAccounts[group.toString()][
|
58
|
+
USDC_MINT.toString()
|
59
|
+
];
|
48
60
|
|
49
|
-
await
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
const bank = await fetchBank(umi, publicKey(accounts.bank));
|
62
|
+
|
63
|
+
const assets =
|
64
|
+
bytesToI80F48(bank.totalAssetShares.value) *
|
65
|
+
bytesToI80F48(bank.assetShareValue.value);
|
66
|
+
const liabs =
|
67
|
+
bytesToI80F48(bank.totalLiabilityShares.value) *
|
68
|
+
bytesToI80F48(bank.liabilityShareValue.value);
|
69
|
+
|
70
|
+
console.log(fromBaseUnit(BigInt(Math.round(assets)), 6));
|
71
|
+
console.log(fromBaseUnit(BigInt(Math.round(liabs)), 6));
|
72
|
+
const missingLiquidity = getBankLiquidityAvailableBaseUnit(bank, false);
|
73
|
+
console.log(fromBaseUnit(missingLiquidity, 6));
|
74
|
+
|
75
|
+
const marginfiAccount = await fetchMarginfiAccount(
|
76
|
+
umi,
|
77
|
+
publicKey("Fun9UD87tLCxqxoTvpGYAy6Uwk2eevFGDk1VvxpXbd5x")
|
78
|
+
);
|
79
|
+
const managerAssets =
|
80
|
+
bytesToI80F48(
|
81
|
+
marginfiAccount.lendingAccount.balances[0].assetShares.value
|
82
|
+
) * bytesToI80F48(bank.assetShareValue.value);
|
83
|
+
console.log(fromBaseUnit(BigInt(Math.round(managerAssets)), 6));
|
56
84
|
|
57
|
-
const
|
85
|
+
const depositAmt =
|
86
|
+
missingLiquidity * BigInt(-1) + BigInt(toBaseUnit(620 + 20, 6));
|
87
|
+
console.log("Depositing", fromBaseUnit(depositAmt, 6));
|
88
|
+
const transactionItems = [
|
89
|
+
new TransactionItem(
|
90
|
+
async () => ({
|
91
|
+
tx: lendingAccountDeposit(umi, {
|
92
|
+
signer,
|
93
|
+
signerTokenAccount: publicKey(
|
94
|
+
getTokenAccount(SOLAUTO_MANAGER, USDC_MINT)
|
95
|
+
),
|
96
|
+
marginfiAccount: marginfiAccount.publicKey,
|
97
|
+
marginfiGroup: publicKey(group),
|
98
|
+
bank: bank.publicKey,
|
99
|
+
bankLiquidityVault: publicKey(accounts.liquidityVault),
|
100
|
+
amount: depositAmt,
|
101
|
+
depositUpToLimit: true,
|
102
|
+
}),
|
103
|
+
}),
|
104
|
+
"deposit"
|
105
|
+
),
|
106
|
+
];
|
58
107
|
|
59
|
-
const txManager = new
|
60
|
-
txHandler:
|
108
|
+
const txManager = new TransactionsManager({
|
109
|
+
txHandler: new TxHandler({
|
110
|
+
signer,
|
111
|
+
rpcUrl: LOCAL_IRONFORGE_API_URL,
|
112
|
+
showLogs: true,
|
113
|
+
}),
|
61
114
|
txRunType: payForTransaction ? "normal" : "only-simulate",
|
62
115
|
priorityFeeSetting: PriorityFeeSetting.Default,
|
63
116
|
retryConfig: { totalRetries: 2 },
|
package/package.json
CHANGED
@@ -17,7 +17,7 @@ export interface TxHandlerProps {
|
|
17
17
|
lpEnv?: ProgramEnv;
|
18
18
|
}
|
19
19
|
|
20
|
-
export
|
20
|
+
export class TxHandler {
|
21
21
|
public rpcUrl!: string;
|
22
22
|
public showLogs = false;
|
23
23
|
public programId!: PublicKey;
|
@@ -64,7 +64,9 @@ export abstract class TxHandler {
|
|
64
64
|
consoleLog(...args);
|
65
65
|
}
|
66
66
|
|
67
|
-
|
67
|
+
defaultLookupTables(): string[] {
|
68
|
+
return [];
|
69
|
+
}
|
68
70
|
|
69
|
-
|
71
|
+
resetLiveTxUpdates(success?: boolean) {}
|
70
72
|
}
|
@@ -126,8 +126,15 @@ export function retryWithExponentialBackoff<T>(
|
|
126
126
|
.catch((error: Error) => {
|
127
127
|
attemptNum++;
|
128
128
|
|
129
|
+
console.log(error.name, error.message);
|
130
|
+
console.log(
|
131
|
+
errorsToThrow?.length,
|
132
|
+
(errorsToThrow ?? []).some(
|
133
|
+
(errorType) => error instanceof errorType
|
134
|
+
)
|
135
|
+
);
|
129
136
|
if (
|
130
|
-
errorsToThrow &&
|
137
|
+
errorsToThrow?.length &&
|
131
138
|
errorsToThrow.some((errorType) => error instanceof errorType)
|
132
139
|
) {
|
133
140
|
reject(error);
|
@@ -206,7 +213,10 @@ export function validPubkey(pubkey?: PublicKey | UmiPublicKey | string) {
|
|
206
213
|
return Boolean(pubkey) && pubkey!.toString() !== PublicKey.default.toString();
|
207
214
|
}
|
208
215
|
|
209
|
-
export function createRecord<T>(
|
216
|
+
export function createRecord<T>(
|
217
|
+
keys: string[],
|
218
|
+
values: T[]
|
219
|
+
): Record<string, T> {
|
210
220
|
return Object.fromEntries(
|
211
221
|
zip(keys, values).map(([k, v]) => [k.toString(), v])
|
212
222
|
);
|