> For the complete documentation index, see [llms.txt](https://obricxyz.gitbook.io/smart/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://obricxyz.gitbook.io/smart/developer.md).

# Developer

## Contract status:

* Aptos: public
  * address: `0xc7ea756470f72ae761b7986e4ed6fd409aad183b1b2d3d2f674d979852f45c4b`
* Solana: alpha stage
  * V2 address: `EaBNtqenvVqpMoXAjYH6H91jLfVSiygczCCDDufwoVop`
  * V3 address: `BYxcSnZ1HEPGHaQ9RNaoGmzdzDBRWWnp9W553vjM7PGP`
* EVMs: private. Please talk to us for testing

## TypeScript SDKs

You can find our npm package for quoting:

* aptos package: <https://www.npmjs.com/package/obric>
  * You can look up the file under \`/dist/sdk.d.ts\` for the SDK interface that our own frontend uses for quoting and swapping.
* solana package: <https://www.npmjs.com/package/obric-solana>
  * \`/dist/sdk.d.ts\` has some basic SDK interface we use for quoting

## Pool Versions

On Aptos, we have 3 active pool versions:

* V1: a variant of PieceSwap primarily dedicated to stablecoin pairs
* V2: a proactively priced variant of constant-product, with separate X-LP token and Y-LP token
* V3: an improvement over V2 with unified LP token

On Solana, we have 2 active pool versions:

* V2
* V3

## Aptos Contract

Our Aptos contracts can be viewed [here](https://explorer.aptoslabs.com/account/0xc7ea756470f72ae761b7986e4ed6fd409aad183b1b2d3d2f674d979852f45c4b/modules/code/router?network=mainnet), under address:

```
0xc7ea756470f72ae761b7986e4ed6fd409aad183b1b2d3d2f674d979852f45c4b
```

There are several ways to integrate with our Aptos contract

* invoke entry functions under the router module
* invoke the entry functions under the modules for the corresponding pool versions
* invoke the public functions under the modules for the corresponding pool versions

### Router entry function invocation

```
    const POOL_TYPE_PIECEWISE:u8 = 3;  // V1 type
    const POOL_TYPE_SS2:u8 = 4;        // V2 type
    const POOL_TYPE_SS3_ABEL:u8 = 6;   // V3 type
    
    /*
    Execute 1 swap action
    Swaps X to Y
    so X,Y,Z are arranged in swap order, not pool order
    */
    public entry fun one_step_route_script<X, Y>(
        sender: &signer,
        first_pool_type: u8,
        first_is_x_to_y: bool, // whether first trade uses normal order
        x_in: u64,
        y_min_out: u64,
    ) {}
    
    /*
    Execute 2 swap actions back-to-back.
    Swaps X to Y to Z
    so X,Y,Z are arranged in swap order, not pool order
    */
    public entry fun two_step_route_script<X, Y, Z>(
        sender: &signer,
        first_pool_type: u8,
        first_is_x_to_y: bool, // whether first trade uses normal order
        second_pool_type: u8,
        second_is_x_to_y: bool, // whether second trade uses normal order
        x_in: u64,
        z_min_out: u64,
    ) {}
    
    /*
    Execute 3 swap actions back-to-back.
    Swaps X to Y to Z to A
    so X,Y,Z are arranged in swap order, not pool order
    */
    public entry fun three_step_route_script<X, Y, Z, A>(
        sender: &signer,
        first_pool_type: u8,
        first_is_x_to_y: bool, // whether first trade uses normal order
        second_pool_type: u8,
        second_is_x_to_y: bool, // whehter second trade uses normal order
        third_pool_type: u8,
        third_is_x_to_y: bool, // whether third trade uses normal order
        x_in: u64,
        a_min_out: u64,
    ) {}
```

### Module entry function invocation

For V1, under the `piece_swap_script` module

```
public entry fun swap_script<X, Y>(
    sender: &signer,
    x_in: u64,
    y_in: u64,
    x_min_out: u64,
    y_min_out: u64,
) {
    assert!(!(x_in > 0 && y_in > 0), E_SWAP_ONLY_ONE_IN_ALLOWED);
    assert!(!(x_min_out > 0 && y_min_out > 0), E_SWAP_ONLY_ONE_OUT_ALLOWED);
    // X to Y
    if (x_in > 0) {
        let y_out = piece_swap::swap_x_to_y<X, Y>(sender, x_in);
        assert!(y_out >= y_min_out, E_OUTPUT_LESS_THAN_MIN);
    }
    else if (y_in > 0) {
        let x_out = piece_swap::swap_y_to_x<X, Y>(sender, y_in);
        assert!(x_out >= x_min_out, E_OUTPUT_LESS_THAN_MIN);
    }
    else {
        assert!(false, E_SWAP_NONZERO_INPUT_REQUIRED);
    }
}
```

For V2, under the `ssswapScript2` module

```
public entry fun swap_x_to_y<X, Y>(user: &signer, amount: u64, min_out: u64) {
    let input_x = coin::withdraw<X>(user, amount);
    let output_y = ssswap2::swap_x_to_y<X, Y>(input_x);
    assert!(coin::value(&output_y) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
    check_and_deposit(user, output_y);
}

public entry fun swap_y_to_x<X, Y>(user: &signer, amount: u64, min_out: u64) {
    let input_y = coin::withdraw<Y>(user, amount);
    let output_x = ssswap2::swap_y_to_x<X, Y>(input_y);
    assert!(coin::value(&output_x) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
    check_and_deposit(user, output_x);
}
```

For V3, under the `ss3swapAbelScript` module

```
public entry fun swap_x_to_y<X, Y>(user: &signer, amount: u64, min_out: u64){
    let input_x = coin::withdraw<X>(user, amount);
    let output_y = ss3swapAbel::swap_x_to_y<X, Y>(input_x);
    assert!(coin::value(&output_y) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
    check_and_deposit(user, output_y);
}

public entry fun swap_y_to_x<X, Y>(user: &signer, amount: u64, min_out: u64){
    let input_y = coin::withdraw<Y>(user, amount);
    let output_x = ss3swapAbel::swap_y_to_x<X, Y>(input_y);
    assert!(coin::value(&output_x) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
    check_and_deposit(user, output_x);
}
```

### Module direct invocation

For V1, under the `piece_swap` module

```
public fun swap_x_to_y_direct<X, Y>(coin_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x_direct<X, Y>(coin_y: coin::Coin<Y>): coin::Coin<X> {}
```

For V2, under the `ssswap2` module

```
public fun swap_x_to_y<X, Y>(input_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x<X, Y>(input_y: coin::Coin<Y>): coin::Coin<X> {}
```

For V3, under the `ss3swapAbel` module

```
public fun swap_x_to_y<X, Y>(input_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x<X, Y>(input_y: coin::Coin<Y>): coin::Coin<X> {}
```

## Solana Contract

Our Solana contract is currently in alpha state. They can be found at these addresses:

```typescript
export const PROGRAM_IDS = {
  V2: new PublicKey('EaBNtqenvVqpMoXAjYH6H91jLfVSiygczCCDDufwoVop'),
  V3: new PublicKey('BYxcSnZ1HEPGHaQ9RNaoGmzdzDBRWWnp9W553vjM7PGP'),
}
```

Our anchor contract IDL can be found [here](https://www.npmjs.com/package/obric-solana?activeTab=code).

**Warning**: our solana contracts are in alpha status. We may in the future migrate all liquidity to a non-upgradable deployment under a new address.


---

# 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 dynamically by asking a question.

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

```
GET https://obricxyz.gitbook.io/smart/developer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
