@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
67 lines • 2.39 kB
JavaScript
;
/**
* @purpose Simplified setDelegate instruction wrapper
*
* Thin convenience wrapper around Codama-generated setDelegate instruction.
* Allows contract owners to set or remove a delegate address that can update the contract rate.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.setDelegate = setDelegate;
const kit_1 = require("@solana/kit");
const instructions_1 = require("../generated/codama/instructions");
const config_1 = require("../utils/config");
const signer_1 = require("../utils/signer");
const instructions_2 = require("../utils/instructions");
/**
* Set or clear a delegate that may update a contract's rate. Owner-only.
*
* @param params - Delegate parameters
* @param config - Optional SDK configuration overrides
* @returns Kit instruction (or web3.js if PublicKey in config)
*
* @example
* ```typescript
* // Set a delegate
* const ix = await setDelegate({
* owner: wallet,
* contract: contractAddress,
* delegate: delegateAddress
* });
*
* // Remove delegate
* const ix2 = await setDelegate({
* owner: wallet,
* contract: contractAddress,
* delegate: null // or omit delegate entirely
* });
* ```
*/
async function setDelegate(params, config) {
// Merge config
const finalConfig = (0, config_1.mergeConfig)(config);
// Validate required params
if (!params.owner) {
throw new Error('owner is required');
}
if (!params.contract) {
throw new Error('contract is required');
}
// Convert owner to transaction signer
const ownerSigner = (0, signer_1.toTransactionSigner)(params.owner);
// Get network-specific addresses
const addresses = (0, config_1.getAddresses)(config);
const programAddress = (0, kit_1.address)(addresses.srsly);
// Convert delegate to Option<Address>
const delegateOption = params.delegate ? (0, kit_1.address)(params.delegate) : null;
// Call Codama-generated instruction
const kitInstruction = (0, instructions_1.getSetDelegateInstruction)({
owner: ownerSigner,
contract: (0, kit_1.address)(params.contract),
delegate: delegateOption,
}, { programAddress });
return (0, instructions_2.prepareInstructions)(kitInstruction, {
computeUnits: params.computeUnits,
PublicKey: finalConfig.PublicKey,
});
}
//# sourceMappingURL=setDelegate.js.map