Skip to content

Commit 715ee43

Browse files
committed
replace wallet with provider
1 parent 52cff3c commit 715ee43

6 files changed

Lines changed: 25 additions & 41 deletions

File tree

lib/agent/lockup/calculateRewardAmount.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { getLockupContract } from './common'
22
import { Provider } from '@ethersproject/abstract-provider'
3-
import { Wallet } from 'ethers'
43

54
export type Options = {
6-
readonly wallet: Wallet
5+
readonly provider: Provider
76
readonly propertyAddress: string
87
}
98

@@ -14,7 +13,7 @@ type CalculateRewardAmount = (
1413
export const calculateRewardAmount: CalculateRewardAmount = async (
1514
options: Options
1615
): Promise<readonly [string, string] | Error> => {
17-
const lockupContract = await getLockupContract(options.wallet)
16+
const lockupContract = await getLockupContract(options.provider)
1817

1918
return lockupContract
2019
? await lockupContract.calculateRewardAmount(options.propertyAddress)

lib/agent/lockup/cap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { getLockupContract } from './common'
22
import { Provider } from '@ethersproject/abstract-provider'
3-
import { Wallet } from 'ethers'
3+
44
type Options = {
5-
readonly wallet: Wallet
5+
readonly provider: Provider
66
}
77

88
type GetCap = (Options: Options) => Promise<string | Error>
99

1010
export const getCap: GetCap = async (
1111
options: Options
1212
): Promise<string | Error> => {
13-
const lockupContract = await getLockupContract(options.wallet)
13+
const lockupContract = await getLockupContract(options.provider)
1414

1515
return lockupContract
1616
? await lockupContract.cap()

lib/agent/lockup/common.spec.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ describe('common.ts', () => {
1818
testProviders.homestead
1919
)(addresses.eth['main'].registry).lockup()
2020
const expected = await expectedLockup(lockupAddress)
21-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.homestead)
22-
const result = await getLockupContract(wallet)
21+
const result = await getLockupContract(testProviders.homestead)
2322
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected))
2423
})
2524
it('provider is ropsten', async () => {
@@ -28,24 +27,21 @@ describe('common.ts', () => {
2827
addresses.eth['ropsten'].registry
2928
).lockup()
3029
const expected = await expectedLockup(lockupAddress)
31-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.ropsten)
32-
const result = await getLockupContract(wallet)
30+
const result = await getLockupContract(testProviders.ropsten)
3331
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected))
3432
})
3533
it('provider is arbitrum one', async () => {
3634
const expectedLockup = await createLockupContractL2(testProviders.arbOne)
3735
const expected = await expectedLockup(arbitrumOneLockup)
38-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.arbOne)
39-
const result = await getLockupContract(wallet)
36+
const result = await getLockupContract(testProviders.arbOne)
4037
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected))
4138
})
4239
it('provider is arbitrum rinkeby', async () => {
4340
const expectedLockup = await createLockupContractL2(
4441
testProviders.arbRinkeby
4542
)
4643
const expected = await expectedLockup(arbitrumRinkebyLockup)
47-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.arbRinkeby)
48-
const result = await getLockupContract(wallet)
44+
const result = await getLockupContract(testProviders.arbRinkeby)
4945
expect(JSON.stringify(result)).toEqual(JSON.stringify(expected))
5046
})
5147
it('use cache', async () => {
@@ -54,16 +50,14 @@ describe('common.ts', () => {
5450
addresses.eth['ropsten'].registry
5551
).lockup()
5652
const expected = await expectedLockup(lockupAddress)
57-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.ropsten)
58-
const result1 = await getLockupContract(wallet)
59-
const result2 = await getLockupContract(wallet)
53+
const result1 = await getLockupContract(testProviders.ropsten)
54+
const result2 = await getLockupContract(testProviders.ropsten)
6055
expect(JSON.stringify(result1)).toEqual(JSON.stringify(expected))
6156
expect(JSON.stringify(result2)).toEqual(JSON.stringify(expected))
6257
})
6358
it('provider is unknown', async () => {
6459
const expected = undefined
65-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.polyMumbai)
66-
const result = await getLockupContract(wallet)
60+
const result = await getLockupContract(testProviders.polyMumbai)
6761
expect(result).toEqual(expected)
6862
})
6963
})

