Einen Safe einrichten
Diese Seite zeigt, wie das SDK konfiguriert wird, wie es die Adresse eines Safes berechnet und warum es vorhandene Safes ablehnt. Danach folgt die Reihenfolge der Schritte: Der Safe wird zuerst auf der Ziel-Chain deployt und konfiguriert, erst dann auf den Quell-Chains. Für Token, die auf Ethereum schon vor dem Safe an seiner Adresse ankommen, beschreibt sie die Bootstrap-Order.
Der Leitfaden unten steht auf Englisch, weil wir ihn unverändert aus dem Repository der SDKs übernehmen.
Setting up a Safe
How an integrator configures the SDK, computes the Safe's address, checks a Safe, and puts the Safe on its chains with the target chain first. Index:
README.md. The steps that follow, in order: the configuration and the signatures (configuration.md), the documents (documents.md), then the applying (running.md).
Configure the SDK
The SDK takes everything it talks to from the integrator. It has no default RPC, order book or attestation endpoint, no key, and no endpoint of ours.
createSdk checks the configuration (resolveConfig in config.ts). It refuses the following with
invalid-config, listing every problem:
- an option it does not know (an option that looks like a key, a secret or a mnemonic is named as one the SDK will not hold);
- a chain that is not one of the six;
- a chain with no RPC set;
-
a URL that is not
https(plainhttpis accepted for a node on this machine), or that carries user info.
An error message never repeats a URL, because an endpoint can carry its key in the path.
TypeScript:
import { createSdk } from 'auto-sweep-sdk-ts';const sdk = createSdk({ chains: { 8453: { rpc: { url: baseRpcUrl }, orderBook: { url: baseOrderBookUrl } }, 42161: { rpc: { transport: myViemTransport }, orderBook: { url: arbitrumOrderBookUrl } }, }, iris: { url: irisUrl }, // only for recovery and the status of transfers integrator: { recipient: myFeeRecipient, volumeBps: 30 }, // optional: the fee entry this app is set up with; the description does not warn about it fetch: myFetch, // optional: the platform's fetch when left out});
Dart takes the RPC of a chain as a URL (RpcConfig(url: ...), reached through package:http) or as a function (RpcConfig(transport: ...), an
RpcTransport the integrator already has, such as an injected provider). A chain gives one of the two: both, or neither, is
invalid-config. The URL follows the same rules as in TypeScript. fetch is optional: left out, the order book and Iris calls go through a fetch on
package:http, and a function passed as fetch replaces it.
import 'package:auto_sweep/auto_sweep.dart';final sdk = createSdk(SdkConfig( chains: { 8453: ChainConfig( rpc: RpcConfig(url: baseRpcUrl), orderBook: EndpointConfig(url: baseOrderBookUrl), ), 42161: ChainConfig( rpc: RpcConfig(transport: (method, params) => myJsonRpc(method, params)), orderBook: EndpointConfig(url: arbitrumOrderBookUrl), ), }, iris: EndpointConfig(url: irisUrl), integrator: IntegratorFee(recipient: myFeeRecipient, volumeBps: 30), // optional: the fee entry this app is set up with; the description does not warn about it fetch: (request) => myFetch(request), // optional: a fetch on package:http when left out));
What each setting is used for is in network.md. The order book of a chain is needed where the integrator uploads documents there, and on Ethereum for the bootstrap order. Iris is needed for recovery and for the status of transfers, and for nothing else.
createSdk also checks the chain before it returns a transaction from buildDeploy,
buildBootstrapOrder, buildApply, buildArm, buildBurn,
buildFallbackBurn, buildOwnerChange and buildMigration: a contract of the release record whose code on the chain is not the record's is refused as
code-hash-mismatch, with the contract named. verifyChain(chainId) makes the same check on request.
The chains
The six chains of version 1 (shared/chains.json). A Safe names one target chain, and Circle forwards a burn to five of them. Plasma is a source only.
| Chain | Chain id | May be the target |
|---|---|---|
| Ethereum | 1 | yes |
| Polygon PoS | 137 | yes |
| Base | 8453 | yes |
| Plasma | 9745 | no |
| Arbitrum One | 42161 | yes |
| Avalanche C-Chain | 43114 | yes |
supportedChains() lists the chains for which the SDK holds a current release record. While no release record exists, it is empty and
recordFor(chainId) throws unsupported-chain. A chain whose record is superseded, retired or vulnerable is not served either.
The Safe's address
computeSafeAddress computes the address from the owners, the threshold and a salt nonce (zero when left out), for the version of the chain's record. It makes no read of a chain, so a lying RPC cannot move it. The address is the same on each chain. The order of the owners is part of the address. The owners are plain (EOA) owners: a contract, passkey or nested-Safe owner is refused.
const safe = sdk.computeSafeAddress({ chainId: 8453, owners, threshold, saltNonce });
final safe = sdk.computeSafeAddress( SafeInput(owners: owners, threshold: threshold, saltNonce: saltNonce), chainId: 8453,);
Existing Safes are refused
Only Safes created by the setup helper of a release take part in version 1 (SETUP-REQ-023).
checkSafe reads a Safe on a chain and refuses, by name:
| Refusal | Why |
|---|---|
safe-not-created-by-helper |
The Safe has another singleton, another fallback handler or another setup, or is not a Safe. Create a v1 Safe and move the funds to it. |
safe-version-below-floor |
The Safe is below Safe v1.5.0 (SAFE_VERSION_FLOOR), which the router needs (SETUP-REQ-019). The SDK does not upgrade a Safe. Create a v1 Safe and move the funds.
|
two-versions-modules |
The modules of two releases are enabled on one chain. One version runs at a time. |
owner-contract-refused, owner-passkey-refused, owner-nested-safe-refused
|
Version 1 serves plain owners only. |
A Safe with no code on the chain passes with deployed: false: it is born through the setup helper's transaction. A later SDK release may add a per-chain join of v1.5.0 Safes with no change to the contracts. It is not built, and the guide does not promise it. The fork test
test_ASafeV141WithTheRouterIsRefused shows what a Safe below v1.5.0 does with the router.
const check = await sdk.checkSafe({ chainId: 8453, safe });
final check = await sdk.checkSafe(chainId: 8453, safe: safe);
The order of the steps
-
Compute the Safe's address and check it on each chain it will use (
computeSafeAddress,checkSafe, above). -
Build the configuration, show the disclosure, collect the signatures (
configuration.md). -
Build and upload the documents of each chain the Safe will use (
documents.md). Orders wait until their document is uploaded. -
Build the first apply of the signed configuration (
buildFirstApply, below). It does not read the Safe, so it can be built before any deploy, and it is built once for all six chains. -
Deploy the Safe on the target chain with that first apply (
buildDeploywithfirstApply), which puts the apply after the deploy. -
Deploy and apply on the source chains the same way. The SDK refuses to arm a source chain before the target chain's Safe is deployed and configured (
source-before-target), because a burn would mint to an address that has no configuration yet. - If a token arrived at the Safe's address on Ethereum before the Safe exists there, the bootstrap order sells it (below).
Deploy ahead, the target first
buildDeploy returns, for each chain, the transactions to send in order, with the target chain first. The deploy is the factory's
createProxyWithNonce; anyone may send it, and whoever sends it pays the gas (costs.md). If a stranger deploys the predicted Safe first, the owners still get their Safe, and the step comes back with
alreadyDeployed: true and no deploy (test_AStrangerWhoDeploysThePredictedSafeFirstGivesTheOwnersTheirSafe).
const steps = await sdk.buildDeploy({ owners, threshold, saltNonce, targetChainId: 8453, chains: [8453], firstApply: first });for (const step of steps) for (const tx of step.transactions) await wallet.send(step.chainId, tx);
final steps = await sdk.buildDeploy(DeployInput( owners: owners, threshold: threshold, saltNonce: saltNonce, targetChainId: 8453, chains: [8453], firstApply: first,));
The target must be a chain Circle forwards to (target-chain-not-allowed, invalid-input).
first is the result of buildFirstApply, which the next section builds. Without it the step is the deploy alone, and the Safe is deployed and not armed.
The first apply, before the Safe exists
buildApply reads each chain and builds nothing for a chain where the Safe has no code: it reports that chain as
undeployed (running.md). A new Safe has no code anywhere, so
buildFirstApply builds its first apply without reading the Safe. It reads a chain only for the tokens of an oracle that the message names and that is not the reviewed one, to apply the refusal list (annex-asset-refused
and the other two). It takes the owners, the threshold and the salt nonce that make the Safe, and the signed message from
configuration.md with the verifyingContract
of the combined signatures:
const first = await sdk.buildFirstApply({ owners, threshold, saltNonce, signed });
final first = await sdk.buildFirstApply(FirstApplyInput( owners: owners, threshold: threshold, saltNonce: saltNonce, signed: signed,));
The result holds the Safe's address, the seq of the message and one transaction per chain,
first.transactions[chainId]. Each is a call of that chain's sweep module to applyConfiguration
with the message and the signatures. A chain list (chains) limits it; left out, it covers each chain the message's release has a record for. The call is the same bytes on each chain, because the contracts sit at the same address on each chain (SECURITY.md, "Verify a replacement version").
The call fails on a chain until the Safe is deployed there, and the same message applies after the deploy (test_ApplyBeforeTheSafeIsDeployedFailsAndTheSameMessageAppliesAfterwards). So
buildFirstApply does not send anything and puts nothing in order: buildDeploy
takes the result as firstApply and sends the call after the deploy, as two transactions or, with
batch: 'multisend', as one call of MultiSendCallOnly v1.5.0 (test_DeployAndApplyInOneBatchThroughMultiSendCallOnlyCalledDirectly). The Base fork suite sends the SDK's deploy and then its first apply to the real factory and the real sweep module, and sends both as one batch (ForkSuiteBaseConformanceVectors).
buildFirstApply checks what it can without a chain. The signatures are checked against the owners and threshold given, because there is no Safe to read them from: signatures that are not the owners' are
signature-mismatch. The message must be for the Safe those owners, threshold and salt nonce make: another Safe is
safe-address-mismatch, in buildFirstApply and again where buildDeploy
or buildBootstrapOrder takes the result. A store that no release record names is unknown-store, and malformed input is
invalid-input. buildDeploy also refuses a firstApply that holds no call for a chain in
chains (invalid-input), one whose call is not a call to that chain's sweep module, and one given together with
apply. A chain of the result that is not in chains is left alone, so one result serves every call.
Build the first apply once and hand it to each buildDeploy call:
-
buildDeployfor the target chain withchains: [targetChainId]andfirstApply: first. Send it. -
buildDeployfor the source chains withchainsset to them and the samefirstApply: first. It reads the target chain and refuses withsource-before-targetuntil the target's Safe is deployed and configured.
A Safe that is already deployed on a chain keeps buildApply, which also builds the sync
and reports the lag (running.md). buildDeploy with a
firstApply for a chain where the Safe has code (a stranger deployed it first) builds the apply alone; it fails on the chain if the Safe already holds that
seq or a newer one.
Ethereum as a source: the bootstrap order
Funds can arrive at the Safe's address on Ethereum before the Safe exists there. buildBootstrapOrder
builds the one discrete order that sells the token's whole balance for USDC, fill-or-kill, valid to the end of the 30-minute bucket it is built in. Its document carries two pre-hooks, the deploy of the Safe and the
apply of the signed configuration, and the burn as its post-hook, and no partner fee: it is the one order whose document the contract does not build. The order carries no owner signature; it is signed in the router's forwarder shape (the signature form the router answers for ComposableCoW, see
docs/cra/router.md) for the sweep module's conditional order, which apply creates. Nothing is sent by the build.
postBootstrapOrder posts it once, to the Ethereum order book the integrator configured, and is the only call of the SDK besides the document upload that writes to a service.
const order = await sdk.buildBootstrapOrder({ owners, threshold, saltNonce, targetChainId: 8453, token, row: { oracle, slippageBps }, firstApply: first });const uid = await sdk.postBootstrapOrder(order);
final order = await sdk.buildBootstrapOrder(BootstrapInput( owners: owners, threshold: threshold, saltNonce: saltNonce, targetChainId: 8453, token: token, row: BootstrapRow(oracle: oracle, slippageBps: slippageBps), firstApply: first,));final uid = await sdk.postBootstrapOrder(order);
The second pre-hook is the call for Ethereum of the first apply (first.transactions[1], above).
apply takes a transaction built by hand instead; give one of the two (invalid-input
otherwise). The refusals: safe-address-mismatch (the first apply is for another Safe than these owners, threshold and salt nonce make),
bootstrap-not-applicable (Ethereum is the target, or the Safe already has code there, so its conditional orders sweep what it holds),
nothing-to-sweep, token-not-priced (the oracle does not price the token in USDC),
bootstrap-document-too-large (the document carries the whole apply call data and reaches the order book's default size limit,
APP_DATA_MAX_BYTES; deploy this chain ahead instead), source-before-target, and the refusal-list refusals for a token the list names (configuration.md). A second order for the same balance in the same bucket is refused by the order book (test_ASecondBootstrapOrderForTheSameBalanceInTheSameBucketIsRefused), and a stranger who deploys the Safe first does not stop the order (test_AStrangerWhoDeploysTheSafeFirstDoesNotStopTheBootstrapOrder).
The document declares the gas of the two pre-hooks: 600,000 for the deploy and 3,000,000 for the apply (DEPLOY_HOOK_GAS_LIMIT
and APPLY_HOOK_GAS_LIMIT in packages/sdk-ts/src/bootstrap.ts; hookGas
overrides them). docs/gas.md ("The declared limits against the measurements") finds the deploy limit enough on each chain, with 260,185 gas spare on Plasma (76.57 %), and the apply limit enough with 88,470 gas spare on Ethereum (3.04 %), the chain with the most tokens at the pin. The apply costs a fixed part plus a part for each token the oracle lists, so a longer list starves the hook: by the line in
docs/gas.md ("The constants the release candidate needs: the apply hook's fixed and per-token parts") 3,000,000 gas covers 32 tokens on Arbitrum One and Polygon PoS and 33 on the other four. The constants are not frozen yet. An integrator that builds a bootstrap order for a chain whose oracle lists more tokens passes its own
hookGas.apply.