From 01231169a74dbda0724edbb2e51d21d9991a0ebf Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Fri, 30 Aug 2024 14:15:04 +0100 Subject: [PATCH] chore: update strategy section in docs, add more tokens Signed-off-by: Gregory Hill --- docs/docs/build/bob-sdk/gateway.md | 24 ++++++++++++++++++++---- sdk/src/gateway/client.ts | 4 ++-- sdk/src/gateway/tokens.ts | 16 +++++++++++++++- sdk/test/gateway.test.ts | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/docs/build/bob-sdk/gateway.md b/docs/docs/build/bob-sdk/gateway.md index 274a0cdd..de6b4502 100644 --- a/docs/docs/build/bob-sdk/gateway.md +++ b/docs/docs/build/bob-sdk/gateway.md @@ -42,7 +42,7 @@ 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 @@ -50,7 +50,7 @@ const gatewaySDK = new GatewaySDK("bob"); // or "mainnet" 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 @@ -63,11 +63,12 @@ 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. }; @@ -75,6 +76,21 @@ const quoteParams: GatewayQuoteParams = { 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. @@ -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!)); ``` diff --git a/sdk/src/gateway/client.ts b/sdk/src/gateway/client.ts index cc2a4c57..8b78d5bd 100644 --- a/sdk/src/gateway/client.ts +++ b/sdk/src/gateway/client.ts @@ -350,7 +350,7 @@ export class GatewayApiClient { * @param includeStrategies Also include output tokens via strategies (e.g. staking or lending). * @returns {Promise} The array of token addresses. */ - async getTokenAddresses(includeStrategies: boolean = false): Promise { + async getTokenAddresses(includeStrategies: boolean = true): Promise { const response = await this.fetchGet(`${this.baseUrl}/tokens?includeStrategies=${includeStrategies}`); return response.json(); } @@ -361,7 +361,7 @@ export class GatewayApiClient { * @param includeStrategies Also include output tokens via strategies (e.g. staking or lending). * @returns {Promise} The array of tokens. */ - async getTokens(includeStrategies: boolean = false): Promise { + async getTokens(includeStrategies: boolean = true): Promise { // https://github.com/ethereum-optimism/ecosystem/blob/c6faa01455f9e846f31c0343a0be4c03cbeb2a6d/packages/op-app/src/hooks/useOPTokens.ts#L10 const tokens = await this.getTokenAddresses(includeStrategies); return tokens diff --git a/sdk/src/gateway/tokens.ts b/sdk/src/gateway/tokens.ts index 0705771a..127a747a 100644 --- a/sdk/src/gateway/tokens.ts +++ b/sdk/src/gateway/tokens.ts @@ -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 */ diff --git a/sdk/test/gateway.test.ts b/sdk/test/gateway.test.ts index 0d9a3ce5..789aa307 100644 --- a/sdk/test/gateway.test.ts +++ b/sdk/test/gateway.test.ts @@ -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]); }); });