Deposits
Deposits are initiated on the L1 by the user. They send a transaction to the so-called DispatchContract, which is
unique to each appchain.
This contract has the responsibility to make sure that for every deposit message that your appchain receives, an actual transfer from the user to the settlement contract happened. That logic is validated by the Mina blockchain via this contract/zkapp. After that validation, the dispatch contract dispatches a message to the appchain that provably has to be honored.
Implementing deposits
To enable deposits (or any type of L1 -> L2 call), add the @runtimeMessage() decorator to your runtime method
(instead of using @runtimeMethod()).
import { RuntimeModule, runtimeModule, runtimeMessage } from "@proto-kit/module";
import { Deposit } from "@proto-kit/protocol";
@runtimeModule()
export class Balances extends RuntimeModule {
// ...
@runtimeMessage()
public async deposit(deposit: Deposit) {
await this.mint(deposit.tokenId, deposit.address, deposit.amount);
}
}Additionally, we need to tell the DispatchContract which runtime method it is allowed to call.
We do this by adding the path to the method to the contract’s config using a moduleName.methodName syntax.
Be careful to use the module name, not the class name - they can be different!
appchain.configure({
// ...
Protocol: {
// ...
SettlementContractModule: {
SettlementContract: {},
BridgeContract: {},
DispatchContract: {
incomingMessagesMethods: {
deposit: "Balances.deposit",
},
},
}
}
});Depositing tokens
Now that our appchain is ready to accept deposits (after deploying the settlement contract with the right runtime + config of course), we can look at how to use the mechanism.
// TODO