-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from dev-protocol/add-positionsCreate
positionsCreate
- Loading branch information
Showing
18 changed files
with
5,816 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { l2AvailableNetworks } from '../const' | ||
import type { UndefinedOr } from '@devprotocol/util-ts' | ||
import { createLockupContract, LockupContract } from '../../../ethereum/lockup' | ||
import { | ||
createLockupContract as createLockupContractL2, | ||
LockupContract as LockupContractL2, | ||
} from '../../../l2/lockup' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { registryClientL1 } from './registryClientL1' | ||
|
||
const cache: WeakMap< | ||
Provider, | ||
readonly [UndefinedOr<LockupContract>, UndefinedOr<LockupContractL2>] | ||
> = new WeakMap() | ||
|
||
export const lockupClients = async ( | ||
provider: Provider | ||
): Promise< | ||
readonly [UndefinedOr<LockupContract>, UndefinedOr<LockupContractL2>] | ||
> => { | ||
const res = | ||
cache.get(provider) ?? | ||
(await (async () => { | ||
const net = await provider.getNetwork() | ||
const registry = await registryClientL1(provider) | ||
const l1 = registry | ||
? createLockupContract(provider)(await registry.lockup()) | ||
: undefined | ||
const l2 = ((data) => | ||
data ? createLockupContractL2(provider)(data.map.lockup) : undefined)( | ||
l2AvailableNetworks.find(({ chainId }) => chainId === net.chainId) | ||
) | ||
const results: readonly [ | ||
UndefinedOr<LockupContract>, | ||
UndefinedOr<LockupContractL2> | ||
] = [l1, l2] | ||
// eslint-disable-next-line functional/no-expression-statement | ||
cache.set(provider, results) | ||
return results | ||
})()) | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { l1AvailableNetworks } from '../const' | ||
import type { UndefinedOr } from '@devprotocol/util-ts' | ||
import { | ||
createRegistryContract, | ||
RegistryContract, | ||
} from '../../../ethereum/registry' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
|
||
const cache: WeakMap<Provider, UndefinedOr<RegistryContract>> = new WeakMap() | ||
|
||
export const registryClientL1 = async ( | ||
provider: Provider | ||
): Promise<UndefinedOr<RegistryContract>> => { | ||
const res = | ||
cache.get(provider) ?? | ||
(await (async () => { | ||
const net = await provider.getNetwork() | ||
const l1Info = l1AvailableNetworks.find( | ||
({ chainId }) => chainId === net.chainId | ||
) | ||
const l1 = l1Info | ||
? createRegistryContract(provider)(l1Info.registry) | ||
: undefined | ||
const results = l1 | ||
// eslint-disable-next-line functional/no-expression-statement | ||
cache.set(provider, l1) | ||
return results | ||
})()) | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { addresses } from '../../addresses' | ||
|
||
export type L1AvailableNetwork = { | ||
readonly chainId: number | ||
readonly registry: string | ||
} | ||
|
||
export type L2AvailableNetwork = { | ||
readonly chainId: number | ||
readonly map: { | ||
readonly token: string | ||
readonly lockup: string | ||
readonly marketFactory: string | ||
readonly metricsFactory: string | ||
readonly policyFactory: string | ||
readonly propertyFactory: string | ||
readonly registry: string | ||
readonly sTokens: string | ||
readonly withdraw: string | ||
} | ||
} | ||
|
||
export const l1AvailableNetworks: readonly L1AvailableNetwork[] = [ | ||
{ chainId: 1, registry: addresses.eth.main.registry }, | ||
{ chainId: 3, registry: addresses.eth.ropsten.registry }, | ||
] | ||
|
||
export const l2AvailableNetworks: readonly L2AvailableNetwork[] = [ | ||
{ | ||
chainId: 42161, | ||
map: addresses.arbitrum.one, | ||
}, | ||
{ chainId: 421611, map: addresses.arbitrum.rinkeby }, | ||
{ chainId: 137, map: addresses.polygon.mainnet }, | ||
{ chainId: 80001, map: addresses.polygon.mumbai }, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { positionsCreate } from './positionsCreate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TransactionResponse } from '@ethersproject/abstract-provider' | ||
import { FallbackableOverrides } from '../common/utils/execute' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { UndefinedOr } from '@devprotocol/util-ts' | ||
|
||
type PositionsClaim = (options: { | ||
readonly provider: Provider | ||
readonly positionId: number | ||
readonly withdrawalAmount: string | ||
readonly overrides?: FallbackableOverrides | ||
}) => Promise<UndefinedOr<TransactionResponse>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { positionsCreate } from './positionsCreate' | ||
|
||
describe('positionsCreate.ts', () => { | ||
it.todo('TODO: Testing it') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TransactionResponse } from '@ethersproject/abstract-provider' | ||
import { FallbackableOverrides } from '../common/utils/execute' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { UndefinedOr } from '@devprotocol/util-ts' | ||
import { lockupClients } from './common/clients/lockupClients' | ||
|
||
type PositionsCreate = (options: { | ||
readonly provider: Provider | ||
readonly destination: string | ||
readonly amount: string | ||
readonly overrides?: FallbackableOverrides | ||
}) => Promise<UndefinedOr<TransactionResponse>> | ||
|
||
export const positionsCreate: PositionsCreate = async (options) => { | ||
const [l1, l2] = await lockupClients(options.provider) | ||
|
||
return l1 | ||
? l1.depositToProperty(options.destination, options.amount) | ||
: l2 | ||
? l2.depositToProperty(options.destination, options.amount) | ||
: undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { UndefinedOr } from '@devprotocol/util-ts' | ||
import { Positions } from '../ethereum/s-tokens/positions' | ||
|
||
type PositionsGet = (options: { | ||
readonly provider: Provider | ||
readonly positionId: number | ||
}) => Promise<UndefinedOr<Positions>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { UndefinedOr } from '@devprotocol/util-ts' | ||
import { Positions } from '../ethereum/s-tokens/positions' | ||
|
||
type PositionsList = (options: { | ||
readonly provider: Provider | ||
readonly destination?: string | ||
readonly user?: string | ||
}) => Promise<UndefinedOr<readonly Positions[]>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TransactionResponse } from '@ethersproject/abstract-provider' | ||
import { FallbackableOverrides } from '../common/utils/execute' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { UndefinedOr } from '@devprotocol/util-ts' | ||
|
||
type PositionsUpdate = (options: { | ||
readonly provider: Provider | ||
readonly positionId: number | ||
readonly additionalAmount: string | ||
readonly overrides?: FallbackableOverrides | ||
}) => Promise<UndefinedOr<TransactionResponse>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.