diff --git a/zp-relayer/abi/accounting-abi.json b/zp-relayer/abi/accounting-abi.json new file mode 100644 index 00000000..c8bddf3a --- /dev/null +++ b/zp-relayer/abi/accounting-abi.json @@ -0,0 +1,487 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_precision", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "manager", + "type": "address" + } + ], + "name": "UpdateKYCProvidersManager", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint8", + "name": "tier", + "type": "uint8" + }, + { + "components": [ + { + "internalType": "uint56", + "name": "tvlCap", + "type": "uint56" + }, + { + "internalType": "uint32", + "name": "dailyDepositCap", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "dailyWithdrawalCap", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "dailyUserDepositCap", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "depositCap", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "directDepositCap", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "dailyUserDirectDepositCap", + "type": "uint32" + } + ], + "indexed": false, + "internalType": "struct ZkBobAccounting.TierLimits", + "name": "limits", + "type": "tuple" + } + ], + "name": "UpdateLimits", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "tier", + "type": "uint8" + } + ], + "name": "UpdateTier", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "getLimitsFor", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "tvlCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tvl", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyDepositCapUsage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyWithdrawalCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyWithdrawalCapUsage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyUserDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyUserDepositCapUsage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "depositCap", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "tier", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "dailyUserDirectDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "dailyUserDirectDepositCapUsage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "directDepositCap", + "type": "uint256" + } + ], + "internalType": "struct IZkBobAccounting.Limits", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint32", + "name": "_txCount", + "type": "uint32" + }, + { + "internalType": "uint72", + "name": "_tvl", + "type": "uint72" + }, + { + "internalType": "uint88", + "name": "_cumTvl", + "type": "uint88" + }, + { + "internalType": "uint32", + "name": "_maxWeeklyTxCount", + "type": "uint32" + }, + { + "internalType": "uint56", + "name": "_maxWeeklyAvgTvl", + "type": "uint56" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "kycProvidersManager", + "outputs": [ + { + "internalType": "contract IKycProvidersManager", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "enum IZkBobAccounting.TxType", + "name": "_txType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "_user", + "type": "address" + }, + { + "internalType": "int256", + "name": "_txAmount", + "type": "int256" + } + ], + "name": "recordOperation", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_tier", + "type": "uint8" + } + ], + "name": "resetDailyLimits", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IKycProvidersManager", + "name": "_kycProvidersManager", + "type": "address" + } + ], + "name": "setKycProvidersManager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_tier", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "_tvlCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_dailyDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_dailyWithdrawalCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_dailyUserDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_depositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_dailyUserDirectDepositCap", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_directDepositCap", + "type": "uint256" + } + ], + "name": "setLimits", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_tier", + "type": "uint8" + }, + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "setUserTier", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_tier", + "type": "uint8" + }, + { + "internalType": "address[]", + "name": "_users", + "type": "address[]" + } + ], + "name": "setUsersTier", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "slot0", + "outputs": [ + { + "internalType": "uint56", + "name": "maxWeeklyAvgTvl", + "type": "uint56" + }, + { + "internalType": "uint32", + "name": "maxWeeklyTxCount", + "type": "uint32" + }, + { + "internalType": "uint24", + "name": "tailSlot", + "type": "uint24" + }, + { + "internalType": "uint24", + "name": "headSlot", + "type": "uint24" + }, + { + "internalType": "uint88", + "name": "cumTvl", + "type": "uint88" + }, + { + "internalType": "uint32", + "name": "txCount", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "slot1", + "outputs": [ + { + "internalType": "uint72", + "name": "tvl", + "type": "uint72" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/zp-relayer/abi/pool-abi.json b/zp-relayer/abi/pool-abi.json index 17c40810..4a1635db 100644 --- a/zp-relayer/abi/pool-abi.json +++ b/zp-relayer/abi/pool-abi.json @@ -35,6 +35,80 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "nullifier", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "operator", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "exitStart", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "exitEnd", + "type": "uint256" + } + ], + "name": "CommitForcedExit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "index", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "nullifier", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "ForcedExit", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -83,56 +157,13 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "uint8", - "name": "tier", - "type": "uint8" - }, - { - "components": [ - { - "internalType": "uint56", - "name": "tvlCap", - "type": "uint56" - }, - { - "internalType": "uint32", - "name": "dailyDepositCap", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "dailyWithdrawalCap", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "dailyUserDepositCap", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "depositCap", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "directDepositCap", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "dailyUserDirectDepositCap", - "type": "uint32" - } - ], "indexed": false, - "internalType": "struct ZkBobAccounting.TierLimits", - "name": "limits", - "type": "tuple" + "internalType": "address", + "name": "accounting", + "type": "address" } ], - "name": "UpdateLimits", + "name": "UpdateAccounting", "type": "event" }, { @@ -154,17 +185,11 @@ { "indexed": false, "internalType": "address", - "name": "user", + "name": "redeemer", "type": "address" - }, - { - "indexed": false, - "internalType": "uint8", - "name": "tier", - "type": "uint8" } ], - "name": "UpdateTier", + "name": "UpdateRedeemer", "type": "event" }, { @@ -199,6 +224,19 @@ "name": "WithdrawFee", "type": "event" }, + { + "inputs": [], + "name": "accounting", + "outputs": [ + { + "internalType": "contract IZkBobAccounting", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -278,112 +316,88 @@ "type": "function" }, { - "inputs": [], - "name": "denominator", - "outputs": [ + "inputs": [ + { + "internalType": "address", + "name": "_operator", + "type": "address" + }, + { + "internalType": "address", + "name": "_to", + "type": "address" + }, { "internalType": "uint256", - "name": "", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_index", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_nullifier", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_out_commit", + "type": "uint256" + }, + { + "internalType": "uint256[8]", + "name": "_transfer_proof", + "type": "uint256[8]" } ], - "stateMutability": "pure", + "name": "commitForcedExit", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "direct_deposit_queue", + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "committedForcedExits", "outputs": [ { - "internalType": "contract IZkBobDirectDepositQueue", + "internalType": "bytes32", "name": "", - "type": "address" + "type": "bytes32" } ], "stateMutability": "view", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "denominator", + "outputs": [ { - "internalType": "address", - "name": "_user", - "type": "address" + "internalType": "uint256", + "name": "", + "type": "uint256" } ], - "name": "getLimitsFor", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "direct_deposit_queue", "outputs": [ { - "components": [ - { - "internalType": "uint256", - "name": "tvlCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tvl", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyDepositCapUsage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyWithdrawalCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyWithdrawalCapUsage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyUserDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyUserDepositCapUsage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "depositCap", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "tier", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "dailyUserDirectDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "dailyUserDirectDepositCapUsage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "directDepositCap", - "type": "uint256" - } - ], - "internalType": "struct ZkBobAccounting.Limits", + "internalType": "contract IZkBobDirectDepositQueue", "name": "", - "type": "tuple" + "type": "address" } ], "stateMutability": "view", @@ -393,42 +407,88 @@ "inputs": [ { "internalType": "uint256", - "name": "_root", + "name": "_nullifier", "type": "uint256" }, { - "internalType": "uint256", - "name": "_tvlCap", - "type": "uint256" + "internalType": "address", + "name": "_operator", + "type": "address" }, { - "internalType": "uint256", - "name": "_dailyDepositCap", - "type": "uint256" + "internalType": "address", + "name": "_to", + "type": "address" }, { "internalType": "uint256", - "name": "_dailyWithdrawalCap", + "name": "_amount", "type": "uint256" }, { "internalType": "uint256", - "name": "_dailyUserDepositCap", + "name": "_exitStart", "type": "uint256" }, { "internalType": "uint256", - "name": "_depositCap", + "name": "_exitEnd", "type": "uint256" + } + ], + "name": "executeForcedExit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot", + "type": "bytes32" + } + ], + "name": "extsload", + "outputs": [ + { + "internalType": "bytes32", + "name": "value", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "startSlot", + "type": "bytes32" }, { "internalType": "uint256", - "name": "_dailyUserDirectDepositCap", + "name": "nSlots", "type": "uint256" - }, + } + ], + "name": "extsload", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ { "internalType": "uint256", - "name": "_directDepositCap", + "name": "_root", "type": "uint256" } ], @@ -437,6 +497,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint96", + "name": "_poolIndex", + "type": "uint96" + } + ], + "name": "initializePoolIndex", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -500,9 +573,9 @@ "name": "pool_index", "outputs": [ { - "internalType": "uint256", + "internalType": "uint96", "name": "", - "type": "uint256" + "type": "uint96" } ], "stateMutability": "view", @@ -528,20 +601,20 @@ }, { "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "name": "redeemer", + "outputs": [ { - "internalType": "uint8", - "name": "_tier", - "type": "uint8" + "internalType": "contract IEnergyRedeemer", + "name": "", + "type": "address" } ], - "name": "resetDailyLimits", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -568,47 +641,12 @@ { "inputs": [ { - "internalType": "uint8", - "name": "_tier", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "_tvlCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_dailyDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_dailyWithdrawalCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_dailyUserDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_depositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_dailyUserDirectDepositCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_directDepositCap", - "type": "uint256" + "internalType": "contract IZkBobAccounting", + "name": "_accounting", + "type": "address" } ], - "name": "setLimits", + "name": "setAccounting", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -616,12 +654,12 @@ { "inputs": [ { - "internalType": "contract IOperatorManager", - "name": "_operatorManager", + "internalType": "contract IEnergyRedeemer", + "name": "_redeemer", "type": "address" } ], - "name": "setOperatorManager", + "name": "setEnergyRedeemer", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -629,12 +667,12 @@ { "inputs": [ { - "internalType": "address", - "name": "_seller", + "internalType": "contract IOperatorManager", + "name": "_operatorManager", "type": "address" } ], - "name": "setTokenSeller", + "name": "setOperatorManager", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -642,17 +680,12 @@ { "inputs": [ { - "internalType": "uint8", - "name": "_tier", - "type": "uint8" - }, - { - "internalType": "address[]", - "name": "_users", - "type": "address[]" + "internalType": "address", + "name": "_seller", + "type": "address" } ], - "name": "setUsersTier", + "name": "setTokenSeller", "outputs": [], "stateMutability": "nonpayable", "type": "function" diff --git a/zp-relayer/pool.ts b/zp-relayer/pool.ts index 314d17de..3e77395a 100644 --- a/zp-relayer/pool.ts +++ b/zp-relayer/pool.ts @@ -1,6 +1,7 @@ import BN from 'bn.js' import PoolAbi from './abi/pool-abi.json' import TokenAbi from './abi/token-abi.json' +import AccountingAbi from './abi/accounting-abi.json' import { AbiItem, toBN } from 'web3-utils' import type { Contract } from 'web3-eth-contract' import config from './configs/relayerConfig' @@ -77,6 +78,7 @@ export interface LimitsFetch { class Pool { public PoolInstance: Contract public TokenInstance: Contract + public AccountingInstance: Contract private txVK: VK public state: PoolState public optimisticState: PoolState @@ -88,6 +90,7 @@ class Pool { constructor() { this.PoolInstance = new web3.eth.Contract(PoolAbi as AbiItem[], config.poolAddress) this.TokenInstance = new web3.eth.Contract(TokenAbi as AbiItem[], config.tokenAddress) + this.AccountingInstance = new web3.eth.Contract(AccountingAbi as AbiItem[], config.poolAddress) const txVK = require(config.txVKPath) this.txVK = txVK @@ -106,6 +109,11 @@ class Pool { this.denominator = toBN(await this.PoolInstance.methods.denominator().call()) this.poolId = toBN(await this.PoolInstance.methods.pool_id().call()) + try { + this.AccountingInstance.options.address = await this.PoolInstance.methods.accounting().call() + } catch (_) { + logger.warn('Accounting contract not configured') + } if (config.permitType === PermitType.SaltedPermit) { this.permitRecover = new SaltedPermitRecover(web3, config.tokenAddress) @@ -270,7 +278,7 @@ class Pool { } async getLimitsFor(address: string): Promise { - const limits = await contractCallRetry(this.PoolInstance, 'getLimitsFor', [address]) + const limits = await contractCallRetry(this.AccountingInstance, 'getLimitsFor', [address]) return { tvlCap: toBN(limits.tvlCap), tvl: toBN(limits.tvl),