Skip to content

Commit

Permalink
Merge pull request #328 from bob-collective/refactor/strategies
Browse files Browse the repository at this point in the history
refactor: strategies
  • Loading branch information
gregdhill committed Aug 30, 2024
2 parents f4ee664 + 749b34d commit f27dc59
Show file tree
Hide file tree
Showing 20 changed files with 959 additions and 670 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
5 changes: 5 additions & 0 deletions sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"useTabs": false,
"printWidth": 120
}
1 change: 1 addition & 0 deletions sdk/examples/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function swapBtcForToken(evmAddress: string) {

const quoteParams: GatewayQuoteParams = {
fromChain: "Bitcoin",
fromToken: "BTC",
fromUserAddress: "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
toChain: "BOB",
toUserAddress: evmAddress,
Expand Down
Loading

0 comments on commit f27dc59

Please sign in to comment.