Developer reference
Call Flaset contracts directly. Deals and invoices are signed using EIP-712, settled in a single transaction.
On this page
Addresses
| Contract | By | Address |
|---|---|---|
| FlasetDeals | Flaset | Explorer for 0x2c5224c5e456B9E1CeE0E6F1ffF8106Cd383e449 |
| FlasetRegistry | Flaset | Explorer for 0xb41a45AEE32806061DDe1341249170BE3559FB8c |
| Sablier Lockup | Others | Explorer for 0x548129a58bC230549DF7F9e33f27E77F6779ff0f |
| Morpho Blue | Others | Explorer for 0x9D53d5E3bd5E8d4Cbfa6DB1ca238AEA02E651010 |
| Uniswap v3 factory | Others | Explorer for 0x1f7d7550B1b028f7571E69A784071F0205FD2EfA |
| Uniswap SwapRouter02 | Others | Explorer for 0xCaf681a66D020601342297493863E78C959E5cb2 |
| USDG | Others | Explorer for 0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168 |
| WETH | Others | Explorer for 0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73 |
ABI and signing
curl "https://sourcify.dev/server/v2/contract/4663/CONTRACT_ADDRESS?fields=abi"- Domains: Flashdeal and Flash checkout.. Both are tied to
chainIdandverifyingContract, so settlement is only possible on the chain and contract the signature was created for. - Signatures: ECDSA is checked first, followed by ERC-1271. EIP-7702 accounts sign with their own key, while contract accounts validate signatures through ERC-1271.
Sign and settle a deal
- Create the deal with a random 256-bit nonce and set
maxFeeusingquoteFee(payAmount). - For a specific buyer, both parties sign the same message. For whitelisted or open deals, the seller signs with
buyer: zeroAddressand the buyer signs with their own address. - The buyer approves FlasetDeals to spend
payAmountof the payment token. The seller approvesassetAmountof the asset token. - Anyone can call
settle(deal, sellerSig, buyerSig, proof)with the buyer’s address. Use[]forproofunless the deal is whitelisted. The contract checks the terms, signatures and fee againstmaxFee. It marks the deal as used before moving any tokens and verifies the vesting stream (StreamMismatchif it does not match). If any check or step fails, the entire transaction reverts. - Read
streamIdfrom theDealSettledevent. Value 0 means no vesting. Before settlement, the seller can callcancel(deal), even while the contract is paused. Cancelling a whitelisted or open deal cancels it for all potential buyers.
const domain = { name: 'FLASET Deals', version: '3', chainId: 4663, verifyingContract: DEALS_V3_ADDRESS };
const types = { Deal: ('address seller,address buyer,uint8 buyerMode,bytes32 buyersRoot,address asset,uint256 assetAmount,'
+ 'address payToken,uint256 payAmount,uint16 vestingBps,uint8 vestingShape,uint64 vestingStart,uint64 vestingCliff,'
+ 'uint64 vestingDuration,uint16 vestingSteps,bool vestingTransferable,uint256 maxFee,uint64 deadline,uint256 nonce')
.split(',').map((f) => { const [type, name] = f.split(' '); return { name, type }; }) };
const signature = await wallet.signTypedData({ account, domain, types, primaryType: 'Deal', message: deal });The deal
Deal(
address seller,
address buyer,
uint8 buyerMode,
bytes32 buyersRoot,
address asset,
uint256 assetAmount,
address payToken,
uint256 payAmount,
uint16 vestingBps,
uint8 vestingShape,
uint64 vestingStart,
uint64 vestingCliff,
uint64 vestingDuration,
uint16 vestingSteps,
bool vestingTransferable,
uint256 maxFee,
uint64 deadline,
uint256 nonce
)
bytes32 constant DEAL_TYPEHASH = 0x73bea4f4da274a40dd7bc89c902ddd32f15786baf0631151876b26f6b1857c51;Vesting shapes
Show codeHide codeThe five shapes: the fields each takes, its Sablier stream (app name) and what unlocks.
0 Linear D > 0
Lockup Linear, start to start + D (linear)
unlocks continuously to the end
1 Cliff 0 < C < D
Lockup Linear, cliff at start + C (cliff)
V × C / D at the cliff, then linearly
2 Steps D > 0, 2 ≤ N ≤ 48, D divisible by N
Lockup Linear in steps of D / N (linearStepper)
N equal unlocks, the first at D / N
3 Monthly D = 0, 2 ≤ N ≤ 48, V ≥ N
Lockup Tranched, N tranches (tranchedMonthly)
V / N rounded down on the start's day and time each following month (UTC),
the remainder in the last; a missing day becomes the month's last
4 All at once D > 0
Lockup Tranched, one tranche (tranchedTimelock)
all of V at start + DWho may buy
- One wallet (mode 0): Only the specified wallet can settle the deal.
- Whitelist (mode 1) or anyone (mode 2): The seller signs with
buyerset to the address. The first eligible wallet to settle gets the deal. Whitelisted buyers must provide a Merkle proof. Only the seller can cancel.
keccak256(bytes.concat(keccak256(abi.encode(wallet))))Pay an invoice
- Get the fee using
quoteFee(invoice.amount). - Build the payment steps. For a direct payment, use
{ tokenIn: payToken, amountOut: amount + fee, maxAmountIn: amount + fee, adapter: 0, poolFee: 0 }. - Approve exactly
maxAmountInfor each step and callpay(invoice, merchantSig, legs, fee, deadline). The function is protected against reentrancy, marks the invoice as paid and records the fee before moving any tokens. - Use
digestin theCheckoutPaidevent to identify the payment. Anyone can pay an invoice, and multiple invoices can share the sameinvoiceId.
Invoice(
address merchant,
address payToken,
uint256 amount,
bytes32 invoiceId,
uint64 deadline
)
bytes32 constant INVOICE_TYPEHASH = 0x9bb298f1843cecddd4c5aa114fcfbecc7737f06b545839364a4af47009eb284d;Show codeHide codeThe Leg struct: one token in, the pay token out, the payer’s bound.
struct Leg {
address tokenIn;
uint256 amountOut;
uint256 maxAmountIn;
address adapter;
uint24 poolFee;
}Functions
Show codeHide codeIts 8 functions: settle, cancel, hashDeal, quoteFee, consumed and the reads.
function settle(Deal d, bytes sellerSig, bytes buyerSig, bytes32[] proof)
returns (bytes32 digest)
function cancel(Deal d) returns (bytes32 digest)
function hashDeal(Deal d) view returns (bytes32)
function domainSeparator() view returns (bytes32)
function quoteFee(uint256 payAmount) view returns (uint256)
function consumed(bytes32 digest) view returns (bool)
function lockup() view returns (address)
function registry() view returns (address)Show codeHide codeIts 11 functions: pay, cancel, hashInvoice, paid, cancelled and the reads.
function pay(Invoice inv, bytes merchantSig, Leg[] legs, uint256 maxFee, uint64 deadline)
returns (bytes32 digest, uint256 fee)
function cancel(Invoice inv) returns (bytes32 digest)
function hashInvoice(Invoice inv) view returns (bytes32)
function domainSeparator() view returns (bytes32)
function quoteFee(uint256 amount) view returns (uint256)
function paid(bytes32 digest) view returns (bool)
function cancelled(bytes32 digest) view returns (bool)
function feesCollected(address token) view returns (uint256)
function feeBps() view returns (uint16)
function feeRecipient() view returns (address)
function pauser() view returns (address)Show codeHide codeLimits and the five moves: refinance, swapCollateral, leverage, deleverage, moveSupply.
struct Limits {
uint256 maxFee;
uint256 minHealth;
uint64 deadline;
}
function refinance(MarketParams from, MarketParams to, uint256 maxBorrow,
Limits lim, MorphoAuth auth) returns (Receipt r)
function swapCollateral(MarketParams from, MarketParams to, uint256 minCollateralOut,
uint24 poolFee, uint256 maxBorrow, Limits lim, MorphoAuth auth) returns (Receipt r)
function leverage(MarketParams market, uint256 ownCollateral, uint256 flashAssets,
uint256 minCollateralOut, uint24 poolFee, Limits lim, MorphoAuth auth) returns (Receipt r)
function deleverage(MarketParams market, uint256 repayAssets, uint256 maxCollateralIn,
uint24 poolFee, bool close, Limits lim, MorphoAuth auth) returns (Receipt r)
function moveSupply(MarketParams from, MarketParams to,
Limits lim, MorphoAuth auth) returns (Receipt r)
function healthFactor(MarketParams m, address user) view returns (uint256)
function quoteFee(uint256 amount) view returns (uint256)Show codeHide codeHow health is worked out, and the reads.
maxBorrow = collateral * oracle.price() / 1e36 * lltv
debt = borrowShares in assets
health = maxBorrow * 1e18 / debt
healthFactor(MarketParams m, address user), quoteFee(uint256 amount), feesCollected(address token)
isMarketAllowed(bytes32 id), registry.hasFlag(token, flag), registry.txCap(token)
dailyCap(address token), dailyUsed(address token, uint256 day)
swapper(), paused()Show codeHide codeexecute with its Limits, Step and Outcome and the reads.
struct Limits {
uint256 maxFee;
uint256 minReturn;
uint256 minHealth;
uint64 deadline;
}
function execute(address flashToken, uint256 flashAssets, Step[] steps,
Limits lim, MorphoAuth auth) returns (Outcome r)
struct Step {
Op op;
address token;
address tokenOut;
address venue;
uint24 poolFee;
MarketParams market;
uint256 amount;
uint256 minOut;
}
struct Outcome {
uint256 fee;
uint256 returned;
StepResult[] steps;
TokenAmount[] left;
}
healthFactor(MarketParams m, address user)
quoteFee(uint256 flashAssets, uint256 profit)
isVenue(address), isMarketAllowed(bytes32)
dailyCap(address token), dailyUsed(address token, uint256 day)
feesCollected(address token)Show codeHide codeMorpho’s Authorization and MorphoAuth.
Authorization(
address authorizer,
address authorized,
bool isAuthorized,
uint256 nonce,
uint256 deadline
)
struct MorphoAuth {
bool withSig;
Authorization grant;
Signature grantSig;
Authorization revoke;
Signature revokeSig;
}Events
Show codeHide codeThe events of the four contracts and the Receipt struct.
event DealSettled(bytes32 indexed digest, address indexed seller, address indexed buyer,
address asset, uint256 assetAmount, uint256 vestedAmount, uint256 streamId,
address payToken, uint256 payAmount, uint256 fee)
event DealCancelled(bytes32 indexed digest, address indexed by)
event CheckoutPaid(bytes32 indexed digest, address indexed merchant, address indexed payer,
address payToken, uint256 amount, uint256 fee, uint256 refunded, bytes32 invoiceId)
event LegSettled(bytes32 indexed digest, address indexed tokenIn, address adapter,
uint256 amountIn, uint256 amountOut)
event InvoiceCancelled(bytes32 indexed digest, address indexed merchant)
event CreditSettled(Kind indexed kind, address indexed user, bytes32 indexed fromMarket, Receipt receipt)
struct Receipt {
bytes32 toMarket;
uint256 flashAssets;
uint256 repaid;
uint256 borrowed;
uint256 removed;
uint256 added;
uint256 swapIn;
uint256 swapOut;
uint256 fee;
uint256 healthAfter;
}
event SetSettled(address indexed user, address indexed flashToken, uint256 flashAssets,
uint256 fee, uint256 returned, uint256 steps)
event StepDone(address indexed user, uint256 indexed index, Op op, address tokenIn,
uint256 amountIn, address tokenOut, uint256 amountOut, address venue, bytes32 marketId)
event Returned(address indexed user, address indexed token, uint256 amount)Errors
The protocol uses named custom errors. Flash Builder reports failed steps through StepFailed(index, reason), while Morpho returns a revert string.