Skip to content

Commit

Permalink
chore: update strategy section in docs, add more tokens
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Aug 30, 2024
1 parent e2e6639 commit 0123116
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
24 changes: 20 additions & 4 deletions docs/docs/build/bob-sdk/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Import the `GatewaySDK` class from `@gobob/bob-sdk` and create an instance of it
```ts title="/src/utils/gateway.ts"
import { GatewayQuoteParams, GatewaySDK } from "@gobob/bob-sdk";

const gatewaySDK = new GatewaySDK("bob"); // or "mainnet"
const gatewaySDK = new GatewaySDK("bob"); // or "bob-sepolia"
```

### Get Available Tokens

Returns an array of available output tokens for you to offer the user. Typically rendered as a drop-down menu. See [our SDK's source code](https://github.com/bob-collective/bob/blob/9c52341033af1ccbe388e64ef97a23bf6c07ccc7/sdk/src/gateway/tokens.ts#L8) for type information.

```ts
const outputTokensWithInfo = await gatewaySDK.getTokensInfo();
const outputTokens = await gatewaySDK.getTokens();
```

### Get a Quote
Expand All @@ -63,18 +63,34 @@ We recommend rendering `quote.fee` and [its other fields](https://github.com/bob

```ts
const quoteParams: GatewayQuoteParams = {
fromToken: "BTC",
fromChain: "Bitcoin",
fromUserAddress: "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
toChain: "BOB",
toUserAddress: "0x2D2E86236a5bC1c8a5e5499C517E17Fb88Dbc18c",
toToken: "tBTC",
toToken: "tBTC", // or e.g. "SolvBTC"
amount: 10000000, // 0.1 BTC
gasRefill: 10000, // 0.0001 BTC. The amount of BTC to swap for ETH for tx fees.
};

const quote = await gatewaySDK.getQuote(quoteParams);
```

#### Get available staking or lending contracts

The SDK will handle automatically when the `toToken` has a fungible ERC20 token, but sometimes there is no representation. In that case we can list the available integrations and specify that in the quote.

```ts
const strategies = await gatewaySDK.getStrategies();
const strategy = strategies.find(contract => contract.integration.name === "pell-wbtc")!;
const quoteParamsStaking: GatewayQuoteParams = {
...quoteParams,
toChain: strategy.chain.chainId,
toToken: strategy.inputToken.symbol, // "wbtc"
strategyAddress: strategy.address,
};
```

### Start the Order

This locks in the quote, placing a hold on the LP's funds. Pass the same `quoteParams` as before and the `quote` returned from the previous step.
Expand All @@ -97,7 +113,7 @@ We recommend using our [sats-wagmi](./sats-wagmi.md) package to interact with yo
import { base64 } from "@scure/base";
import { Transaction } from "@scure/btc-signer";

// NOTE: It is up to your implementation to sign the PSBT here!
// SIGN THIS!
const tx = Transaction.fromPSBT(base64.decode(psbtBase64!));
```

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/gateway/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class GatewayApiClient {
* @param includeStrategies Also include output tokens via strategies (e.g. staking or lending).
* @returns {Promise<EvmAddress[]>} The array of token addresses.
*/
async getTokenAddresses(includeStrategies: boolean = false): Promise<EvmAddress[]> {
async getTokenAddresses(includeStrategies: boolean = true): Promise<EvmAddress[]> {
const response = await this.fetchGet(`${this.baseUrl}/tokens?includeStrategies=${includeStrategies}`);
return response.json();
}
Expand All @@ -361,7 +361,7 @@ export class GatewayApiClient {
* @param includeStrategies Also include output tokens via strategies (e.g. staking or lending).
* @returns {Promise<Token[]>} The array of tokens.
*/
async getTokens(includeStrategies: boolean = false): Promise<Token[]> {
async getTokens(includeStrategies: boolean = true): Promise<Token[]> {
// https://github.com/ethereum-optimism/ecosystem/blob/c6faa01455f9e846f31c0343a0be4c03cbeb2a6d/packages/op-app/src/hooks/useOPTokens.ts#L10
const tokens = await this.getTokenAddresses(includeStrategies);
return tokens
Expand Down
16 changes: 15 additions & 1 deletion sdk/src/gateway/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ const TOKENS = [
decimals: 18,
bob: "",
bobSepolia: "0xc4229678b65e2D9384FDf96F2E5D512d6eeC0C77",
}
},
{
name: "Solv BTC",
symbol: "SolvBTC",
decimals: 18,
bob: "0x541FD749419CA806a8bc7da8ac23D346f2dF8B77",
bobSepolia: "",
},
{
name: "uniBTC",
symbol: "uniBTC",
decimals: 8,
bob: "0x236f8c0a61dA474dB21B693fB2ea7AAB0c803894",
bobSepolia: "",
},
];

/** @description Tokens supported on BOB and BOB Sepolia */
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ describe("Gateway Tests", () => {
.reply(200, [ZeroAddress]);

const gatewaySDK = new GatewaySDK("bob");
assert.deepEqual(await gatewaySDK.getTokenAddresses(), [ZeroAddress]);
assert.deepEqual(await gatewaySDK.getTokenAddresses(false), [ZeroAddress]);
});
});

0 comments on commit 0123116

Please sign in to comment.