平衡数学 TS
平衡池数学的打字法执行。 也作为出版物发表 关于国家预防机制的一揽子措施。 。 。 .
钩子支持
虎克逐个得到支持.
当游泳池的钩子类型包含在 PoolState (单位:千美元) HookState 还必须传递作为任何断层操作的输入。 见 删除流动性示例 见下文.
目前支持的钩子 :
- 退出 FeeHook 语句
- 此勾钩执行 ExitFeeHook Example 在其中找到的示例 单重置
实例
交换
const vault = new Vault();
const pool = {
chainId: '11155111',
blockNumber: '5955146',
poolType: 'WEIGHTED',
poolAddress: '0x204d4194e4e42364e3d1841d0a9b1ef857879c31',
tokens: [
'0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
'0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75'
],
scalingFactors: [ 1000000000000000000n, 1000000000000000000n ],
weights: [ 500000000000000000n, 500000000000000000n ],
swapFee: 1000000000000000n,
balances: [ 64604926441576011n, 46686842105263157924n ],
tokenRates: [ 1000000000000000000n, 1000000000000000000n ],
totalSupply: 1736721048412749353n
};
const calculatedAmount = vault.swap(
{
amountRaw,
tokenIn,
tokenOut,
swapKind,
},
pool,
);
添加流动性
const vault = new Vault();
const pool = {
chainId: '11155111',
blockNumber: '5955145',
poolType: 'WEIGHTED',
poolAddress: '0x204d4194e4e42364e3d1841d0a9b1ef857879c31',
tokens: [
'0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
'0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75'
],
scalingFactors: [ 1000000000000000000n, 1000000000000000000n ],
weights: [ 500000000000000000n, 500000000000000000n ],
swapFee: 0n,
balances: [ 64604926441576011n, 46686842105263157924n ],
tokenRates: [ 1000000000000000000n, 1000000000000000000n ],
totalSupply: 1736721048412749353n
}
const calculatedAmounts = vault.addLiquidity(
{
pool: pool.poolAddress,
maxAmountsIn: inputAmountsRaw,
minBptAmountOut: bptOutRaw,
kind,
},
pool,
);
删除流动性
此示例显示在池与出Fee钩注册时如何计算去除百合操作的结果.
const vault = new Vault();
const poolState = {
poolType: 'WEIGHTED',
hookType: 'ExitFee',
chainId: '11155111',
blockNumber: '5955145',
poolAddress: '0x03722034317d8fb16845213bd3ce15439f9ce136',
tokens: [
'0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
'0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75',
],
scalingFactors: [1000000000000000000n, 1000000000000000000n],
weights: [500000000000000000n, 500000000000000000n],
swapFee: 100000000000000000n,
aggregateSwapFee: 0n,
balancesLiveScaled18: [5000000000000000n, 5000000000000000000n],
tokenRates: [1000000000000000000n, 1000000000000000000n],
totalSupply: 158113883008415798n,
};
const inputHookState = {
removeLiquidityHookFeePercentage: 0n,
tokens: poolState.tokens,
};
const removeLiquidityInput = {
pool: '0xb2456a6f51530053bc41b0ee700fe6a2c37282e8',
minAmountsOutRaw: [1n, 1n],
maxBptAmountInRaw: 10000000000000n,
kind: RemoveKind.PROPORTIONAL,
};
const outPutAmount = vault.removeLiquidity(
{
pool: pool.poolAddress,
minAmountsOutRaw: amountsOutRaw,
maxBptAmountInRaw: bptInRaw,
kind,
},
pool,
inputHookState
);