Dynamic SDK Earn
Client-side implementation of the Dynamic Earn API — yield vaults, wallet positions, accrued rewards, and the unsigned signing payloads for depositing into, withdrawing from, and claiming rewards on a vault.
Full Example
1. Initialize the SDK
// main.dart
import 'package:dynamic_sdk/dynamic_sdk.dart';
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
DynamicSDK.init(
props: ClientProps(
environmentId: 'YOUR_ENVIRONMENT_ID',
appName: 'Your App Name',
redirectUrl: 'yourapp://',
),
);
runApp(const MyApp());
}
2. Browse vaults and read a wallet's position
import 'package:dynamic_sdk/dynamic_sdk.dart';
import 'package:dynamic_sdk_earn/dynamic_sdk_earn.dart';
Future<void> showVault(BaseWallet wallet) async {
final earn = DynamicSDK.instance.earn;
final vaults = await earn.listVaults();
final vault = await earn.getVaultDetails(vaultId: vaults.first.vaultId);
final position = await earn.getVaultPosition(
vaultId: vault.vaultId,
ownerAddress: wallet.address,
);
final rewards = await earn.getVaultRewards(
vaultId: vault.vaultId,
ownerAddress: wallet.address,
);
}
3. Deposit, withdraw, and claim rewards
Each action returns an unsigned payload; execute() signs and broadcasts it
with the wallet, sending the ERC-20 approval and waiting for it to confirm
first whenever the payload carries one.
final deposit = await earn.deposit(
vaultId: vault.vaultId,
request: EarnVaultActionRequest(
ownerAddress: wallet.address,
amount: '12.5',
),
);
final transactionHash = await earn.execute(
payload: deposit.signingPayload,
wallet: wallet,
onStepChange: (step) => print('Earn step: ${step.name}'),
);
claim() throws an EarnException with nothingToClaim == true when the
wallet has no claimable rewards on the vault.
A runnable version of this flow lives in the example app, under
example/lib/screens/profile/wallet/earn/earn_demo_screen.dart — reachable
from an EVM wallet's details screen through the "Earn Demo" button.
Models
This package holds the typed models for the Earn API:
| Model | Purpose |
|---|---|
EarnVaultSummary / EarnVaultListResponse |
Vaults available to the environment, with net APY and TVL when live data is available |
EarnVaultDetails |
A single vault, including assetDecimals and the vault contract address |
EarnVaultPosition |
A wallet's share balance and its current asset value, in raw token units |
EarnVaultReward / EarnVaultRewardsResponse |
Rewards a wallet has accrued through a vault |
EarnVaultActionRequest / EarnVaultClaimRequest |
Request bodies for deposit, withdraw and claim |
EarnVaultActionResponse / EarnSigningPayload |
The unsigned transaction (and optional ERC-20 approval) to sign and send |
EarnException |
Failure of an Earn API call, carrying the HTTP statusCode |
Amounts cross the wire as strings in two different units, so mixing them up silently deposits the wrong value:
EarnVaultActionRequest.amountis human-readable ("12.5"= 12.5 USDC).EarnVaultPosition,EarnVaultRewardandEarnEvmTransactionDataamounts are raw token units and can exceed a Dartint— parse them withBigInt.parse.
EarnSigningPayload.evmApproval is populated when the wallet has to approve
the vault to spend its tokens first; that approval must be confirmed on-chain
before evmTransaction is sent. Withdrawals redeem shares the owner already
holds, so they never carry one.