brava-ts-client v0.0.72
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.
- Get into root of Brava Client project.
- Run
npm run build
- Run
npm link
. - Get into root of the project you want import Brava Client to.
- Run
npm link brava-ts-client
. - 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
- Instantiate Action object with right arguments
import { FluidSupplyAction } from 'brava-ts-client';
// ...
const fluidSupplyAction = new FluidSupplyAction(
'TOKEN_ADDRESS',
'1000000000',
'FROM_ADDRESS',
'TO_ADDRESS'
);
- Run
encodeArgs()
on the action object to get a string payload
const fluidSupplyPayload = fluidSupplyAction.encodeArgs();
- 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
- 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'
);
- 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]);
- Run
encodeSequence()
on Sequence object to get transaction payload
const sequencePayload = sequence.encodeSequence();
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago