@orca-so/common-sdk
Advanced tools
Comparing version 0.2.1 to 0.2.2-beta.1
@@ -0,3 +1,4 @@ | ||
export * from "./constants"; | ||
export * from "./transactions-builder"; | ||
export * from "./transactions-processor"; | ||
export * from "./types"; |
@@ -17,4 +17,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./constants"), exports); | ||
__exportStar(require("./transactions-builder"), exports); | ||
__exportStar(require("./transactions-processor"), exports); | ||
__exportStar(require("./types"), exports); |
@@ -34,2 +34,3 @@ import { AddressLookupTableAccount, Commitment, Connection, SendOptions, Signer, Transaction, VersionedTransaction } from "@solana/web3.js"; | ||
}; | ||
type SyncBuildOptions = BuildOptions & Required<BaseBuildOption>; | ||
/** | ||
@@ -99,4 +100,10 @@ * A set of options that the builder will use by default, unless overridden by the user in each method. | ||
*/ | ||
txnSize(userOptions?: Partial<BuildOptions>): Promise<number>; | ||
txnSize(userOptions?: Partial<BuildOptions>): number; | ||
/** | ||
* Constructs a transaction payload with the gathered instructions synchronously | ||
* @param options - Options used to build the transaction | ||
* @returns a TransactionPayload object that can be excuted or agregated into other transactions | ||
*/ | ||
buildSync(options: SyncBuildOptions): TransactionPayload; | ||
/** | ||
* Constructs a transaction payload with the gathered instructions | ||
@@ -103,0 +110,0 @@ * @param userOptions - Options to override the default build options |
@@ -14,2 +14,3 @@ "use strict"; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const constants_1 = require("./constants"); | ||
const LEGACY_TX_UNIQUE_KEYS_LIMIT = 35; | ||
@@ -121,11 +122,43 @@ exports.defaultTransactionBuilderOptions = { | ||
txnSize(userOptions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const finalOptions = Object.assign(Object.assign({}, this.opts.defaultBuildOption), userOptions); | ||
if (this.isEmpty()) { | ||
return 0; | ||
} | ||
const request = yield this.build(finalOptions); | ||
const tx = request.transaction; | ||
return (0, exports.isVersionedTransaction)(tx) ? measureV0Tx(tx) : measureLegacyTx(tx); | ||
const finalOptions = Object.assign(Object.assign(Object.assign({}, this.opts.defaultBuildOption), userOptions), { latestBlockhash: constants_1.MEASUREMENT_BLOCKHASH }); | ||
if (this.isEmpty()) { | ||
return 0; | ||
} | ||
const request = this.buildSync(finalOptions); | ||
const tx = request.transaction; | ||
return (0, exports.isVersionedTransaction)(tx) ? measureV0Tx(tx) : measureLegacyTx(tx); | ||
} | ||
/** | ||
* Constructs a transaction payload with the gathered instructions synchronously | ||
* @param options - Options used to build the transaction | ||
* @returns a TransactionPayload object that can be excuted or agregated into other transactions | ||
*/ | ||
buildSync(options) { | ||
const { latestBlockhash, maxSupportedTransactionVersion } = options; | ||
const ix = this.compressIx(true); | ||
const allSigners = ix.signers.concat(this.signers); | ||
const recentBlockhash = latestBlockhash; | ||
if (maxSupportedTransactionVersion === "legacy") { | ||
const transaction = new web3_js_1.Transaction(Object.assign(Object.assign({}, recentBlockhash), { feePayer: this.wallet.publicKey })); | ||
transaction.add(...ix.instructions); | ||
transaction.feePayer = this.wallet.publicKey; | ||
return { | ||
transaction: transaction, | ||
signers: allSigners, | ||
recentBlockhash, | ||
}; | ||
} | ||
const txnMsg = new web3_js_1.TransactionMessage({ | ||
recentBlockhash: recentBlockhash.blockhash, | ||
payerKey: this.wallet.publicKey, | ||
instructions: ix.instructions, | ||
}); | ||
const { lookupTableAccounts } = options; | ||
const msg = txnMsg.compileToV0Message(lookupTableAccounts); | ||
const v0txn = new web3_js_1.VersionedTransaction(msg); | ||
return { | ||
transaction: v0txn, | ||
signers: allSigners, | ||
recentBlockhash, | ||
}; | ||
} | ||
@@ -140,3 +173,3 @@ /** | ||
const finalOptions = Object.assign(Object.assign({}, this.opts.defaultBuildOption), userOptions); | ||
const { latestBlockhash, maxSupportedTransactionVersion, blockhashCommitment } = finalOptions; | ||
const { latestBlockhash, blockhashCommitment } = finalOptions; | ||
let recentBlockhash = latestBlockhash; | ||
@@ -146,27 +179,3 @@ if (!recentBlockhash) { | ||
} | ||
const ix = this.compressIx(true); | ||
const allSigners = ix.signers.concat(this.signers); | ||
if (maxSupportedTransactionVersion === "legacy") { | ||
const transaction = new web3_js_1.Transaction(Object.assign(Object.assign({}, recentBlockhash), { feePayer: this.wallet.publicKey })); | ||
transaction.add(...ix.instructions); | ||
transaction.feePayer = this.wallet.publicKey; | ||
return { | ||
transaction: transaction, | ||
signers: allSigners, | ||
recentBlockhash, | ||
}; | ||
} | ||
const txnMsg = new web3_js_1.TransactionMessage({ | ||
recentBlockhash: recentBlockhash.blockhash, | ||
payerKey: this.wallet.publicKey, | ||
instructions: ix.instructions, | ||
}); | ||
const { lookupTableAccounts } = finalOptions; | ||
const msg = txnMsg.compileToV0Message(lookupTableAccounts); | ||
const v0txn = new web3_js_1.VersionedTransaction(msg); | ||
return { | ||
transaction: v0txn, | ||
signers: allSigners, | ||
recentBlockhash, | ||
}; | ||
return this.buildSync(Object.assign(Object.assign({}, finalOptions), { latestBlockhash: recentBlockhash })); | ||
}); | ||
@@ -195,3 +204,5 @@ } | ||
const signedTxn = yield this.wallet.signTransaction(txn); | ||
btx.signers.filter((s) => s !== undefined).forEach((keypair) => signedTxn.partialSign(keypair)); | ||
btx.signers | ||
.filter((s) => s !== undefined) | ||
.forEach((keypair) => signedTxn.partialSign(keypair)); | ||
txId = yield this.connection.sendRawTransaction(signedTxn.serialize(), sendOpts); | ||
@@ -198,0 +209,0 @@ } |
{ | ||
"name": "@orca-so/common-sdk", | ||
"version": "0.2.1", | ||
"version": "0.2.2-beta.1", | ||
"description": "Common Typescript components across Orca", | ||
@@ -43,2 +43,2 @@ "repository": "https://github.com/orca-so/orca-sdks", | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1572
110414