# 流动性质押

## afSUI SDK

```typescript
const staking = new Aftermath("TESTNET").Staking();
```

## 交易

### Staking Positions

```typescript
const stakingPositions = await staking.getStakingPositions({
    walletAddress: "0x..",
});
```

### Stake

```typescript
const tx = await staking.getStakeTransaction({
    walletAddress: "0x..",
    suiStakeAmount: 1_000_000_000n, // 1 Sui
    validatorAddress: "0x..",
});
```

### Unstake

```typescript
const tx = await staking.getUnstakeTransaction({
    walletAddress: "0x..",
    afSuiUnstakeAmount: 1_000_000_000n, // 1 AfSui
    isAtomic: true,
});
```

## 检查

### Staked SUI TVL

```typescript
const suiTvl = await staking.getSuiTvl();

console.log(suiTvl);
// 9_540_200_000n
```

### afSUI Exchange Rate

```typescript
// (1 SUI = x afSUI)
const afSuiExchangeRate = await staking.getAfSuiExchangeRate();
console.log(afSuiExchangeRate);
// 1.000149000231
```

## afSUI API

```typescript
const testnetStakingAddresses = {
    staking: {
        packages: {
            events:
"0x58e6bdd081ae6035141871a1c7cdf82895e944a8b7673f78d22e370a07cbf99b",
            lsd:
"0x58e6bdd081ae6035141871a1c7cdf82895e944a8b7673f78d22e370a07cbf99b",
            afsui:
"0x5783fa2298e7301a1c7f99ce45d4a207478fbf3003eca9482ae823d6f6c7cd60",
        },
        objects: {
            stakedSuiVault:
"0x690f36f9c5249b0c4c9b3efdf8a2864c750a8021037360e3b7bedc9ceafb277f",
            safe:
"0x091686a693e86929f91ef539d867fae334a33d124bc2c204dcb3b53dd9016501",
            treasury:
"0xf3d41534e43ecf36da8657b48350a09a3e50eeb2ce61f8ceb80e6d2f85828bc0",
            referralVault: 
"0x8d357115058f22976cd01c5415116d9aca806d1ded37eecd75d87978f404e927",
            validatorConfigsTable:
"0xc9b9c0f1115793a24e0551609e51daa5ffe2b11429d12b46fdf8a3b0bfc0e908",
         },
     },
 },
 
 const afApi = new AftermathApi(
     new SuiClient({
         transport: new SuiHTTPTransport({
             url: "https://testnet.mainnet.sui.io",
         }),
     }),
     testnetStakingAddresses,
     new IndexerCaller("TESTNET"),
 );
 
 const stakingApi = afApi.Staking();
```

## Transaction Command Examples

```typescript
const stakingApi = afApi.Staking();

const suiCoin = await afApi.Coin().fetchCoinWithAmountTx({
    walletAddress: "0x...",
    coinType: "0x02::sui::SUI",
    coinAmount: BigInt(1_423_837_387), // ~1.4 SUI
});

const afSuiCoin = stakingApi.stakeTx({
    tx,
    suiCoin,
    validatorAddress: "0x...",
});

stakingApi.atomicUnstakeTx({
    tx,
    afSuiCoin,
    withTransfer: true
});
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ch-docs.aftermath.finance/kai-fa-ren-yuan/liu-dong-xing-zhi-ya.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
