Overview Last updated: 2019-09-12

Defire offers a set of API endpoints and libraries to access the open financial system (also known as DeFi). This documentation is designed to help customers integrate with Defire, both by providing the necessary context to understand the blockchain financial instruments, and by giving technical guidance on how to work with the Defire API. We’ve tried to make this documentation user-friendly, but if you have any questions, please email us at info@defire.io

NOTE: As we are in beta, this documentation can be updated.

What is DeFi?

Decentralized finance, or DeFi, are a range of common financial instruments that run on the blockchain. These instruments can be executed without the necessity of any middlemen and ensure that the individual is the sole custodian of their assets at all times. It is worth mentioning that these DeFi products are non-custodial but use centralized price feeds and centrally administer platform developments & updates. That is why there are different levels of DeFi and some people prefer to call it open finance.

What can I do?

With DeFire system you can:

  • Control access: Create portfolios, roles, users and permission to secure blockchain transactions.
  • Pay: Make a payment to another account in a reliable and efficient way.
  • Trade: Trade any crypto asset without the necessity of a middleman.
  • Margin Trade: Trade on margin opening short or leveraged positions.
  • Lend: Deposit funds to continuously earn market best interest.
  • Borrow: Borrow many assets directly using crypto holdings as collateral.
  • Track: View metrics and track your funds and transactions over time.

Smart contracts

We developed a serie of smart contracts that handle portfolios, permissions and metatransactions. They also act as secure proxies to access other financial smart contracts functions and keep everything trustless.


Portfolio

Manages deposits, withdraw, multisig and metatransactions for each portfolio. Each account has one portfolio

Authorizer

Verifies signatures and salts, permissions, whitelisted contracts and limits for each transaction.

PayHandler

Handles all payment functionality (pay, schedule pay, swap & pay).

TradeHandler

Handles all trading functionality (market orders, limit orders, margin trade).

LendHandler

Handles all lending functionality and interests earned.

BorrowHandler

Handles all borrowing functionality and interests paid.

TokenManager

Handles creation of tokens (ERC20, ERC721).

IUniswap, ICompound, IDxDy, ..

Interfaces to each external financial smart contract.

GasHandler

Handles gas payment for metatransactions.

Scheduler

Allows to execute transactions in the future.

BatchHandler

Handles batching of transactions.

FeeHandler

Handle service fees, discounts codes, referrals, etc.

Permissions

Manages the available permissions and roles.

SafeMath

Wrappers over Solidity's arithmetic operations with added overflow.

DeFi protocolos

Defire make use of the most prominent DeFi protocols and smart contracts. Here there is a list of some of them:

Even though DeFi tools are being built on many blockchains, we are focusing now on Ethereum but we will include more blockchains in the future.

Quickstart

Sometimes a good way to understand how an API works is to start right away coding an example. Here we offer one where the developer will be able to create a portfolio (wallet), deposit an asset to it, lend the total amount, earn interests and withdraw everything.

1- Create porfolio

To start you need an Ethereum wallet and its the private key. If you do not have one, check here how to create it.

Make sure that your wallet has at least 0.05 ETH

Execute this code to create a portfolio and fund it:


// Require the Defire library with a private key.
const defire = require('defire')('f702ab818a8c6...86c1c064');

// Create a portfolio. Need ETH on the account.
const portfolio = await defire.portfolio.create({
	number: 0, // optional, default 0
	description: 'main portfolio', // optional
	deposit: [{ 
		amount: 200,
		currency: 'eth'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}]
});

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio' \
	-d '{tx}'

2- Lend your asset

Now that you have created a portfolio, you are ready to start lending it.

Execute this code to lend ETH:


// Require the Defire library with a private key.
const defire = require('defire')('f702ab818a8c6...86c1c064');

//Lend.
const lending = await defire.lend.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	description: 'My first lend'
});
	

	curl -X POST \
		-H 'Accept: application/json' \
		-H 'Content-Type: application/json' \
		'https://api.defire.io/v1/lend' \
		-d '{tx}'
	

3- Query your portfolio

