Skip to content

Commit

Permalink
Merge pull request #105 from clober-dex/feat/update-vault-interface
Browse files Browse the repository at this point in the history
feat: update vault interface
  • Loading branch information
Dorvin authored Sep 25, 2024
2 parents c2f5c7b + 4fee55c commit 706b668
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 78 deletions.
32 changes: 0 additions & 32 deletions src/abis/rebalancer/minter-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,11 @@ export const MINTER_ABI = [
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [
{
internalType: 'address',
name: 'target',
type: 'address',
},
],
name: 'AddressEmptyCode',
type: 'error',
},
{
inputs: [],
name: 'ERC20TransferFailed',
type: 'error',
},
{
inputs: [],
name: 'FailedCall',
type: 'error',
},
{
inputs: [
{
internalType: 'uint256',
name: 'balance',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'needed',
type: 'uint256',
},
],
name: 'InsufficientBalance',
type: 'error',
},
{
inputs: [],
name: 'NativeTransferFailed',
Expand Down
5 changes: 5 additions & 0 deletions src/abis/rebalancer/operator-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ export const OPERATOR_ABI = [
name: 'tickB',
type: 'int24',
},
{
internalType: 'uint64',
name: 'alpha',
type: 'uint64',
},
],
name: 'updatePrice',
outputs: [],
Expand Down
74 changes: 38 additions & 36 deletions src/abis/rebalancer/rebalancer-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ export const REBALANCER_ABI = [
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [
{
internalType: 'address',
name: 'target',
type: 'address',
},
],
name: 'AddressEmptyCode',
type: 'error',
},
{
inputs: [],
name: 'AlreadyOpened',
Expand All @@ -36,27 +25,6 @@ export const REBALANCER_ABI = [
name: 'ERC20TransferFailed',
type: 'error',
},
{
inputs: [],
name: 'FailedCall',
type: 'error',
},
{
inputs: [
{
internalType: 'uint256',
name: 'balance',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'needed',
type: 'uint256',
},
],
name: 'InsufficientBalance',
type: 'error',
},
{
inputs: [],
name: 'InvalidAmount',
Expand Down Expand Up @@ -773,14 +741,48 @@ export const REBALANCER_ABI = [
name: 'getLiquidity',
outputs: [
{
internalType: 'uint256',
components: [
{
internalType: 'uint256',
name: 'reserve',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'claimable',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'cancelable',
type: 'uint256',
},
],
internalType: 'struct IRebalancer.Liquidity',
name: 'liquidityA',
type: 'uint256',
type: 'tuple',
},
{
internalType: 'uint256',
components: [
{
internalType: 'uint256',
name: 'reserve',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'claimable',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'cancelable',
type: 'uint256',
},
],
internalType: 'struct IRebalancer.Liquidity',
name: 'liquidityB',
type: 'uint256',
type: 'tuple',
},
],
stateMutability: 'view',
Expand Down
29 changes: 29 additions & 0 deletions src/abis/rebalancer/strategy-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const STRATEGY_ABI = [
name: 'InvalidTick',
type: 'error',
},
{
inputs: [],
name: 'InvalidValue',
type: 'error',
},
{
inputs: [],
name: 'NotOperator',
Expand Down Expand Up @@ -228,6 +233,12 @@ export const STRATEGY_ABI = [
name: 'tickB',
type: 'int24',
},
{
indexed: false,
internalType: 'uint256',
name: 'alpha',
type: 'uint256',
},
],
name: 'UpdatePrice',
type: 'event',
Expand Down Expand Up @@ -323,6 +334,19 @@ export const STRATEGY_ABI = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getAlpha',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
Expand Down Expand Up @@ -620,6 +644,11 @@ export const STRATEGY_ABI = [
name: 'tickB',
type: 'int24',
},
{
internalType: 'uint256',
name: 'alpha',
type: 'uint256',
},
],
name: 'updatePrice',
outputs: [],
Expand Down
14 changes: 13 additions & 1 deletion src/apis/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function fetchPool(
const [
{ bookIdA, bookIdB, reserveA, reserveB, orderListA, orderListB },
totalSupply,
[liquidityA, liquidityB],
[totalLiquidityA, totalLiquidityB],
] = await publicClient.multicall({

Check failure on line 33 in src/apis/pool.ts

View workflow job for this annotation

GitHub Actions / NPM Test (18.10)

open.test.ts > try open pool

ContractFunctionExecutionError: The contract function "getPool" returned no data ("0x"). This could be due to any of the following: - The contract does not have the function "getPool", - The parameters passed to the contract function may be invalid, or - The address is not a contract. Contract Call: address: 0xCF556d850277BC579c99C0729F4E72e62C57D811 function: getPool(bytes32 key) args: (0x6cf422b2bb53aafd274d55740e6c8437055eba392cb2f69633c35462ab920bb7) Docs: https://viem.sh/docs/contract/multicall Version: [email protected] ❯ getContractError ../node_modules/viem/utils/errors/getContractError.ts:72:10 ❯ multicall ../node_modules/viem/actions/public/multicall.ts:271:23 ❯ Module.fetchPool ../src/apis/pool.ts:33:7 ❯ Module.openPool ../src/call.ts:1037:16 ❯ open.test.ts:111:24 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { details: undefined, docsPath: '/docs/contract/multicall', metaMessages: [ 'This could be due to any of the following:', ' - The contract does not have the function "getPool",', ' - The parameters passed to the contract function may be invalid, or', ' - The address is not a contract.', ' ', 'Contract Call:', ' address: 0xCF556d850277BC579c99C0729F4E72e62C57D811\n function: getPool(bytes32 key)\n args: (0x6cf422b2bb53aafd274d55740e6c8437055eba392cb2f69633c35462ab920bb7)' ], shortMessage: 'The contract function "getPool" returned no data ("0x").', version: '[email protected]', abi: [ { inputs: [ { internalType: 'contract IBookManager', name: 'bookManager_', type: 'address' }, { internalType: 'address', name: 'initialOwner_', type: 'address' } ], stateMutability: 'nonpayable', type: 'constructor' }, { inputs: [], name: 'AlreadyOpened', type: 'error' }, { inputs: [], name: 'ERC20TransferFailed', type: 'error' }, { inputs: [], name: 'InvalidAmount', type: 'error' }, { inputs: [], name: 'InvalidBookPair', type: 'error' }, { inputs: [], name: 'InvalidHook', type: 'error' }, { inputs: [], name: 'InvalidLockAcquiredSender', type: 'error' }, { inputs: [], name: 'InvalidLockCaller', type: 'error' }, { inputs: [], name: 'InvalidMaker', type: 'error' }, { inputs: [], name: 'InvalidStrategy', type: 'error' }, { inputs: [], name: 'InvalidTick', type: 'error' }, { inputs: [], name: 'InvalidValue', type: 'error' }, { inputs: [], name: 'LockFailure', type: 'error' }, { inputs: [], name: 'NativeTransferFailed', type: 'error' }, { inputs: [], name: 'NotSelf', type: 'error' }, { inputs: [ { internalType: 'address', name: 'owner', type: 'address' } ], name: 'OwnableInvalidOwner', type: 'error' }, { inputs: [ { internalType: 'address', name: 'account', type: 'address' } ], name: 'OwnableUnauthorizedAccount', type: 'error' }, { inputs: [ { internalType: 'address', name: 'token', type: 'address' } ], name: 'SafeERC20FailedOperation', type: 'error' }, { inputs: [], name: 'Slippage', type: 'error' }, { anonymous: false, inputs: [ { indexed: true, internalType: 'address', name: 'owner', type: 'address' }, { indexed: true, internalType: 'address', name: 'spender', type: 'address' }, { indexed: true, internalType: 'uint256', name: 'id', type: 'uint256' }, { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' } ], name: 'Approval', type: 'event' }, { anonymous: false, inputs: [ { indexed: true, internalType: 'address', name: 'user', type: 'address' }, { indexed: true, internalType: 'bytes32', name: 'key', type: 'bytes32' }, { indexed: false, internalType: 'uint256', name: 'amountA', type: 'uint256' }, { indexed: false, internalType: 'uint256', name: 'amountB', type: 'uint256' }, { indexed: false, internalType: 'uint256', name: 'lpAmount', type: 'uint256' } ], name: 'Burn', type: 'event' }, { anonymous: false, inputs: [ { indexed: true, internalType: 'address', name: 'user', type: 'address' }, { indexed: true, internalType: 'bytes32', name: 'key', type: 'bytes32' }, { indexed: false, internalType: 'uint256', name: 'amountA', type: 'uint256' }, { indexed: false, internalType: 'uint256', name: 'amountB', type: 'uint256' }, { indexed: false, internalType: 'uint256', nam
allowFailure: false,
contracts: [
Expand All @@ -53,6 +53,14 @@ export async function fetchPool(
},
],
})
const liquidityA =
totalLiquidityA.reserve +
totalLiquidityA.cancelable +
totalLiquidityA.claimable
const liquidityB =
totalLiquidityB.reserve +
totalLiquidityB.cancelable +
totalLiquidityB.claimable
const orders = await fetchOnChainOrders(
publicClient,
chainId,
Expand All @@ -74,6 +82,10 @@ export async function fetchPool(
: market.quote.decimals,
liquidityA: BigInt(liquidityA),
liquidityB: BigInt(liquidityB),
cancelableA: BigInt(totalLiquidityA.cancelable),
cancelableB: BigInt(totalLiquidityB.cancelable),
claimableA: BigInt(totalLiquidityA.claimable),
claimableB: BigInt(totalLiquidityB.claimable),
reserveA: BigInt(reserveA),
reserveB: BigInt(reserveB),
orderListA: orders.filter((order) => orderListA.includes(BigInt(order.id))),
Expand Down
9 changes: 8 additions & 1 deletion src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ export const updateStrategyPrice = async ({
oraclePrice,
priceA,
priceB,
alpha,
options,
}: {
chainId: CHAIN_IDS
Expand All @@ -1527,6 +1528,7 @@ export const updateStrategyPrice = async ({
oraclePrice: string // price with currencyA as quote
priceA: string // price with currencyA as quote
priceB: string // price when currencyA as quote
alpha: string // alpha value, 0 < alpha <= 1
options?: {
tickA?: bigint
tickB?: bigint
Expand All @@ -1535,6 +1537,9 @@ export const updateStrategyPrice = async ({
useSubgraph?: boolean
} & DefaultWriteContractOptions
}): Promise<Transaction> => {
if (Number(alpha) <= 0 || Number(alpha) > 1) {
throw new Error('Alpha value must be in the range (0, 1]')
}
const publicClient = createPublicClient({
chain: CHAIN_MAP[chainId],
transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
Expand Down Expand Up @@ -1591,6 +1596,8 @@ export const updateStrategyPrice = async ({
? Number(options.tickB)
: Number(invertTick(roundingUpPriceB ? roundingUpTickB : roundingDownTickB))

const alphaRaw = parseUnits(alpha, 6)

return buildTransaction(
publicClient,
{
Expand All @@ -1599,7 +1606,7 @@ export const updateStrategyPrice = async ({
address: CONTRACT_ADDRESSES[chainId]!.Operator,
abi: OPERATOR_ABI,
functionName: 'updatePrice',
args: [pool.key, oracleRawPrice, tickA, tickB],
args: [pool.key, oracleRawPrice, tickA, tickB, alphaRaw],
},
options?.gasLimit,
)
Expand Down
16 changes: 8 additions & 8 deletions src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export const CONTRACT_ADDRESSES: {
Controller: getAddress('0xfAe4A04fa491DC21F77796394532a1B62d8331BF'),
BookManager: getAddress('0x4a4eaF7382821da4Fb85e8A8d515f5555383d58A'),
BookViewer: getAddress('0xA7603C4c895a533E66c30EA76cC6F6A6A0c5cbFe'),
Rebalancer: getAddress('0x4Ba00c2849D993279AD30E1618C73d6db4c64ACe'),
Strategy: getAddress('0x49cD6E6cFBB0B022f2389FaC4b0889CdBC26dc11'),
Minter: getAddress('0x852Ce4B5448F95A7D091393B5bbc159d16fb291a'),
Operator: getAddress('0xEEE4F3b484787bd28aa0e790b4ab92660e7ecd06'),
Rebalancer: getAddress('0xCF556d850277BC579c99C0729F4E72e62C57D811'),
Strategy: getAddress('0x8aDF62b0b6078EaE5a2D54e9e5DD2AA71F6748C4'),
Minter: getAddress('0xF2f51B00C2e9b77F23fD66649bbabf8a025c39eF'),
Operator: getAddress('0x33559576B062D08230b467ea7DC7Ce75aFcbdE92'),
},
[CHAIN_IDS.ARBITRUM_SEPOLIA]: {
Controller: getAddress('0xFbbA685a39bE6640B8EB08c6E6DDf2664fD1D668'),
BookManager: getAddress('0xC528b9ED5d56d1D0d3C18A2342954CE1069138a4'),
BookViewer: getAddress('0x73c524e103C94Bf2743659d739586395B1A9e1BE'),
Rebalancer: getAddress('0x4Ba00c2849D993279AD30E1618C73d6db4c64ACe'),
Strategy: getAddress('0x49cD6E6cFBB0B022f2389FaC4b0889CdBC26dc11'),
Minter: getAddress('0x852Ce4B5448F95A7D091393B5bbc159d16fb291a'),
Operator: getAddress('0xEEE4F3b484787bd28aa0e790b4ab92660e7ecd06'),
Rebalancer: getAddress('0xCF556d850277BC579c99C0729F4E72e62C57D811'),
Strategy: getAddress('0x8aDF62b0b6078EaE5a2D54e9e5DD2AA71F6748C4'),
Minter: getAddress('0xF2f51B00C2e9b77F23fD66649bbabf8a025c39eF'),
Operator: getAddress('0x33559576B062D08230b467ea7DC7Ce75aFcbdE92'),
},
[CHAIN_IDS.BASE]: {
Controller: getAddress('0x57dDD0d3DF50685444442076AC59F9c7Df75D150'),
Expand Down
16 changes: 16 additions & 0 deletions src/model/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class Pool {
reserveB: string
liquidityA: bigint
liquidityB: bigint
cancelableA: bigint
cancelableB: bigint
claimableA: bigint
claimableB: bigint
orderListA: OnChainOpenOrder[]
orderListB: OnChainOpenOrder[]

Expand All @@ -40,6 +44,10 @@ export class Pool {
reserveB,
liquidityA,
liquidityB,
cancelableA,
cancelableB,
claimableA,
claimableB,
orderListA,
orderListB,
}: {
Expand All @@ -56,6 +64,10 @@ export class Pool {
reserveB: bigint
liquidityA: bigint
liquidityB: bigint
cancelableA: bigint
cancelableB: bigint
claimableA: bigint
claimableB: bigint
orderListA: OnChainOpenOrder[]
orderListB: OnChainOpenOrder[]
}) {
Expand Down Expand Up @@ -87,6 +99,10 @@ export class Pool {
this.decimals = decimals
this.liquidityA = liquidityA
this.liquidityB = liquidityB
this.cancelableA = cancelableA
this.cancelableB = cancelableB
this.claimableA = claimableA
this.claimableB = claimableB
this.reserveA = formatUnits(reserveA, this.currencyA.decimals)
this.reserveB = formatUnits(reserveB, this.currencyB.decimals)
this.orderListA = orderListA
Expand Down

0 comments on commit 706b668

Please sign in to comment.