> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bison.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Tokenization

> Tokenizing market positions on-chain

The SDK provides methods to mint positions as ERC-20 tokens directly on-chain, query token information, and manage wallet integration.

## Minting & Burning

### `executeMintFlow`

Withdraw position tokens from the exchange to your wallet as ERC-20 tokens.

```typescript theme={null}
async executeMintFlow(params: {
  walletClient: WalletClient;
  publicClient: PublicClient;
  userAddress: `0x${string}`;
  chain: string;
  marketId: string;
  side: 'yes' | 'no';
  number: string;
}): Promise<{ txHash: `0x${string}` }>
```

#### Example

```typescript theme={null}
// Withdraw 20 YES position tokens from exchange to wallet
const result = await client.executeMintFlow({
  walletClient,
  publicClient,
  userAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  chain: 'base',
  marketId: 'KXFEDDECISION-26JAN-T425',
  side: 'yes',
  number: '20.00',
});

console.log('Tokens minted! Transaction:', result.txHash);
```

### `executeBurnFlow`

Deposit position tokens from your wallet back to the exchange as tradeable positions.

```typescript theme={null}
async executeBurnFlow(params: {
  walletClient: WalletClient;
  publicClient: PublicClient;
  userAddress: `0x${string}`;
  chain: string;
  marketId: string;
  side: 'yes' | 'no';
  number: string;
}): Promise<{ txHash: `0x${string}` }>
```

#### Example

```typescript theme={null}
// Deposit 15 NO position tokens from wallet back to exchange
const result = await client.executeBurnFlow({
  walletClient,
  publicClient,
  userAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  chain: 'base',
  marketId: 'KXFEDDECISION-26JAN-T425',
  side: 'no',
  number: '15.00',
});

console.log('Tokens burned! Transaction:', result.txHash);
```

## Token Queries

### `getCreatedTokens`

Retrieve information about position tokens that have been created on-chain.

```typescript theme={null}
async getCreatedTokens(chain?: 'base' | 'bsc'): Promise<GetCreatedTokensResponse>
```

#### Parameters

<ParamField path="chain" type="string">
  Optional chain identifier (`"base"` or `"bsc"`).
</ParamField>

#### Returns

List of created position tokens with their contract addresses and market information.

#### Example

```typescript theme={null}
const { tokens } = await client.getCreatedTokens('base');

console.log('Created tokens:');
tokens.forEach(token => {
  console.log(`Market: ${token.marketId}`);
  console.log(`  Side: ${token.side}`);
  console.log(`  Token address: ${token.tokenAddress}`);
});
```

### `getPositionTokenAddress`

Get the on-chain token address for a specific market position.

```typescript theme={null}
async getPositionTokenAddress(params: {
  publicClient: PublicClient;
  chain: 'base' | 'bsc';
  marketId: string;
  side: 'yes' | 'no';
}): Promise<`0x${string}` | null>
```

#### Parameters

<ParamField path="publicClient" type="PublicClient" required>
  Viem public client for reading from the blockchain
</ParamField>

<ParamField path="chain" type="string" required>
  Chain identifier (`"base"` or `"bsc"`)
</ParamField>

<ParamField path="marketId" type="string" required>
  Market ticker
</ParamField>

<ParamField path="side" type="string" required>
  Position side: `"yes"` or `"no"`
</ParamField>

#### Returns

Token address if the position has been minted, `null` otherwise.

#### Example

```typescript theme={null}
import { createPublicClient, http } from 'viem';
import { base } from 'viem/chains';

const publicClient = createPublicClient({
  chain: base,
  transport: http(),
});

const tokenAddress = await client.getPositionTokenAddress({
  publicClient,
  chain: 'base',
  marketId: 'KXBTC-100K-DEC31',
  side: 'yes',
});

if (tokenAddress) {
  console.log('YES token address:', tokenAddress);
} else {
  console.log('Position tokens not yet minted');
}
```

### `getTokenBalance`

Get the balance of an ERC20 token for a specific address.

```typescript theme={null}
async getTokenBalance(params: {
  publicClient: PublicClient;
  tokenAddress: `0x${string}`;
  userAddress: `0x${string}`;
}): Promise<bigint>
```

#### Parameters

<ParamField path="publicClient" type="PublicClient" required>
  Viem public client for reading from the blockchain
</ParamField>

<ParamField path="tokenAddress" type="string" required>
  ERC20 token contract address
</ParamField>

<ParamField path="userAddress" type="string" required>
  Wallet address to check balance for
</ParamField>

#### Returns

Token balance as a `bigint`. Position tokens have 0 decimals.

#### Example

```typescript theme={null}
const tokenAddress = await client.getPositionTokenAddress({
  publicClient,
  chain: 'base',
  marketId: 'KXBTC-100K-DEC31',
  side: 'yes',
});

if (tokenAddress) {
  const balance = await client.getTokenBalance({
    publicClient,
    tokenAddress,
    userAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  });
  
  console.log(`Balance: ${balance} YES tokens`);
}
```

## Wallet Integration

### `addTokenToWallet`

Add a position token to the user's wallet (e.g., MetaMask).

```typescript theme={null}
async addTokenToWallet(params: {
  tokenAddress: `0x${string}`;
  marketId: string;
  side: 'yes' | 'no';
}): Promise<boolean>
```

#### Parameters

<ParamField path="tokenAddress" type="string" required>
  Position token contract address
</ParamField>

<ParamField path="marketId" type="string" required>
  Market ticker (used for token symbol)
</ParamField>

<ParamField path="side" type="string" required>
  Position side: `"yes"` or `"no"`
</ParamField>

#### Returns

`true` if the user accepted the request, `false` otherwise.

#### Example

```typescript theme={null}
const tokenAddress = await client.getPositionTokenAddress({
  publicClient,
  chain: 'base',
  marketId: 'KXBTC-100K-DEC31',
  side: 'yes',
});

if (tokenAddress) {
  try {
    const added = await client.addTokenToWallet({
      tokenAddress,
      marketId: 'KXBTC-100K-DEC31',
      side: 'yes',
    });
    
    if (added) {
      console.log('Token added to wallet successfully');
    } else {
      console.log('User declined to add token');
    }
  } catch (error) {
    console.error('Failed to add token:', error);
  }
}
```

<Note>
  This method requires a browser environment with an injected Web3 wallet (like MetaMask). It will throw an error if called in a non-browser environment or if no wallet is detected.
</Note>

## Important Notes

* Token addresses are only available after positions have been minted on-chain
* Position tokens have 0 decimals - quantities represent whole tokens
* Token symbols are automatically generated from the market ID (first 7 chars) and side
