0.0.72 • Published 4 months ago

brava-ts-client v0.0.72

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

Brava TypeScript Client

Overview

Client provides high level functions to interact with Brava Smart Contracts and use Safe Smart Account.

Token-Based Deposit Flow (New in v0.0.67)

Starting with version 0.0.67, the client supports a token-based deposit flow that preserves exact token amounts throughout the portfolio update process. This provides more precise control when working with deposits of different tokens.

Key Features

  • Preserves exact token amounts in deposit actions
  • Only converts to USD internally for calculations and validations
  • Maintains the original token amounts in final transactions
  • Provides backward compatibility with the existing USD-based API

Token-Based API Functions

Use these new functions (with the WithTokenAmounts suffix) when you want to work directly with token amounts:

// Execute a portfolio update with exact token amounts
await executePortfolioUpdateWithTokenAmounts(
  signer,
  tokenDeposits, // Balance[] with exact token amounts
  withdrawalAsset,
  currentPortfolio,
  targetPortfolio,
  covers,
  safeAddr,
  chainId
);

// Get a transaction for a portfolio update with exact token amounts
const tx = await getPortfolioUpdateTxWithTokenAmounts(
  tokenDeposits, // Balance[] with exact token amounts
  withdrawalAsset,
  currentPortfolio,
  targetPortfolio,
  covers,
  userAddr,
  safeAddr,
  chainId
);

// Create a transaction payload for portfolio updates with token amounts
const payload = await executePortfolioUpdatePayloadWithTokenAmounts(
  tokenDeposits, // Balance[] with exact token amounts
  withdrawalAsset,
  currentPortfolio,
  targetPortfolio,
  covers,
  userAddr,
  safeAddr,
  chainId
);

Usage in development

Use of npm link is adviced until Client is deployed to remote registry.

  1. Get into root of Brava Client project.
  2. Run npm run build
  3. Run npm link.
  4. Get into root of the project you want import Brava Client to.
  5. Run npm link brava-ts-client.
  6. You can now import and use Brava Client tools using standard import syntax, e.g.

import { deploySafe, executeSafeTransaction } from "brava-ts-client";

Creating Action payload

  1. Instantiate Action object with right arguments
import { FluidSupplyAction } from 'brava-ts-client';

// ...

const fluidSupplyAction = new FluidSupplyAction(
  'TOKEN_ADDRESS',
  '1000000000',
  'FROM_ADDRESS',
  'TO_ADDRESS'
);
  1. Run encodeArgs() on the action object to get a string payload
const fluidSupplyPayload = fluidSupplyAction.encodeArgs();
  1. Now you can use returned payload to execute safe transaction
import { executeSafeTransaction, SafeOperation } from 'brava-ts-client';
const txResponse = await executeSafeTransaction(
  safeAddress,
  actionContractAddress,
  0,
  fluidSupplyPayload,
  SafeOperation.DelegateCall,
  signer
);

Creating Sequence payload

  1. Instantiate action objects
const fluidSupply = new FluidSupplyAction(
  'TOKEN_ADDRESS',
  '100000000',
  'FROM_ADDRESS',
  'TO_ADDRESS'
);
const yearnSupply = new YearnSupplyAction(
  'TOKEN_ADDRESS',
  '100000000',
  'FROM_ADDRESS',
  'TO_ADDRESS'
);
  1. Instantiate Sequence object. Sequence will execute actions in the same order as passed to sequence constructor
const sequence = new Sequence([fluidSupply, yearnSupply], [0, 0, 0, 0], [0, 0, 0, 0]);
  1. Run encodeSequence() on Sequence object to get transaction payload
const sequencePayload = sequence.encodeSequence();
0.0.70

4 months ago

0.0.71

4 months ago

0.0.72

4 months ago

0.0.67

4 months ago

0.0.68

4 months ago

0.0.69

4 months ago

0.0.62

5 months ago

0.0.63

5 months ago

0.0.64

5 months ago

0.0.65

5 months ago

0.0.66

5 months ago

0.0.60

5 months ago

0.0.61

5 months ago

0.0.59

5 months ago

0.0.54

5 months ago

0.0.55

5 months ago

0.0.56

5 months ago

0.0.57

5 months ago

0.0.51

5 months ago

0.0.52

5 months ago

0.0.53

5 months ago

0.0.50

5 months ago

0.0.48

5 months ago

0.0.49

5 months ago

0.0.46

5 months ago

0.0.47

5 months ago

0.0.40

6 months ago

0.0.41

6 months ago

0.0.42

6 months ago

0.0.43

6 months ago

0.0.44

5 months ago

0.0.45

5 months ago

0.0.37

6 months ago

0.0.38

6 months ago

0.0.39

6 months ago

0.0.24

6 months ago

0.0.25

6 months ago

0.0.30

6 months ago

0.0.31

6 months ago

0.0.32

6 months ago

0.0.33

6 months ago

0.0.34

6 months ago

0.0.35

6 months ago

0.0.36

6 months ago

0.0.26

6 months ago

0.0.27

6 months ago

0.0.28

6 months ago

0.0.29

6 months ago

0.0.20

6 months ago

0.0.21

6 months ago

0.0.22

6 months ago

0.0.23

6 months ago

0.0.18

6 months ago

0.0.19

6 months ago

0.0.13

7 months ago

0.0.14

7 months ago

0.0.15

6 months ago

0.0.16

6 months ago

0.0.17

6 months ago

0.0.11

7 months ago

0.0.12

7 months ago

0.0.10

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.3

8 months ago

0.0.4

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago