from compass_api_sdk import CompassAPI, models
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.risk_yield.risk_yield_swap(owner="0x06A9aF046187895AcFc7258450B15397CAc67400", token_in="USDG", token_out="WETH", amount_in="100", chain=models.RiskYieldSwapRequestChain.ROBINHOOD, gas_sponsorship=False, preview=False, slippage_pct="0.5", deadline_seconds=300)
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.riskYield.riskYieldSwap({
owner: "0x06A9aF046187895AcFc7258450B15397CAc67400",
chain: "robinhood",
tokenIn: "USDG",
tokenOut: "WETH",
amountIn: "100",
});
console.log(result);
}
run();curl --request POST \
--url https://api.compasslabs.ai/v2/risk_yield/swap \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"owner": "0x06A9aF046187895AcFc7258450B15397CAc67400",
"chain": "robinhood",
"token_in": "USDG",
"token_out": "WETH",
"amount_in": "100"
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
owner: '0x06A9aF046187895AcFc7258450B15397CAc67400',
chain: 'robinhood',
token_in: 'USDG',
token_out: 'WETH',
amount_in: '100'
})
};
fetch('https://api.compasslabs.ai/v2/risk_yield/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/risk_yield/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'owner' => '0x06A9aF046187895AcFc7258450B15397CAc67400',
'chain' => 'robinhood',
'token_in' => 'USDG',
'token_out' => 'WETH',
'amount_in' => '100'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/risk_yield/swap"
payload := strings.NewReader("{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.compasslabs.ai/v2/risk_yield/swap")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/risk_yield/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}"
response = http.request(request)
puts response.read_body{
"transaction": {
"chainId": "0x2105",
"data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d",
"from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c",
"gas": "0x7a120",
"maxFeePerGas": "0x59682f00",
"maxPriorityFeePerGas": "0x3b9aca00",
"nonce": "0x5",
"to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
"value": "0x0"
},
"swap": {
"token_in": "<string>",
"token_out": "<string>",
"amount_in": "<string>",
"amount_out_quoted": "<string>",
"amount_out_min": "<string>",
"price_impact_pct": "<string>",
"pool_fee_ppm": 123
},
"steps": [
{
"kind": "APPROVE",
"description": "<string>",
"contract": "<string>",
"token": "<string>",
"amount": "<string>"
}
],
"simulation": {
"ok": true,
"error": "<string>",
"gas_used": 123
},
"warnings": [
"<string>"
]
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Swap tokens
Trade one token for another from inside your Risk Yield Account.
Mostly used to reach the ratio a range needs before opening a position: a range fixes the proportion of the two assets, and a caller holding one of them has to swap to it.
There is no aggregator on this chain, so the route is a Uniswap v3 pool. The API quotes every enabled fee tier and takes whichever returns the most — a 1% pool with depth beats a 0.05% pool with none, which here is the common case rather than the corner one.
The transaction is simulated before it is returned. A failing simulation is a 422 rather than something to sign: on this chain a token may tax transfers, block an address or be paused, and none of that is visible until the call is actually made.
from compass_api_sdk import CompassAPI, models
with CompassAPI(
api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:
res = compass_api.risk_yield.risk_yield_swap(owner="0x06A9aF046187895AcFc7258450B15397CAc67400", token_in="USDG", token_out="WETH", amount_in="100", chain=models.RiskYieldSwapRequestChain.ROBINHOOD, gas_sponsorship=False, preview=False, slippage_pct="0.5", deadline_seconds=300)
# Handle response
print(res)import { CompassApiSDK } from "@compass-labs/api-sdk";
const compassApiSDK = new CompassApiSDK({
apiKeyAuth: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await compassApiSDK.riskYield.riskYieldSwap({
owner: "0x06A9aF046187895AcFc7258450B15397CAc67400",
chain: "robinhood",
tokenIn: "USDG",
tokenOut: "WETH",
amountIn: "100",
});
console.log(result);
}
run();curl --request POST \
--url https://api.compasslabs.ai/v2/risk_yield/swap \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"owner": "0x06A9aF046187895AcFc7258450B15397CAc67400",
"chain": "robinhood",
"token_in": "USDG",
"token_out": "WETH",
"amount_in": "100"
}
'const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
owner: '0x06A9aF046187895AcFc7258450B15397CAc67400',
chain: 'robinhood',
token_in: 'USDG',
token_out: 'WETH',
amount_in: '100'
})
};
fetch('https://api.compasslabs.ai/v2/risk_yield/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.compasslabs.ai/v2/risk_yield/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'owner' => '0x06A9aF046187895AcFc7258450B15397CAc67400',
'chain' => 'robinhood',
'token_in' => 'USDG',
'token_out' => 'WETH',
'amount_in' => '100'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.compasslabs.ai/v2/risk_yield/swap"
payload := strings.NewReader("{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.compasslabs.ai/v2/risk_yield/swap")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.compasslabs.ai/v2/risk_yield/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"owner\": \"0x06A9aF046187895AcFc7258450B15397CAc67400\",\n \"chain\": \"robinhood\",\n \"token_in\": \"USDG\",\n \"token_out\": \"WETH\",\n \"amount_in\": \"100\"\n}"
response = http.request(request)
puts response.read_body{
"transaction": {
"chainId": "0x2105",
"data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d",
"from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c",
"gas": "0x7a120",
"maxFeePerGas": "0x59682f00",
"maxPriorityFeePerGas": "0x3b9aca00",
"nonce": "0x5",
"to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
"value": "0x0"
},
"swap": {
"token_in": "<string>",
"token_out": "<string>",
"amount_in": "<string>",
"amount_out_quoted": "<string>",
"amount_out_min": "<string>",
"price_impact_pct": "<string>",
"pool_fee_ppm": 123
},
"steps": [
{
"kind": "APPROVE",
"description": "<string>",
"contract": "<string>",
"token": "<string>",
"amount": "<string>"
}
],
"simulation": {
"ok": true,
"error": "<string>",
"gas_used": 123
},
"warnings": [
"<string>"
]
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Body
Swap one token for another from inside the Risk Yield Account.
There is no aggregator on this chain, so the route is a Uniswap v3 pool. The API quotes every enabled fee tier and takes whichever returns the most — a 1% pool with depth beats a 0.05% pool with none, and here that is the common case.
The wallet that owns the Risk Yield Account.
"0x06A9aF046187895AcFc7258450B15397CAc67400"
What you are spending.
"USDC"
"WETH"
"0xA0b86a33E6441ccF30EE5DdEF1E9b652C91ac1c8"
What you want.
"USDC"
"WETH"
"0xA0b86a33E6441ccF30EE5DdEF1E9b652C91ac1c8"
In token units, not wei.
x > 0"100"
Risk Yield is available on Robinhood Chain only.
robinhood "robinhood"
Return EIP-712 typed data for the owner to sign instead of a transaction, so a sponsor can broadcast it.
Return the plan and its simulation without building a transaction. Nothing is signed and nothing can be broadcast.
How far the executed amounts may fall short of the quote before the transaction reverts. Memecoin pools move between the quote and the block that includes the transaction.
0 < x <= 10How long the transaction stays valid once built.
30 <= x <= 3600Pin the route to one fee tier. Leave unset to let the API pick the tier that returns the most.
0 <= x <= 1000000Response
Successful Response
Null when preview was set, or when the plan is a no-op.
Show child attributes
Show child attributes
{ "chainId": "0x2105", "data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d", "from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c", "gas": "0x7a120", "maxFeePerGas": "0x59682f00", "maxPriorityFeePerGas": "0x3b9aca00", "nonce": "0x5", "to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67", "value": "0x0" }
The swap leg of an entry or a rebalance.
Show child attributes
Show child attributes
What the single transaction does, in order.
Show child attributes
Show child attributes
The result of executing this against current state. A failure here is the only warning you get about a token that taxes transfers, blocks an address, or is paused.
Show child attributes
Show child attributes
Was this page helpful?