Skip to content

Commit

Permalink
api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser committed Sep 14, 2023
1 parent 6799e43 commit a955e44
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
52 changes: 27 additions & 25 deletions centrifuge-app/src/utils/useLiquidityPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ export function useActiveDomains(poolId: string) {
return [manager, pool] as const
})
)
return results
.map((result, i) => {
if (result.status === 'rejected') {
console.error(result.reason)
return null
}
const [manager, pool] = result.value
const router = routers![i]
if (!pool.isActive) return null
return {
chainId: router.chainId,
managerAddress: manager,
}
})
.filter(Boolean) as {
chainId: number
managerAddress: string
}[]
// return [
// {
// chainId: 5,
// managerAddress: '0xd0150fFD04C931100251347C533e69BC5a239dF6',
// },
// ]
// return results
// .map((result, i) => {
// if (result.status === 'rejected') {
// console.error(result.reason)
// return null
// }
// const [manager, pool] = result.value
// const router = routers![i]
// if (!pool.isActive) return null
// return {
// chainId: router.chainId,
// managerAddress: manager,
// }
// })
// .filter(Boolean) as {
// chainId: number
// managerAddress: string
// }[]
return [
{
chainId: 5,
managerAddress: '0x083f637f07609bef01EeCFa5d7fD033c91f5290D',
},
]
},
{
enabled: !!routers?.length && !poolId.startsWith('0x'),
Expand All @@ -60,7 +60,9 @@ export function useActiveDomains(poolId: string) {
return query
}

export function useLiquidityPools(poolId: string, trancheId: string) {
export function useLiquidityPools(_poolId: string, _trancheId: string) {
const poolId = '1171854325'
const trancheId = '0x102f4ef817340a8839a515d2c73a7c1d'
const {
evm: { chainId, getProvider },
} = useWallet()
Expand Down
20 changes: 11 additions & 9 deletions centrifuge-js/src/modules/liquidityPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as ABI from './liquidityPools/abi'

const maxUint256 = '115792089237316195423570985008687907853269984665640564039457584007913129639935'
const PERMIT_TYPEHASH = '0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9'
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'

type EvmQueryOptions = {
rpcProvider?: JsonRpcProvider
Expand Down Expand Up @@ -60,13 +61,13 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
switchMap((rawPool) => {
const pool = rawPool.toPrimitive() as any
const tx = api.tx.utility.batchAll([
api.tx.connectors.addPool(poolId, { EVM: chainId }),
api.tx.liquidityPools.addPool(poolId, { EVM: chainId }),
...pool.tranches.ids.flatMap((trancheId: string) => [
api.tx.connectors.addTranche(poolId, trancheId, { EVM: chainId }),
api.tx.liquidityPools.addTranche(poolId, trancheId, { EVM: chainId }),
// Ensure the domain currencies are enabled
// Using a batch, because theoretically they could have been enabled already for a different domain
api.tx.utility.batch(
currencyIds.map((cid) => api.tx.connectors.allowPoolCurrency(poolId, trancheId, cid))
currencyIds.map((cid) => api.tx.liquidityPools.allowPoolCurrency(poolId, trancheId, cid))
),
]),
])
Expand Down Expand Up @@ -162,9 +163,10 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {

function getDomainRouters() {
return inst.getApi().pipe(
switchMap((api) => api.query.connectorsGateway.domainRouters.entries()),
switchMap((api) => api.query.liquidityPoolsGateway.domainRouters.entries()),
map((rawRouters) => {
console.log('rawRouters', rawRouters)
return [{ chainId: 5, router: '0x7B4d13fE32Fd91eb002cb4A43A374519aD3DF5eC' }]
return rawRouters
.map(([rawKey, rawValue]) => {
const key = (rawKey.toHuman() as ['Centrifuge' | { EVM: string }])[0]
Expand All @@ -186,7 +188,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {

async function getManagerFromRouter(args: [router: string], options?: EvmQueryOptions) {
const [router] = args
const MOCK_router = '0x49d80873b5Bf0F7B54483269c51C5B312f34F9D0'
const MOCK_router = '0x7B4d13fE32Fd91eb002cb4A43A374519aD3DF5eC'
const gatewayAddress = await contract(MOCK_router, ABI.Router, options).gateway()
const managerAddress = await contract(gatewayAddress, ABI.Gateway, options).investmentManager()
return managerAddress as string
Expand Down Expand Up @@ -238,15 +240,15 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {

const currencyIds = await firstValueFrom(getDomainCurrencyIds([chainId]))

const tokenManager: string = await contract(managerAddress, ABI.InvestmentManager, options).tokenManager()
const poolManager: string = await contract(managerAddress, ABI.InvestmentManager, options).poolManager()

// const lps = ['0x6627eC6b0e467D02117bE6949189054102EAe177']
const stablesData = await multicall<{ currencyAddresses?: string[] }>(
[
...currencyIds.map(
(currencyId, i) =>
({
target: tokenManager,
target: poolManager,
call: ['function currencyIdToAddress(uint128) view returns (address)', currencyId],
returns: [[`currencyAddresses[${i}]`]],
} as Call)
Expand All @@ -263,7 +265,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
...stablesData.currencyAddresses.map(
(currencyAddr, i) =>
({
target: managerAddress,
target: poolManager,
call: [
'function getLiquidityPool(uint64, bytes16, address) view returns (address)',
poolId,
Expand Down Expand Up @@ -404,7 +406,7 @@ export function getLiquidityPoolsModule(inst: Centrifuge) {
},
{
target: lp,
call: ['function hasMember(address) view returns (bool)', user],
call: ['function checkTransferRestriction(address, address, uint) view returns (bool)', NULL_ADDRESS, user, 0],
returns: [['isAllowedToInvest']],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
[
"function getLiquidityPoolsForTranche(uint64, bytes16) view returns (address[])",
"function tokenManager() view returns (address)"
]
["function poolManager() view returns (address)"]

0 comments on commit a955e44

Please sign in to comment.