# Unstaking sOADA

Users can unstake their sOADA tokens to convert them back to OADA tokens.

The `UnstakeOadaRequest` type defines the structure for unstaking requests:

```typescript
// src/oada/actions.ts
// Type definition for sOADA unstaking requests
// Specifies the amount of sOADA tokens to unstake
type UnstakeOadaRequest = {
  amount: bigint;
};
```

The `unstakeOada` action handles the unstaking process:

```typescript
// src/oada/actions.ts
// Async thunk for unstaking sOADA tokens
// Manages the complete unstaking process including transaction creation, signing, and submission
export const unstakeOada = createAsyncThunk<
  BasicResponse<string>,
  UnstakeOadaRequest,
  {
    dispatch: AppDispatch;
    state: RootState;
    extra: Services;
    rejectValue: FailResponse;
  }
>("unstakeOada", async (request: UnstakeOadaRequest, thunkApi) => {
  // Implementation details for unstaking sOADA tokens
  const wallet = thunkApi.getState().wallet.wallet!;
  const [utxos, changeAddress] = await getWalletUtxos(wallet);

  const ownerPkh = bech32AddressToPaymentPkh(changeAddress);

  const serverRequest = {
    ownerPkh,
    returnAddressBech32: changeAddress,
    amount: request.amount,
  };

  const requestOptions = {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json;charset=UTF-8",
    },
    body: Json.stringify(serverRequest),
  };

  const rawResponse = await fetch(
    `${oadaEndpointsUrl}/unstake-oada`,
    requestOptions
  );

  const addFee = (recipe: TxRecipe) => {
    oadaFeeAddress &&
      oadaStakeFee &&
      recipe.txOuts.push({
        address: oadaFeeAddress,
        value: { lovelace: oadaStakeFee },
        datum: null,
        refScript: null,
      });
    return recipe;
  };
  const signedTxResponse = await getRecipeBuildSendTx(
    utxos,
    changeAddress,
    rawResponse,
    addFee
  );

  return signedTxResponse;
});
```

The `OadaStakeOrderView` and `OadaUnstakeOrderView` interfaces define the structure for stake and unstake orders:

```typescript
// src/oada/actions.ts
// Interface for OADA stake order information
// Contains details about pending stake orders
export type OadaStakeOrderView = {
  txOutRef: string; // Transaction reference
  oadaAmount: number; // Amount of OADA to stake
  adaAmount: number; // Amount of ADA involved
  returnAddressBech32: string; // Return address for rewards
};

// Interface for OADA unstake order information
// Contains details about pending unstake orders
export type OadaUnstakeOrderView = {
  txOutRef: string; // Transaction reference
  soadaAmount: number; // Amount of sOADA to unstake
  adaAmount: number; // Amount of ADA involved
  returnAddressBech32: string; // Return address for rewards
};
```

## Unstaking features include:

* 0.1% unstaking fee
* Dynamic conversion rate based on staking pool
* Transaction fee handling
* UTxO management
