Skip to content

Commit a3fc662

Browse files
committed
minimum impl for positionsCreate
1 parent bac9a71 commit a3fc662

27 files changed

Lines changed: 5741 additions & 812 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { l2AvailableNetworks } from '../const'
2+
import type { UndefinedOr } from '@devprotocol/util-ts'
3+
import { createLockupContract, LockupContract } from '../../../ethereum/lockup'
4+
import {
5+
createLockupContract as createLockupContractL2,
6+
LockupContract as LockupContractL2,
7+
} from '../../../l2/lockup'
8+
import { Provider } from '@ethersproject/abstract-provider'
9+
import { registryClientL1 } from './registryClientL1'
10+
11+
const cache: WeakMap<
12+
Provider,
13+
readonly [UndefinedOr<LockupContract>, UndefinedOr<LockupContractL2>]
14+
> = new WeakMap()
15+
16+
export const lockupClients = async (
17+
provider: Provider
18+
): Promise<
19+
readonly [UndefinedOr<LockupContract>, UndefinedOr<LockupContractL2>]
20+
> => {
21+
const res =
22+
cache.get(provider) ??
23+
(await (async () => {
24+
const net = await provider.getNetwork()
25+
const registry = await registryClientL1(provider)
26+
const l1 = registry
27+
? createLockupContract(provider)(await registry.lockup())
28+
: undefined
29+
const l2 = ((data) =>
30+
data ? createLockupContractL2(provider)(data.map.lockup) : undefined)(
31+
l2AvailableNetworks.find(({ chainId }) => chainId === net.chainId)
32+
)
33+
const results: readonly [
34+
UndefinedOr<LockupContract>,
35+
UndefinedOr<LockupContractL2>
36+
] = [l1, l2]
37+
// eslint-disable-next-line functional/no-expression-statement
38+
cache.set(provider, results)
39+
return results
40+
})())
41+
return res
42+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { l1AvailableNetworks } from '../const'
2+
import type { UndefinedOr } from '@devprotocol/util-ts'
3+
import {
4+
createRegistryContract,
5+
RegistryContract,
6+
} from '../../../ethereum/registry'
7+
import { Provider } from '@ethersproject/abstract-provider'
8+
9+
const cache: WeakMap<Provider, UndefinedOr<RegistryContract>> = new WeakMap()
10+
11+
export const registryClientL1 = async (
12+
provider: Provider
13+
): Promise<UndefinedOr<RegistryContract>> => {
14+
const res =
15+
cache.get(provider) ??
16+
(await (async () => {
17+
const net = await provider.getNetwork()
18+
const l1Info = l1AvailableNetworks.find(
19+
({ chainId }) => chainId === net.chainId
20+
)
21+
const l1 = l1Info
22+
? createRegistryContract(provider)(l1Info.registry)
23+
: undefined
24+
const results = l1
25+
// eslint-disable-next-line functional/no-expression-statement
26+
cache.set(provider, l1)
27+
return results
28+
})())
29+
return res
30+
}

β€Žlib/agent/common/const.tsβ€Ž

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
import { ethers } from 'ethers'
2-
import { env } from './env'
1+
import { addresses } from '../../addresses'
32

4-
export const networks = {
5-
ethereum: {
6-
main: 1,
7-
ropsten: 3,
8-
},
9-
arbitrum: {
10-
one: 42161,
11-
rinkeby: 421611,
12-
},
3+
export type L1AvailableNetwork = {
4+
readonly chainId: number
5+
readonly registry: string
136
}
147

15-
export const testProviders = {
16-
homestead: ethers.getDefaultProvider(env.homestead),
17-
ropsten: ethers.getDefaultProvider(env.ropsten),
18-
arbOne: ethers.getDefaultProvider(env.arbMainnet),
19-
arbRinkeby: ethers.getDefaultProvider(env.arbRinkeby),
20-
polyMumbai: ethers.getDefaultProvider(env.polygonMumbai),
8+
export type L2AvailableNetwork = {
9+
readonly chainId: number
10+
readonly map: {
11+
readonly token: string
12+
readonly lockup: string
13+
readonly marketFactory: string
14+
readonly metricsFactory: string
15+
readonly policyFactory: string
16+
readonly propertyFactory: string
17+
readonly registry: string
18+
readonly sTokens: string
19+
readonly withdraw: string
20+
}
2121
}
22+
23+
export const l1AvailableNetworks: readonly L1AvailableNetwork[] = [
24+
{ chainId: 1, registry: addresses.eth.main.registry },
25+
{ chainId: 3, registry: addresses.eth.ropsten.registry },
26+
]
27+
28+
export const l2AvailableNetworks: readonly L2AvailableNetwork[] = [
29+
{
30+
chainId: 42161,
31+
map: addresses.arbitrum.one,
32+
},
33+
{ chainId: 421611, map: addresses.arbitrum.rinkeby },
34+
{ chainId: 137, map: addresses.polygon.mainnet },
35+
{ chainId: 80001, map: addresses.polygon.mumbai },
36+
]

β€Žlib/agent/common/env.tsβ€Ž

Lines changed: 0 additions & 7 deletions
This file was deleted.

β€Žlib/agent/common/utils.spec.tsβ€Ž

Lines changed: 0 additions & 110 deletions
This file was deleted.

β€Žlib/agent/common/utils.tsβ€Ž

Lines changed: 0 additions & 52 deletions
This file was deleted.

β€Žlib/agent/index.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { positionsCreate } from './lockup/positionsCreate'

β€Žlib/agent/lockup/calculateCumulativeHoldersRewardAmount.spec.tsβ€Ž

Lines changed: 0 additions & 31 deletions
This file was deleted.

β€Žlib/agent/lockup/calculateCumulativeHoldersRewardAmount.tsβ€Ž

Lines changed: 0 additions & 18 deletions
This file was deleted.

β€Žlib/agent/lockup/calculateRewardAmount.spec.tsβ€Ž

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
Β (0)