At any time you can check your portfolio and how much have ETH you earned on iterests.


// Returns porfolio by id
const portfolio = await defire.portfolio.get('6598be5d-febc-4d17-bcde-c8199d88218d');
	

	curl -X GET \
		-H 'Accept: application/json' \
		-H 'Content-Type: application/json' \
		'https://api.defire.io/v1/porfolio/6598be5d-febc-4d17-bcde-c8199d88218d' 
	

4- Withdraw

Finally, you can withdraw the total amount of ETH from your portfolio.


// Withdraw from a portfolio.
const portfolio = await defire.portfolio.withdraw({
	id: portfolio.id, 
	withdraw: [{ 
	amount: 200,
	currency: 'eth'
	}],
	to: ' 0x128a4b0a2e961d2304cc1eca867d9a1806a67f47'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/porfolio/6598be5d-febc-4d17-bcde-c8199d88218d/withdraw' \
	-d '{tx}'
	

And that's it!

API

Defire API allow developers to access directly the decentralized financial tools of Ethereum. It abstracts all the complexity to create a blockchain transaction, pay gas for it, listen to events, detect if successfully executed or not. This API is always available and auto-scales, but more importantly it is secured by our proxy smart contracts. This means that developers are always in control of their funds.

Public and private keys

When you make an Ethereum wallet on any platform, you are receiving a private key tied to a public address. It just might not come in the form that you're expecting it to be. Keystore files hold your private key encrypted inside of them, while mnemonic phrases are used as a generation method for multiple private keys.

Want to install a wallet?

Want to learn more about Ethereum wallets?

Want to learn more about securely storing funds and managing private keys?

Environments

https://test-api.defire.io (Sandbox).

https://api.defire.io (Production).

Status

We provide comprehensive status information about the health of our API to ensure you have the context you need to debug issues and better serve your users. It will be available soon at status.defire.io. You can also get status information visiting the management Dashboard. Defire system status reports uptime and incidents for our two API environments: Sandbox and Production.

Portfolio


Create Porfolio


	// Require the Defire library with a private key.
	const defire = require('defire')('f702ab818a8c6...86c1c064');
	
	// Create a portfolio. Need ETH on the account.
	const portfolio = await defire.portfolio.create({
		number: 0, // optional, default 0
		description: 'main portfolio', // optional
		deposit: [{ 
			amount: 200,
			currency: 'eth'
		}],
		auth: [{
			address: ' 0x165349b4c304B127489237B71ce060e382b75859',
			permissions: ['deposit', 'lend']
		}]
	});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Update Porfolio


//Update porfolio name and permissions
const portfolio = await defire.portfolio.update({
	id: portfolio.id, 
	description: 'my main portfolio', 
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend', 'trade']
	}]
	});
	

curl -X PUT \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio/[id] ' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Deposit into Porfolio


