The documents
The three app-data documents of a Safe on a chain, and their upload to CoW's order book. Index: README.md. Before this page:
configuration.md. After it: running.md.
What they are
Every order of the Safe carries the hash of a document in its appData. The order book resolves the hash to the document, reads its hooks and its partner fees, and settles accordingly. The sweep module builds the three documents of a Safe on a chain and emits them, as exact bytes, when it applies a configuration (ConfigurationApplied). The SDK builds the same bytes, so the hash an order carries is the hash of the document the integrator uploads.
| Document | Used by | Holds |
|---|---|---|
source |
the sales on a source chain |
the burn as the post-hook (the bridge module's burn(safe), with the gas the record declares for it), and the integrator's partner-fee entry when its rate is above zero; with none, no partnerFee key
|
target |
the sales on the target chain |
the integrator's partner-fee entry when its rate is above zero (with none, an empty metadata), and no hook
|
carrier |
the carrier slice: when a chain that is on holds only USDC, the Safe sells a small part of it for the chain's wrapped native token, and the same trade sends the rest through Circle | the burn hook, and no partnerFee key |
The integrator's entry comes from the configuration the owners signed. The service takes no fee and the SDK writes no partner fee of its own: the only entry a document can carry is the integrator's, and with none set there is no
partnerFee key at all. With no integrator fee the source document is therefore the carrier document's bytes, and their hashes are equal. The bytes are canonical JSON, with the keys sorted at every level and no whitespace. Each document is run through a port of the order book's own checks before it is handed out. A document the port refuses is
documents-invalid and is never uploaded. That code is a fault of the SDK or of the record, not of the integrator's input. The port follows the order book's checks as of the SDK release; the order book can still refuse a document the port passes.
Build them
const set = await sdk.buildDocuments({ chainId: 8453, safe, integrator: build.configuration.integrator, // the entry the owners signed appliedFrom: applyBlock, // optional: the block of the apply});
final set = await sdk.buildDocuments(DocumentsInput( chainId: 8453, safe: safe, integrator: build.configuration.integrator, appliedFrom: applyBlock,));
Each DocumentSet holds the three documents with their text, their hash (the Keccak-256 of the exact bytes, which is the order's
appData) and their size. Building reads nothing. With appliedFrom, the SDK reads the latest
ConfigurationApplied of the Safe from that block on the chain and holds the chain's bytes equal to the built ones. It refuses
documents-differ when they are not (the owners signed another entry, or a later configuration was applied), and
documents-not-applied when the chain emitted no event since that block.
Upload them
uploadDocuments sends PUT /api/v1/app_data/{hash} of each document to the order book the integrator configured for the set's chain. It takes one set or several. Every set is rebuilt and each chain's order book is looked up before the first request, so a set that is not the built one (invalid-input) or a chain with no order book URL (invalid-config) fails with nothing sent. The answer must be the document's own hash.
const result = await sdk.uploadDocuments([setBase, setArbitrum]);
final result = await sdk.uploadDocuments([setBase, setArbitrum]);
Without the upload there are no orders: an order whose document the order book does not know waits, and nothing is sold or sent. So upload before the configuration is applied, for each chain the Safe uses, and again after a new configuration that changes the integrator's entry. An upload that fails is a named refusal with the order book's reason:
order-book-refused (the order book answered with an error), order-book-unreachable
(it could not be reached, or it is rate limiting or failing, and the upload can be repeated) and invalid-order-book-answer. When some requests fail and others succeed, one error lists every document that failed and every document that was stored. Uploading again is harmless.
UploadResult.uploaded lists each stored document with its hash and whether the order book created it (created).
The order book's default limit for a document is APP_DATA_MAX_BYTES in packages/sdk-ts/src/bootstrap.ts. The port of the order book's checks holds every document to it. The bootstrap order's document carries a whole
apply call data and can reach it (setup.md).
What this touches
The upload is one of the two calls of the SDK that write to a service. It sends the document, which names the Safe's address, the burn hook and the integrator's fee recipient, if any, to the order book the integrator chose (network.md).