We're hiring!
See open positions

We make
DeFi accessible
through
Python

From data-sourcing over backtesting strategies to analytics — we cover your infrastructure needs in one simple Python package. No Solidity required.

Backed by

Trusted by


Introducing
Dojo
By Compass Labs

Python Interface

Only Python.Only Python.

A Python interface for DeFi, enabling users to build and simulate strategies and contracts entirely on-premises before real-world deployment.


Dojo

Protocol Integration

Bridging the gap.Bridging the gap.

Dojo is successfully integrated with Uniswap, Aave and, soon, Perpetual Protocol; and continually expanding across more protocols and Layer 2s.


Data accessibility

Decipher history.Decipher history.

Access on-chain data of any smart contract and any historic block for data ingestion and strategy evaluation.

1,800
1,820
1,840
1,860
1,880
1,900

python logoSolidity
1

// SPDX-License-Identifier: MIT

2

pragma solidity ^0.8.0;

3

import "@aave/protocol-v2/contracts/interfaces/IFlashLoanReceiver.sol";

4

import "@aave/protocol-v2/contracts/interfaces/ILendingPool.sol";

5

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

6

contract FlashLoanReceiver is IFlashLoanReceiver {

7

ILendingPool public lendingPool;

8

constructor(address _lendingPool) {

9

lendingPool = ILendingPool(_lendingPool);

10

}

11

function executeOperation(

12

address[] memory assets,

13

uint256[] memory amounts,

14

uint256[] memory premiums,

15

address initiator,

16

bytes memory params

17

) external override {

18

(address recipient) = abi.decode(params, (address));

19

for (uint256 i = 0; i < assets.length; i++) {

20

IERC20(assets[i]).transfer(recipient, amounts[i]);

21

}

22

for (uint256 i = 0; i < assets.length; i++) {

23

uint256 amountOwing = amounts[i] + premiums[i];

24

IERC20(assets[i]).approve(address(lendingPool), amountOwing);

25

}

26

}

27

function initiateFlashLoan(address[] memory assets, uint256[] memory amounts, bytes memory params) external {

28

lendingPool.flashLoan(address(this), assets, amounts, params);

29

}

30

}

python logoSolidity
1

const axios = require('axios');

2

3

async function fetchHistoricPrices(token0, token1, startTime, endTime) {

4

const query = `

5

{

6

pair(id: "${token0}-${token1}") {

7

token0 {

8

symbol

9

}

10

token1 {

11

symbol

12

}

13

token0Price

14

token1Price

15

token0PriceHistory(first: 1000, where: { timestamp_gte: ${startTime}, timestamp_lte: ${endTime} }, orderBy: timestamp, orderDirection: asc) {

16

price

17

timestamp

18

}

19

token1PriceHistory(first: 1000, where: { timestamp_gte: ${startTime}, timestamp_lte: ${endTime} }, orderBy: timestamp, orderDirection: asc) {

20

price

21

timestamp

22

}

23

}

24

}

25

`;

26

27

try {

28

const response = await axios.post('https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2', {

29

query: query

30

});

31

return response.data.data.pair;

32

} catch (error) {

33

console.error('Error fetching historic prices:', error);

34

return null;

35

}

36

}

37

38

// Example usage

39

const token0 = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'; // Token0 address (e.g., ETH)

40

const token1 = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; // Token1 address (e.g., DAI)

41

const startTime = Math.floor((Date.now() - 7 * 24 * 60 * 60 * 1000) / 1000); // 7 days ago in Unix timestamp

42

const endTime = Math.floor(Date.now() / 1000); // Current time in Unix timestamp

43

44

fetchHistoricPrices(token0, token1, startTime, endTime)

45

.then(pairData => {

46

console.log(pairData);

47

})

48

.catch(error => {

49

console.error('Error:', error);

50

});

python logo
1

env = UniV3Env(

2

data_range = (2021-06-01, 2023-03-04)

3

)

4

5

env.load_data()

6

7

policy = [

8

AAVEv3FlashLoan(amount = 1_000_000),

9

Univ3Trade(pool = 'USDC-WETH', amount = 1_000_000),

10

Balv2Trade(pool = 'USDC-WETH', amount = 'max'),

11

AAVEv3FlashLoanRepay(amount = 1_000_000),

12

]

13

14

testnet.backtest_run(env, [policy])

15

16

sandbox.live_run(private_key = '0x0..', env, [policy])

Python Interface

Smart contracts, simplified.Smart contracts, simplified.

A Python interface for DeFi. You don't need to run a node. No data-sourcing required. Only Python.


Simulation platform

Practice before you preach.Practice before you preach.

Test and train strategies and smart contracts through dojo’s agent-based simulator to simulate transactions at the EVM smart contract level.

Dojo by Compass Labs

    Examples