@huma-finance/sdk 0.0.75-beta.981 → 0.0.75-beta.986
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/API.md +10 -0
- package/dist/cjs/utils/solana/buildOptimalTransaction.d.ts +10 -2
- package/dist/cjs/utils/solana/buildOptimalTransaction.js +32 -18
- package/dist/cjs/utils/solana/buildOptimalTransaction.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/solana/buildOptimalTransaction.d.ts +10 -2
- package/dist/utils/solana/buildOptimalTransaction.js +32 -18
- package/dist/utils/solana/buildOptimalTransaction.js.map +1 -1
- package/package.json +3 -3
package/API.md
CHANGED
|
@@ -72,6 +72,9 @@ Note that this does not approve a creditline in Huma's pools and an approve call
|
|
|
72
72
|
<dd><p>Get the chain ID from a signer or provider object.</p></dd>
|
|
73
73
|
<dt><a href="#getPoolInfo">getPoolInfo(poolName, poolType)</a> ⇒ <code>PoolInfoType</code> | <code>undefined</code></dt>
|
|
74
74
|
<dd><p>Returns the pool info based on the provided pool name and type, using the same chain ID as the provider/signer given</p></dd>
|
|
75
|
+
<dt><a href="#isSetComputeLimitInstruction">isSetComputeLimitInstruction()</a></dt>
|
|
76
|
+
<dd><p>Check if a given instruction is a SetComputeUnitLimit instruction
|
|
77
|
+
See https://github.com/solana-program/compute-budget/blob/main/clients/js/src/generated/programs/computeBudget.ts#L29</p></dd>
|
|
75
78
|
</dl>
|
|
76
79
|
|
|
77
80
|
## Typedefs
|
|
@@ -919,6 +922,13 @@ Note that this does not approve a creditline in Huma's pools and an approve call
|
|
|
919
922
|
| poolName | <code>POOL\_NAME</code> | <p>The name of the pool.</p> |
|
|
920
923
|
| poolType | <code>POOL\_TYPE</code> | <p>The type of the pool.</p> |
|
|
921
924
|
|
|
925
|
+
<a name="isSetComputeLimitInstruction"></a>
|
|
926
|
+
|
|
927
|
+
## isSetComputeLimitInstruction()
|
|
928
|
+
<p>Check if a given instruction is a SetComputeUnitLimit instruction
|
|
929
|
+
See https://github.com/solana-program/compute-budget/blob/main/clients/js/src/generated/programs/computeBudget.ts#L29</p>
|
|
930
|
+
|
|
931
|
+
**Kind**: global function
|
|
922
932
|
<a name="IrysConstructorArgs"></a>
|
|
923
933
|
|
|
924
934
|
## IrysConstructorArgs : <code>Object</code>
|
|
@@ -3,5 +3,13 @@ import { SolanaChainEnum } from '@huma-finance/shared';
|
|
|
3
3
|
import { HumaSolanaContext } from '../../helpers';
|
|
4
4
|
export declare function extractWritableAccounts(tx: Transaction): PublicKey[];
|
|
5
5
|
export type HeliusPriorityLevel = 'Min' | 'Low' | 'Medium' | 'High' | 'VeryHigh' | 'UnsafeMax';
|
|
6
|
-
export declare function buildOptimalTransaction(tx: Transaction, txAccounts: PublicKey[], context: HumaSolanaContext, heliusPriorityLevel?: HeliusPriorityLevel): Promise<
|
|
7
|
-
|
|
6
|
+
export declare function buildOptimalTransaction(tx: Transaction, txAccounts: PublicKey[], context: HumaSolanaContext, heliusPriorityLevel?: HeliusPriorityLevel): Promise<{
|
|
7
|
+
tx: Transaction;
|
|
8
|
+
unitsConsumed: number | undefined;
|
|
9
|
+
fee: number | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function buildOptimalTransactionFromConnection(tx: Transaction, txAccounts: PublicKey[], connection: Connection, chainId: SolanaChainEnum, signer: PublicKey, heliusPriorityLevel?: HeliusPriorityLevel, heliusApiKey?: string | null): Promise<{
|
|
12
|
+
tx: Transaction;
|
|
13
|
+
unitsConsumed: number | undefined;
|
|
14
|
+
fee: number | undefined;
|
|
15
|
+
}>;
|
|
@@ -50,24 +50,38 @@ async function getPriorityFeeEstimate(priorityLevel, tx, txAccounts, chainEnum,
|
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if a given instruction is a SetComputeUnitLimit instruction
|
|
55
|
+
* See https://github.com/solana-program/compute-budget/blob/main/clients/js/src/generated/programs/computeBudget.ts#L29
|
|
56
|
+
*/
|
|
57
|
+
function isSetComputeLimitInstruction(ix) {
|
|
58
|
+
return (ix.programId.equals(web3_js_1.ComputeBudgetProgram.programId) && ix.data[0] === 2 // opcode for setComputeUnitLimit is 2
|
|
59
|
+
);
|
|
60
|
+
}
|
|
53
61
|
async function buildOptimalTransactionImpl(tx, txAccounts, connection, chainEnum, signer, heliusPriority = 'Medium', heliusApiKey) {
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
let unitsConsumed;
|
|
63
|
+
const computeLimitIndex = tx.instructions.findIndex(isSetComputeLimitInstruction);
|
|
64
|
+
// Calculate compute unit limit if it doesn't exist
|
|
65
|
+
if (computeLimitIndex === -1) {
|
|
66
|
+
const testInstructions = [
|
|
67
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }),
|
|
68
|
+
...tx.instructions,
|
|
69
|
+
];
|
|
70
|
+
const testTransaction = new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
71
|
+
instructions: testInstructions,
|
|
72
|
+
payerKey: signer,
|
|
73
|
+
recentBlockhash: (await connection.getLatestBlockhash()).blockhash,
|
|
74
|
+
}).compileToV0Message([]));
|
|
75
|
+
const rpcResponse = await connection.simulateTransaction(testTransaction, {
|
|
76
|
+
replaceRecentBlockhash: true,
|
|
77
|
+
sigVerify: false,
|
|
78
|
+
});
|
|
79
|
+
unitsConsumed = rpcResponse.value.unitsConsumed;
|
|
80
|
+
if (unitsConsumed) {
|
|
81
|
+
tx.instructions.unshift(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
82
|
+
units: unitsConsumed * 1.2,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
71
85
|
}
|
|
72
86
|
// Calculate compute unit priority fee
|
|
73
87
|
const heliusPriorityFeeEstimateRes = await getPriorityFeeEstimate(heliusPriority, tx, txAccounts, chainEnum, heliusApiKey);
|
|
@@ -76,7 +90,7 @@ async function buildOptimalTransactionImpl(tx, txAccounts, connection, chainEnum
|
|
|
76
90
|
tx.instructions.unshift(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
77
91
|
microLamports: chosenFee,
|
|
78
92
|
}));
|
|
79
|
-
return tx;
|
|
93
|
+
return { tx, unitsConsumed, fee: chosenFee };
|
|
80
94
|
}
|
|
81
95
|
async function buildOptimalTransaction(tx, txAccounts, context, heliusPriorityLevel) {
|
|
82
96
|
return buildOptimalTransactionImpl(tx, txAccounts, context.connection, context.chainId, context.publicKey, heliusPriorityLevel, context.heliusApiKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildOptimalTransaction.js","sourceRoot":"","sources":["../../../../src/utils/solana/buildOptimalTransaction.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"buildOptimalTransaction.js","sourceRoot":"","sources":["../../../../src/utils/solana/buildOptimalTransaction.ts"],"names":[],"mappings":";;AAYA,0DAYC;AA+HD,0DAmBC;AAED,sFAsBC;AAlMD,6CAQwB;AACxB,iDAAsD;AAGtD,SAAgB,uBAAuB,CAAC,EAAe;IACrD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAa,CAAA;IAE7C,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC7B,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;gBACnB,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAClC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CA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