// Deposit into a portfolio
const portfolio = await defire.portfolio.deposit({
	id: portfolio.id, 
	deposit: [{ 
	amount: 180,
	currency: 'dai'
	}]
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio/[id]/deposit ' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Withdraw Porfolio


// Withdraw from a portfolio.
const portfolio = await defire.portfolio.withdraw({
	id: portfolio.id, 
	withdraw: [{ 
	amount: 200,
	currency: 'eth'
	}],
	to: ' 0x128a4b0a2e961d2304cc1eca867d9a1806a67f47'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio/[id]/withdraw ' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get Porfolio


// Returns porfolio by id
const portfolio = await defire.portfolio.get('6598be5d-febc-4d17-bcde-c8199d88218d');

	

curl -X PUT \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio/[id] ' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get All Porfolios


// Returns all porfolio 
const portfolios = await defire.portfolio.getAll();

	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/portfolio' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

{
	id: '6598be5d-febc-4d17-bcde-c8199d88218d',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	number: 0, 
	description: 'main portfolio', 
	balances: [{ 
		amount: 200,
		currency: 'eth'
	},{ 
		amount: 1200,
		currency: 'dai'
	}],
	auth: [{
		address: ' 0x165349b4c304B127489237B71ce060e382b75859',
		permissions: ['deposit', 'lend']
	}],
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Payments


Make a Payment


//Make a payment
const payment = await defire.payment.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 80,
	currency: 'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My first payment'
});
				
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Schedule a payment


//Schedule a payment
const scheduledPayment = await defire.payment.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get a Payment


const payment = await defire.payment.get('5f931f82-6b06-4792-968b-9e3bfd6ad51a');
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get all payments


const payments = await defire.payment.getAll();
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Cancel a scheduled payment


//Cancel a scheduled payment
await defire.payment.cancel(scheduledPayment.id);
	

curl -X DEL \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment[id]' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Create a swap payment


// Create a swap payment.
const scheduledPayment = await defire.payment.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My third payment'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/payment' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Payment 
payment = {
	id: '5f931f82-6b06-4792-968b-9e3bfd6ad51a',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	amount: 12,
	currency: 'dai',
	pattern:  '* * 5 * * *', //schedule pattern
	swapFrom:  'eth',
	to: ' 0x165349b4c304B127489237B71ce060e382b75859',
	description: 'My second payment'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Trading


Create a market order


//Create a market order.
const trade = await defire.trade.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	protocol: "all",
	sourceAsset: "dai", 
	destinationAsset: "eth",
	sourceAmount: 1000, // Market fill if no destination amount
	minFillPercent: 40,
	description: 'My first trade'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/trdae' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Trade 
trade = {
  id: '755ae1e3-225c-4889-b2db-b14a456f55cc',
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My first trade'
  executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
  updatedAt: 1569196800030,
  createdAt: 1569196800030
}
	

Create a limit order


		//Create a limit order. Need to set 'destinationAmount'
		const trade = await defire.trade.create({
			portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
			protocol: "uniswap", 
			sourceAsset: "dai", 
			destinationAsset: "eth",
			sourceAmount: 1000, 
			destinationAmount: 5,
			minFillPercent: 40,
			description: 'My second trade'
		});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/trade' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Trade 
trade = {
  id: '755ae1e3-225c-4889-b2db-b14a456f55cc',
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My first trade'
  executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
  updatedAt: 1569196800030,
  createdAt: 1569196800030
}
	

Cancel a trade


//Create a limit order. Need to set 'destinationAmount'
const trade = await defire.trade.create({
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My second trade'
});
	

curl -X DEL \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/trade' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Trade 
trade = {
  id: '755ae1e3-225c-4889-b2db-b14a456f55cc',
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My first trade'
  executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
  updatedAt: 1569196800030,
  createdAt: 1569196800030
}
	

Create a market order


//Get a trade
const trade = await defire.trade.get('755ae1e3-225c-4889-b2db-b14a456f55cc');
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/trdae/[id]' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Trade 
trade = {
  id: '755ae1e3-225c-4889-b2db-b14a456f55cc',
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My first trade'
  executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
  updatedAt: 1569196800030,
  createdAt: 1569196800030
}
	

Get all trades


//Get trades
const trades = await defire.trade.getAll();
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/trdae' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Trade 
trade = {
  id: '755ae1e3-225c-4889-b2db-b14a456f55cc',
  portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
  protocol: "uniswap", 
  sourceAsset: "dai", 
  destinationAsset: "eth",
  sourceAmount: 1000, 
  destinationAmount: 5,
  minFillPercent: 40,
  description: 'My first trade'
  executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
  updatedAt: 1569196800030,
  createdAt: 1569196800030
}
	

Lending


Lend


//Lend.
const lending = await defire.lend.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	description: 'My first lend'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/lend' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Lending 
lending = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	interestObtained: 1.5,
	description: 'My first lend'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Redeem


//Redeem.
await defire.lend.redeem(lending.id);
	

curl -X DEL \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/lend' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Lending 
lending = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	interestObtained: 1.5,
	description: 'My first lend'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get a lending


//Get a lending
const lending = await defire.lend.get('fe09e5ef-c645-42c3-9bf9-fcdf91bd8031');
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/lend/[id]' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Lending 
lending = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	interestObtained: 1.5,
	description: 'My first lend'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get all lendings


//Get lendings
const lendings = await defire.lend.getAll();
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/lend' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Lending 
lending = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'compound',
	amount: 2000,
	currency: 'dai',
	interestObtained: 1.5,
	description: 'My first lend'
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Borrowing


Borrow


// Borrow.
const borrowing = await defire.borrow.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'dxdy',
	amount: 450,
	currency: 'dai',
	description: 'My first borrow'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/borrow' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Borrowing 
borrowing = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'dxdy',
	amount: 450,
	currency: 'dai',
	description: 'My first borrow',
	interests: 1.2,
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Repay borrowing


//Repay borrowing.
const reborrowing = await defire.borrow.redeem(borrowing.id);

	

curl -X DEL \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/borrow/[id]' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Borrowing 
borrowing = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'dxdy',
	amount: 450,
	currency: 'dai',
	description: 'My first borrow',
	interests: 1.2,
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get a borrowing


//Get a borrowing
const borrowing = await defire.borrow.get('fe09e5ef-c645-42c3-9bf9-fcdf91bd8031');

	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/borrow/' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Borrowing 
borrowing = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'dxdy',
	amount: 450,
	currency: 'dai',
	description: 'My first borrow',
	interests: 1.2,
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Get all borrowing


//Get borrowings
const borrowings = await defire.borrow.getAll();

	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/borrow' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Borrowing 
borrowing = {
	id: 'fe09e5ef-c645-42c3-9bf9-fcdf91bd8031',
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	source: 'dxdy',
	amount: 450,
	currency: 'dai',
	description: 'My first borrow',
	interests: 1.2,
	executor: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Token


Create a Token


// Create a token and move it to a portfolio.
const token = await defire.token.create({
	portfolioId: '6598be5d-febc-4d17-bcde-c8199d88218d',
	type: defire.token.types.ERC20,
	totalSupply: 2000000,
	decimals: 10,
	name: 'MyToken',
	symbol: 'MTKN',
	description: 'My first token'
});
	

curl -X POST \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/token' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

	//Token 
	token = {
		id: '825576d9-fb25-40d5-821a-814b72dc8812',
		owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
		type: defire.token.types.ERC20,
		totalSupply: 2000000,
		decimals: 10,
		name: 'MyToken',
		symbol: 'MTKN',
		description: 'My first token',
		updatedAt: 1569196800030,
		createdAt: 1569196800030
	}
	

Get a token


//Get a token
const token = await defire.token.get('825576d9-fb25-40d5-821a-814b72dc8812');

	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/token/[id]' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

	//Token 
	token = {
		id: '825576d9-fb25-40d5-821a-814b72dc8812',
		owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
		type: defire.token.types.ERC20,
		totalSupply: 2000000,
		decimals: 10,
		name: 'MyToken',
		symbol: 'MTKN',
		description: 'My first token',
		updatedAt: 1569196800030,
		createdAt: 1569196800030
	}
	

Get all tokens


//Get tokens
const tokens = await defire.token.getAll();
	

curl -X GET \
	-H 'Accept: application/json' \
	-H 'Content-Type: application/json' \
	'https://api.defire.io/v1/token/' \
	-d '{tx}'
	

Responses
200 successful operation ApiResponse 400 Invalid values 401 Invalid signature 403 You are not authorized 404 Portfolio not found

//Token 
token = {
	id: '825576d9-fb25-40d5-821a-814b72dc8812',
	owner: ' 0xDFd72e05eC74187c074592996b63f9f6517D5C8A',
	type: defire.token.types.ERC20,
	totalSupply: 2000000,
	decimals: 10,
	name: 'MyToken',
	symbol: 'MTKN',
	description: 'My first token',
	updatedAt: 1569196800030,
	createdAt: 1569196800030
}
	

Smart Contracts

We are still on beta and our smart contracts are currently being tested and audited. Once ready, smart contracts will be explained here and their addresses published.