> For the complete documentation index, see [llms.txt](https://docs.gage.cash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gage.cash/developers/sdk-puts.md).

# Puts with gage-sdk

Puts with gage-sdk: a loan of a stock token against USDG that gains as the stock falls, its loss stopping at the margin you put in.

Where a stock token's lending generation names a put router, such as NVDA's, a put is a loan of that stock token against USDG: your USDG margin and the USDG the loan's payout buys are pledged together, `size` times the margin in all. It gains as the stock falls, and its loss stops at the margin you put in. There is no liquidation: the loan is never closed early because a price moves; if it is not repaid by the end of its term, the lenders keep the pledge and nothing else is taken.

## Find the asset

```ts
const { lendAssets = [] } = await gage.capabilities();
const asset = lendAssets.find((a) => a.symbol.toLowerCase() === symbol.toLowerCase());
if (!asset || !("putRouter" in asset)) throw new Error(`gage offers no put on ${symbol} now`);
```

A stock token offers puts when `capabilities().lendAssets` names its `putRouter`, beside the `loopRouter` a put opens through and its own core and terms.

## Open

```ts
const quote = await gage.putQuote({ lendAsset: asset.token, margin: parseUnits(marginUsdg, 6).toString(), size, term: term.seconds, wallet: signer.address });
const { action: _, ...put } = quote.prepare;
const opened = await gage.run({ action: "put_open", ...put }, signer);
```

* `margin` is the USDG you put in, raw (6 decimals): the most the put can lose. `size` is 1.1 to 10, the whole pledge over the margin: 4 pledges the margin and three times it, bought with the loan.
* The quote answers the pledge, the purchase, the loan and its repayment in the stock token, its fixed cost for the term (`costBps`, of the loan), the most the purchase may cost, and a `prepare` object.
* `put_open` approves the margin and the purchase's most exactly, in one transaction, and is refused above `maxCostBps` or beyond what the pledge supports (`SIZE_TOO_HIGH`).

## Close, roll over, roll over by itself

```ts
const closed = await gage.run({ action: "put_close", loanId, engine, ...(minBack ? { minBack } : {}) }, signer);
```

* **`put_close`** repays a running put out of its own pledge: the pledge buys the repayment back and the rest comes back to you, in one transaction, never returning less than `minBack`. A pledge that cannot buy the repayment back now cannot close it (`PLEDGE_SHORT`): repay it in the stock token with `reclaim`, or leave it to end.
* **`put_roll`** rolls a put into a new loan of the same size on the same pledge; your USDG buys what the new payout leaves short.
* **`put_auto_roll`** leaves a put to roll over by itself: gage's keeper rolls it in its last hours, at most `maxCost` each, buying each top-up with at most `maxSpend` of your USDG, up to four times. It leaves standing approvals to the put router, until you withdraw them in your wallet. **`put_cancel_auto_roll`** ends it.

Each put action names the loan's core (`engine`), the stock token's own from `capabilities().lendAssets`. While a put router is paused, its actions are refused (`PUT_PAUSED`) and the loan can still be repaid.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gage.cash/developers/sdk-puts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
