Skip to main content

Class: SolanaWriter

Defined in: solana-client/src/writer.ts:110

Solana implementation of OvercastWriter.

Each method maps an Overcast domain object onto the corresponding on-chain instruction and returns the prepared transaction. PDAs are derived locally via the ./pda helpers (mirroring the program's seeds = [..]), and the per-asset SPL token program is resolved by reading each mint's owner so both legacy Token and Token-2022 assets are handled. The protocol's claim mints use the permanent-delegate extension and are therefore always Token-2022.

Domain types carry asset / account references as base58 Bytes32 strings; offers and options are content-addressed, so MarketOption.collateralOffer / settlementOffer are the 32-byte offer ids whose bytes seed the PDAs.

The signer / fee payer is taken from the program's provider wallet. This is the write side only; on-chain reads live in SolanaReader.

Implements​

Constructors​

Constructor​

new SolanaWriter(program): SolanaWriter;

Defined in: solana-client/src/writer.ts:111

Parameters​

ParameterType
programProgram<OvercastCore>

Returns​

SolanaWriter

Methods​

borrowCollateral()​

borrowCollateral(
option,
amount,
metadata?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:769

borrows collateral out of the option's escrow into the taker's own collateral token account, tracking an outstanding-borrow debt on the option. Only permitted while option.details.borrowAllowed is set and before the option's exercise window starts (option.details.startTimestamp); the settlement layer additionally decides whether the borrow is allowed. Repayment is trusted, not enforced on chain — only take a borrow-enabled option from a taker you trust to honor it. The option is neither exercisable nor redeemable until all borrowed collateral is repaid. The taker must sign this transaction themselves (not delegable).

Parameters​

ParameterTypeDescription
optionMarketOption-
amountbigintnative (smallest-unit) amount of option.details.collateralAsset to borrow.
metadataMetadataopaque settlement-layer metadata, forwarded to the layer's borrow check verbatim (see exerciseOption). Defaults to empty.

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.borrowCollateral

burnExerciseClaims()​

burnExerciseClaims(option, holder): Promise<Transaction>;

Defined in: solana-client/src/writer.ts:603

Burns the exercise claims holder still has left on an expired option, writing off the entire balance of their Token-2022 claim ATA in one call.

Solana-specific: like closeOptionAccounts this is account cleanup with no counterpart in the chain-agnostic OvercastWriter, so it isn't part of that interface — and being outside it, returns the bare transaction rather than the TxStep list every interface method does. The two go together — an exercise claim mint can only be closed at zero supply, so every remaining holder's claims must be burned before the option's accounts can be reclaimed.

Permissionless, and notably it does not need the holder's signature: the mint's permanent delegate is the protocol state, so the program burns on the holder's behalf and only the fee payer signs. What bounds it instead is time — the program requires the option to be past details.endTimestamp, so unexercised claims can't be destroyed while they are still worth something. Burning zero is a no-op on chain rather than an error.

Parameters​

ParameterTypeDescription
optionMarketOptionthe option whose exercise claims to burn; must match the on-chain, content-addressed option exactly.
holderBytes32the account whose claims are burned. Its claim ATA must exist — the address the protocol mints claims to (see matchOffer / exerciseOption); claims parked in a non-ATA token account are out of reach here.

Returns​

Promise<Transaction>


cancelOffer()​

cancelOffer(
offer,
operation?,
accountCreator?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:162

cancels an open offer, refunding its escrowed collateral/premium to the creator's deposit vault

Parameters​

ParameterTypeDescription
offerOfferthe offer to close (must match the on-chain, content-addressed offer exactly).
operation?SignedOperationdelegated authorization by the offer's maker; the operation must have been signed over this offer's id.
accountCreator?PublicKey-

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.cancelOffer

closeOptionAccounts()​

closeOptionAccounts(option): Promise<Transaction>;

Defined in: solana-client/src/writer.ts:661

Closes every account a fully wound-down option leaves behind: the option itself, its two offers, their offer escrows, the option-scoped collateral / settlement escrows and both claim mints. Rent goes back to whoever funded each account — the offer PDAs and their escrows to their respective offer creators, everything the match created to the wallet that submitted matchOffer.

Solana-specific: this is account-rent cleanup with no counterpart in the chain-agnostic OvercastWriter, so it isn't part of that interface.

Permissionless — no party authorizes it and only the fee payer signs, hence no operation variant. The token programs reject closing a non-empty account or a mint with live supply, so the call only succeeds once every escrow is drained and both claim mints are at zero supply (burn any residual exercise claims first); until then it fails and changes nothing.

Parameters​

ParameterTypeDescription
optionMarketOptionthe option to clean up; must match the on-chain, content-addressed option exactly.

Returns​

Promise<Transaction>


closeUsedOperation()​

closeUsedOperation(usedOperation): Promise<Transaction>;

Defined in: solana-client/src/writer.ts:757

Closes a delegated operation's UsedOperation replay-protection PDA, returning its rent to the original payer. Solana-only.

Permissionless, can be called after the operation intent is expired.

Parameters​

ParameterTypeDescription
usedOperationUsedOperationthe record to close, from SolanaReader.getUsedOperation.

Returns​

Promise<Transaction>


createOffer()​

createOffer(offer, operation?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:113

creates a new offer

Parameters​

ParameterTypeDescription
offerOffer-
operation?SignedOperationdelegated authorization by the offer's creator; the operation must have been signed over this exact offer.

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.createOffer

deposit()​

deposit(deposit): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:872

deposits funds into the depositor's protocol escrow vault

The one operation that is routinely more than one transaction: where the chain gates the pull on a standing allowance (ERC-20 on EVM), the returned list is [approve, deposit] — the approval for exactly deposit.amount, omitted when the existing allowance already covers it. See TxStep.

Parameters​

ParameterTypeDescription
depositDepositParams-

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.deposit

exerciseOption()​

exerciseOption(
option,
amount,
params?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:363

params.settlement is forwarded as the instruction's remaining_accounts, which core hands verbatim to the layer's can_exercise CPI — see SolanaSettlementContext for the accounts each layer expects.

Parameters​

ParameterType
optionMarketOption
amountbigint
paramsSettlementParams<SolanaLayer>

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.exerciseOption

matchOffer()​

matchOffer(settlementOffer, collateralOffer): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:205

matches settlement and collateral offer

Parameters​

ParameterTypeDescription
settlementOfferOffer-
collateralOfferOffer-

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.matchOffer

redeemOption()​

redeemOption(
option,
amount,
params?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:470

params.settlement is not forwarded here: redemption is the option's unwind, so neither shipped layer reads accounts on can_redeem — each burns claims for a pro-rata share of the escrows, consulting no oracle. A layer whose payout split did depend on a price would need it wired to remainingAccounts exactly as exerciseOption does.

Parameters​

ParameterType
optionMarketOption
amountbigint
paramsSettlementParams<SolanaLayer>

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.redeemOption

removeAuthorizedKey()​

removeAuthorizedKey(key): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:980

revokes a key previously authorized via setAuthorizedKey, closing its signing-key record (the rent is refunded to the wallet). Operations signed with key are rejected afterwards. The wallet must sign this transaction itself.

Parameters​

ParameterTypeDescription
keyBytes32the public key to deauthorize.

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.removeAuthorizedKey

repayCollateral()​

repayCollateral(option, amount): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:825

repays previously borrowed collateral back into the option's escrow, reducing the outstanding-borrow debt tracked on the option. Permissionless — any signer holding the collateral asset may repay on the taker's behalf; the repaying wallet must sign this transaction itself.

Parameters​

ParameterTypeDescription
optionMarketOption-
amountbigintnative (smallest-unit) amount of option.details.collateralAsset to repay; must not exceed the option's current outstanding borrow.

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.repayCollateral

setAuthorizedKey()​

setAuthorizedKey(key, permissions): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:949

authorizes key to sign SignedOperations on the calling wallet's behalf. Registers a signing-key record owned by the wallet; thereafter an operator may submit that wallet's delegable calls (createCollateralOffer, createSettlementOffer, exerciseOption) by presenting an operation signed with key. The wallet must sign this transaction itself — you can only authorize keys for yourself.

Parameters​

ParameterTypeDescription
keyBytes32the public key to authorize as a signer for this wallet.
permissionsnumberthe permissions bitmap - defaults to 0xFFFF granting all permissions. Build the bitmap with buildPermissionsBitmap

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.setAuthorizedKey

withdraw()​

withdraw(withdraw, signedOperation?): Promise<Transaction[]>;

Defined in: solana-client/src/writer.ts:906

withdraws funds from the withdrawer's protocol escrow vault

Parameters​

ParameterTypeDescription
withdrawWithdrawParams-
signedOperation?SignedOperation-

Returns​

Promise<Transaction[]>

Implementation of​

OvercastWriter.withdraw