1. 引言
主要代码见:
- https://github.com/AztecProtocol/aztec-connect-bridges(Solidity)
- https://github.com/AztecProtocol/defi-bridge-hackathon(JavaScript)
本文主要借助Element Finance的Aztec Connect Contract合约来说明。
1.1 关键词解释- Principal Token:表示lender存入defi中的抵押品。
- Yield Token:表示lender因存放抵押品而产生的可变利息。
在Element Finance中,有一些对aztec connect bridge合约有用的流程:
- 1)从AMM中以一定折扣购买principal tokens,按期持有并赎回。
- 2)批量赎回。
- 3)Auto rollover of mints。自动累加mints。
最容易支持的流程是从AMM购买token 以及 支持token赎回。 取决于存入的资产 以及 想要支持的粒度,有3种潜在的实现方式:
- 1)Direct Async Bridge Flow:用户在zk.money中已有相应的source assets,或者愿意支付gas费来向zk.money存入资产。
用户在zk.money中已有相应的source assets,或者愿意支付gas费来向zk.money存入资产。
Element支持的资产类型有:DAI/USDC/WBTC,以及,crv3crypto, steCRV等复合资产。
相应的用户流程为:
- 1)用户在aztec L2层,选择所支持资产的shielded balance,发起一笔DeFi deposit交易。
- 2)aztec L2层 与 以太坊L1层 之间的rollup provider,会将L2层的交易打包,以每 n n n笔一组。
- 3)rollup provider会将打包后的交易提交到以太坊L1层的Aztec Rollup合约。
- 4)以太坊L1层的Aztec Rollup合约会调用部署在L1层的相应的Element的bridge合约。该bridge合约会受到来自于Aztec Rollup合约的aggregated transaction,在bridge合约内:
- 4.1)若对input asset有多个Element池,则DBC应使用
auxData
来选择正确的pool expiry。 - 4.2)将以given input asset ERC20 tokens,从Element AMM中购买
totalInputValue
个principal token。 - 4.3)记录购买交互操作中的interaction nonce值 和 所购买的principal token数量。
- 4.4)记录interaction nonce值 和 相应的到期日,使得该异步交易可在后续日期finalised。
- 4.5)给L1层的Aztec Rollup合约返回
isAsync=true
。
- 4.1)若对input asset有多个Element池,则DBC应使用
bridge合约中应有一个public函数,可返回a list of bridges that can be finalised。
对于返回的每个bridge的interactionNonce
值,可创建一笔以太坊交易,调用Aztec Rollup合约中的RollupContract.processAsyncDefiInteraction(uint256 interactionNonce)
来最终finalise on the bridge contract。
// Aztec Rollup合约
function processAsyncDeFiInteraction(uint256 interactionNonce) external {
// call canFinalise on the bridge
// call finalise on the bridge
DefiInteraction storage interaction = defiInteractions[
interactionNonce
];
require(
interaction.bridgeAddress != address(0),
"Rollup Contract: UNKNOWN_NONCE"
);
(uint256 outputValueA, uint256 outputValueB, bool interactionComplete) = IDefiBridge(
interaction.bridgeAddress
).finalise(
interaction.inputAssetA,
interaction.inputAssetB,
interaction.outputAssetA,
interaction.outputAssetB,
interaction.interactionNonce,
uint64(interaction.auxInputData)
);
.......
}
在Element bridge合约中,其finalise
函数将执行以下操作:
- 1)将principal token兑换为基础抵押品。
- 2)向提供此服务的
block.coinbase
或msg.sender
支付fee。可计算为a gas multiplier and paid from the collateral.redemption。 - 3)返回 基础抵押品 + 利息 到aztec rollup合约中,返回
outputAssetA
的正确值。
// Element Bridge合约
// serves as the 'off ramp' for the transaction
// converts the principal tokens back to the underlying asset
function finalise(
AztecTypes.AztecAsset calldata,
AztecTypes.AztecAsset calldata,
AztecTypes.AztecAsset calldata outputAssetA,
AztecTypes.AztecAsset calldata,
uint256 interactionNonce,
uint64
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool interactionComplete) {
require(msg.sender == rollupProcessor, "ElementBridge: INVALID_CALLER");
// retrieve the interaction and verify it's ready for finalising
Interaction storage interaction = interactions[interactionNonce];
require(interaction.expiry != 0, "ElementBridge: UNKNOWN_NONCE");
require(
interaction.expiry
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?