Skip to main content
POST
/
markets
/
creditbook
/
swap_collateral
Swap collateral
curl --request POST \
  --url https://tars.loopscale.com/v1/markets/creditbook/swap_collateral \
  --header 'Content-Type: application/json' \
  --data '
{
  "loan": "<string>",
  "withdrawCollateral": [
    {
      "amount": 123,
      "collateralMint": "<string>"
    }
  ],
  "depositCollateral": [
    {
      "collateralAmount": 123,
      "collateralAssetData": {
        "Spl": {
          "mint": "<string>"
        }
      }
    }
  ],
  "cpiIxs": [
    {
      "programId": "<string>",
      "accounts": [
        {
          "pubkey": "<string>",
          "isSigner": true,
          "isWritable": true
        }
      ],
      "data": "<string>"
    }
  ],
  "cpiLuts": [
    "<string>"
  ],
  "cpiSigners": [
    "<string>"
  ]
}
'
import requests

url = "https://tars.loopscale.com/v1/markets/creditbook/swap_collateral"

payload = {
    "loan": "<string>",
    "withdrawCollateral": [
        {
            "amount": 123,
            "collateralMint": "<string>"
        }
    ],
    "depositCollateral": [
        {
            "collateralAmount": 123,
            "collateralAssetData": { "Spl": { "mint": "<string>" } }
        }
    ],
    "cpiIxs": [
        {
            "programId": "<string>",
            "accounts": [
                {
                    "pubkey": "<string>",
                    "isSigner": True,
                    "isWritable": True
                }
            ],
            "data": "<string>"
        }
    ],
    "cpiLuts": ["<string>"],
    "cpiSigners": ["<string>"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    loan: '<string>',
    withdrawCollateral: [{amount: 123, collateralMint: '<string>'}],
    depositCollateral: [{collateralAmount: 123, collateralAssetData: {Spl: {mint: '<string>'}}}],
    cpiIxs: [
      {
        programId: '<string>',
        accounts: [{pubkey: '<string>', isSigner: true, isWritable: true}],
        data: '<string>'
      }
    ],
    cpiLuts: ['<string>'],
    cpiSigners: ['<string>']
  })
};

fetch('https://tars.loopscale.com/v1/markets/creditbook/swap_collateral', 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://tars.loopscale.com/v1/markets/creditbook/swap_collateral",
  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([
    'loan' => '<string>',
    'withdrawCollateral' => [
        [
                'amount' => 123,
                'collateralMint' => '<string>'
        ]
    ],
    'depositCollateral' => [
        [
                'collateralAmount' => 123,
                'collateralAssetData' => [
                                'Spl' => [
                                                                'mint' => '<string>'
                                ]
                ]
        ]
    ],
    'cpiIxs' => [
        [
                'programId' => '<string>',
                'accounts' => [
                                [
                                                                'pubkey' => '<string>',
                                                                'isSigner' => true,
                                                                'isWritable' => true
                                ]
                ],
                'data' => '<string>'
        ]
    ],
    'cpiLuts' => [
        '<string>'
    ],
    'cpiSigners' => [
        '<string>'
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json"
  ],
]);

$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://tars.loopscale.com/v1/markets/creditbook/swap_collateral"

	payload := strings.NewReader("{\n  \"loan\": \"<string>\",\n  \"withdrawCollateral\": [\n    {\n      \"amount\": 123,\n      \"collateralMint\": \"<string>\"\n    }\n  ],\n  \"depositCollateral\": [\n    {\n      \"collateralAmount\": 123,\n      \"collateralAssetData\": {\n        \"Spl\": {\n          \"mint\": \"<string>\"\n        }\n      }\n    }\n  ],\n  \"cpiIxs\": [\n    {\n      \"programId\": \"<string>\",\n      \"accounts\": [\n        {\n          \"pubkey\": \"<string>\",\n          \"isSigner\": true,\n          \"isWritable\": true\n        }\n      ],\n      \"data\": \"<string>\"\n    }\n  ],\n  \"cpiLuts\": [\n    \"<string>\"\n  ],\n  \"cpiSigners\": [\n    \"<string>\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	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://tars.loopscale.com/v1/markets/creditbook/swap_collateral")
  .header("Content-Type", "application/json")
  .body("{\n  \"loan\": \"<string>\",\n  \"withdrawCollateral\": [\n    {\n      \"amount\": 123,\n      \"collateralMint\": \"<string>\"\n    }\n  ],\n  \"depositCollateral\": [\n    {\n      \"collateralAmount\": 123,\n      \"collateralAssetData\": {\n        \"Spl\": {\n          \"mint\": \"<string>\"\n        }\n      }\n    }\n  ],\n  \"cpiIxs\": [\n    {\n      \"programId\": \"<string>\",\n      \"accounts\": [\n        {\n          \"pubkey\": \"<string>\",\n          \"isSigner\": true,\n          \"isWritable\": true\n        }\n      ],\n      \"data\": \"<string>\"\n    }\n  ],\n  \"cpiLuts\": [\n    \"<string>\"\n  ],\n  \"cpiSigners\": [\n    \"<string>\"\n  ]\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://tars.loopscale.com/v1/markets/creditbook/swap_collateral")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"loan\": \"<string>\",\n  \"withdrawCollateral\": [\n    {\n      \"amount\": 123,\n      \"collateralMint\": \"<string>\"\n    }\n  ],\n  \"depositCollateral\": [\n    {\n      \"collateralAmount\": 123,\n      \"collateralAssetData\": {\n        \"Spl\": {\n          \"mint\": \"<string>\"\n        }\n      }\n    }\n  ],\n  \"cpiIxs\": [\n    {\n      \"programId\": \"<string>\",\n      \"accounts\": [\n        {\n          \"pubkey\": \"<string>\",\n          \"isSigner\": true,\n          \"isWritable\": true\n        }\n      ],\n      \"data\": \"<string>\"\n    }\n  ],\n  \"cpiLuts\": [\n    \"<string>\"\n  ],\n  \"cpiSigners\": [\n    \"<string>\"\n  ]\n}"

response = http.request(request)
puts response.read_body
{
  "transactions": [
    {
      "message": "<string>",
      "signatures": [
        {
          "publicKey": "<string>",
          "signature": "<string>"
        }
      ]
    }
  ],
  "expectedLoanInfo": {
    "loan": {
      "address": "<string>"
    }
  }
}
"Something went wrong: You have an error in your SQL syntax."
"Failed to deserialize the JSON body into the target type: missing field `mints` at line 1 column 1."

Body

application/json
loan
string
required

Loan address to modify

withdrawCollateral
object[]
required

Amount and mint of the collateral to withdraw

depositCollateral
object[]
required

Collateral to deposit after intermediate steps

cpiIxs
object[]
required

Instructions to run between withdrawal and re-deposit

cpiLuts
string[]
required

Optional Address Lookup Tables for the transaction

cpiSigners
string[]
required

Optional keypairs required to initialize accounts

Response

Single versioned transaction message and signatures

transactions
object[]
expectedLoanInfo
object

Loan post transaction state used for verification