lib/agent/lockup/common.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ import {
1212
LockupContract as LockupContractL2,
1313
} from '../../l2/lockup/index'
1414
import { Network } from '@ethersproject/networks'
15-
import { Wallet } from 'ethers'
15+
import { Provider } from '@ethersproject/abstract-provider'
16+
import { Signer } from '@ethersproject/abstract-signer'
1617

1718
const cacheLockupContract = new WeakMap()
1819

1920
export const getLockupContract = async (
20-
wallet: Wallet
21+
provider: Provider
2122
): Promise<LockupContract | LockupContractL2 | undefined> => {
22-
const network = await wallet.provider.getNetwork()
23+
const network = await provider.getNetwork()
2324
return cacheLockupContract.has(network)
2425
? cacheLockupContract.get(network)
25-
: generateLockupContract(wallet)
26+
: generateLockupContract(provider)
2627
}
2728

2829
const generateLockupContract = async (
29-
wallet: Wallet
30+
provider: Provider
3031
): Promise<LockupContract | LockupContractL2 | undefined> => {
31-
const provider = wallet.provider
3232
const network = await provider.getNetwork()
3333
const chainId = network.chainId
3434
const lockupContract = (await isL1(chainId))
35-
? createLockupContract(wallet)
36-
: createLockupContractL2(wallet)
35+
? createLockupContract(provider)
36+
: createLockupContractL2(provider)
3737

3838
const lockupAddress = (await isL1(chainId))
3939
? await getL1ContractAddress(provider, 'lockup')

lib/agent/lockup/positionsCreate.spec.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ describe('positionsCreate.ts', () => {
1212
}
1313

1414
it('', async () => {
15-
// await window.ethereum.enable()
16-
const wallet = new ethers.Wallet(env.mnemonic, testProviders.ropsten)
17-
console.log(wallet)
1815
const options: Options = {
19-
wallet,
16+
provider: testProviders.ropsten,
2017
propertyAddress,
2118
amount,
2219
overrides,
@@ -27,7 +24,7 @@ describe('positionsCreate.ts', () => {
2724
it('return undefined if network is not valid', async () => {
2825
const wallet = new ethers.Wallet(env.mnemonic, testProviders.polyMumbai)
2926
const options: Options = {
30-
wallet,
27+
provider: testProviders.polyMumbai,
3128
propertyAddress,
3229
amount,
3330
overrides,
@@ -36,9 +33,3 @@ describe('positionsCreate.ts', () => {
3633
expect(tx).toEqual(undefined)
3734
})
3835
})
39-
40-
// declare global {
41-
// interface Window {
42-
// ethereum: any;
43-
// }
44-
// }

lib/agent/lockup/positionsCreate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { TransactionResponse } from '@ethersproject/abstract-provider'
22
import { getLockupContract } from './common'
33
import { Provider } from '@ethersproject/abstract-provider'
44
import { FallbackableOverrides } from '../../common/utils/execute'
5-
import { Wallet } from 'ethers'
5+
66

77
export type Options = {
8-
readonly wallet: Wallet
8+
readonly provider: Provider,
99
readonly propertyAddress: string
1010
readonly amount: string
1111
readonly overrides?: FallbackableOverrides
@@ -18,7 +18,7 @@ type PositionsCreate = (
1818
export const positionsCreate: PositionsCreate = async (
1919
options: Options
2020
): Promise<TransactionResponse | undefined> => {
21-
const lockupContract = await getLockupContract(options.wallet)
21+
const lockupContract = await getLockupContract(options.provider)
2222

2323
return lockupContract
2424
? await lockupContract.depositToProperty(

0 commit comments

Comments
 (0)