Skip to content

Commit 6c6c2a6

Browse files
committed
wip
1 parent be4ed3a commit 6c6c2a6

File tree

13 files changed

+84
-56
lines changed

13 files changed

+84
-56
lines changed

lib/agent/common/approveIfNeeded.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
TransactionReceipt,
66
} from '@ethersproject/abstract-provider'
77
import type { BaseProvider } from '@ethersproject/providers'
8-
import { BigNumber } from 'ethers'
98
import { createErc20Contract } from '../../common/erc20'
109
import { FallbackableOverrides } from '../../common/utils/execute'
1110
import { clientsDev } from './clients/clientsDev'
@@ -63,7 +62,7 @@ export const approveIfNeeded: ApproveIfNeeded = async (factoryOptions) => {
6362
)
6463

6564
return whenDefinedAll([client, factoryOptions.to], ([dev, to]) => {
66-
return BigNumber.from(allowance).lt(factoryOptions.requiredAmount)
65+
return BigInt(allowance ?? 0) < BigInt(factoryOptions.requiredAmount)
6766
? ({
6867
approvalNeeded: true,
6968
approveIfNeeded: async (options) => {

lib/agent/estimationsAPY.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { UndefinedOr, whenDefined, whenDefinedAll } from '@devprotocol/util-ts'
44
import { clientsMetricsFactory } from './common/clients/clientsMetricsFactory'
55
import { clientsMetricsGroup } from './common/clients/clientsMetricsGroup'
66
import { clientsPolicy } from './common/clients/clientsPolicy'
7-
import { BigNumber as BN } from 'ethers'
87
import { BigNumber } from 'bignumber.js'
98

109
type EstimationsAPY = (options: {
@@ -36,8 +35,9 @@ export const estimationsAPY: EstimationsAPY = async (options) => {
3635
[tvl, yeild, l1P || l2P],
3736
([_tvl, y, policy]) => policy.holdersShare(y, _tvl)
3837
)
39-
const annualYeild = whenDefined(yeild, (y) =>
40-
BN.from(y).mul(l1P ? BN.from(2102400) : BN.from(31536000))
38+
const annualYeild = whenDefined(
39+
yeild,
40+
(y) => BigInt(y) * (l1P ? BigInt(2102400) : BigInt(31536000))
4141
)
4242
const shareOfHolders = whenDefinedAll([holders, yeild], ([hol, y]) =>
4343
new BigNumber(hol).div(y).toNumber()

lib/agent/fixtures/swap/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ethers } from 'ethers'
2-
import type { BaseProvider } from '@ethersproject/providers'
1+
import { ContractRunner, ethers } from 'ethers'
32
import { swapAbiV2 } from './abi-v2'
43
import { swapAbiV3 } from './abi-v3'
54
import { createGetEstimatedDevForEthCaller } from './getEstimatedDevForEth'
@@ -35,7 +34,7 @@ export type SwapContract = {
3534
}
3635

3736
export const createSwapContract =
38-
(provider: BaseProvider, v: 'v2' | 'v3' | 'v3_polygon' = 'v3') =>
37+
(provider: ContractRunner, v: 'v2' | 'v3' | 'v3_polygon' = 'v3') =>
3938
(address: string): SwapContract => {
4039
const contract = new ethers.Contract(
4140
address,

lib/agent/fixtures/swap/swapEthAndStakeDev.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2-
import { ethers } from 'ethers'
2+
import { ZeroHash, ethers } from 'ethers'
33
import {
44
execute,
55
FallbackableOverrides,
@@ -33,15 +33,11 @@ export const createSwapEthAndStakeDevCaller: CreateSwapEthAndStakeDevCaller =
3333
? [
3434
propertyAddress,
3535
String(deadline),
36-
payload ?? ethers.constants.HashZero,
36+
payload ?? ZeroHash,
3737
gatewayAddress,
3838
gatewayBasisPoints,
3939
]
40-
: [
41-
propertyAddress,
42-
String(deadline),
43-
payload ?? ethers.constants.HashZero,
44-
]
40+
: [propertyAddress, String(deadline), payload ?? ZeroHash]
4541

4642
return execute<MutationOption>({
4743
contract,

lib/agent/positionsCreate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const positionsCreate: PositionsCreate = async (options) => {
2525
provider: options.provider,
2626
requiredAmount: options.amount,
2727
from: options.from,
28-
to: ((x) => x?.contract().address)(l1 ?? l2),
28+
to: await ((x) => x?.contract().getAddress())(l1 ?? l2),
2929
callback: (receipt) =>
3030
l1
3131
? l1.depositToProperty(

lib/agent/positionsCreateWithEth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FallbackableOverrides } from '../common/utils/execute'
33
import type { BaseProvider } from '@ethersproject/providers'
44
import { clientsUtilsSwapForStake } from './common/clients/clientsUtilsSwapForStake'
55
import { TransactionResponse } from '@ethersproject/abstract-provider'
6-
import { constants } from 'ethers'
6+
import { ZeroHash } from 'ethers'
77

88
type PositionsCreateWithEth = (options: {
99
readonly provider: BaseProvider
@@ -55,15 +55,15 @@ export const positionsCreateWithEth: PositionsCreateWithEth = async (
5555
? await l2.swapEthAndStakeDevCaller(
5656
options.destination,
5757
deadline,
58-
options.payload ?? constants.HashZero,
58+
options.payload ?? ZeroHash,
5959
_overrides,
6060
options.gatewayAddress,
6161
String(options.gatewayBasisPoints)
6262
)
6363
: await l2.swapEthAndStakeDevCaller(
6464
options.destination,
6565
deadline,
66-
options.payload ?? constants.HashZero,
66+
options.payload ?? ZeroHash,
6767
_overrides
6868
)
6969
},

lib/agent/positionsCreateWithEthForPolygon.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { FallbackableOverrides } from '../common/utils/execute'
33
import type { BaseProvider } from '@ethersproject/providers'
44
import { clientsUtilsSwapForStake } from './common/clients/clientsUtilsSwapForStake'
5-
import { constants } from 'ethers'
5+
import { ZeroHash } from 'ethers'
66
import {
77
approveIfNeeded,
88
ApproveIfNeededResult,
@@ -57,7 +57,7 @@ export const positionsCreateWithEth: PositionsCreateWithEthForPolygon = async (
5757
requiredAmount: ethAmount,
5858
from,
5959
token: weth,
60-
to: l2.contract().address,
60+
to: await l2.contract().getAddress(),
6161
callback: async () => {
6262
const deadline = options.deadline
6363
? options.deadline
@@ -67,7 +67,7 @@ export const positionsCreateWithEth: PositionsCreateWithEthForPolygon = async (
6767
options.destination,
6868
ethAmount,
6969
deadline,
70-
options.payload ?? constants.HashZero,
70+
options.payload ?? ZeroHash,
7171
_overrides,
7272
options.gatewayAddress,
7373
String(options.gatewayBasisPoints)
@@ -76,7 +76,7 @@ export const positionsCreateWithEth: PositionsCreateWithEthForPolygon = async (
7676
options.destination,
7777
ethAmount,
7878
deadline,
79-
options.payload ?? constants.HashZero,
79+
options.payload ?? ZeroHash,
8080
_overrides
8181
)
8282
},

lib/agent/propertiesAssets.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ export const propertiesAssets: PropertiesAssets = async (options) => {
5252
const results = await whenDefined(marketBehaviors, (mb) =>
5353
Promise.all(
5454
mb.map(async (cont) => {
55-
const metrics = cont.metrics.contract().address
56-
const market = cont.market.contract().address
55+
const [metrics, market] = await Promise.all([
56+
cont.metrics.contract().getAddress(),
57+
cont.market.contract().getAddress(),
58+
])
5759
const marketSlug = marketSet.find(([, addr]) => addr === market)?.[0]
5860
return {
5961
id: await cont.marketBehavior.getId(metrics),

lib/common/erc20/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ethers } from 'ethers'
2-
import type { BaseProvider } from '@ethersproject/providers'
1+
import { ContractRunner, ethers } from 'ethers'
32
import { erc20Abi } from './abi'
43
import { createTransferCaller } from './transfer'
54
import { createBalanceOfCaller } from './balanceOf'
@@ -39,7 +38,7 @@ export type Erc20Contract = {
3938
}
4039

4140
export const createErc20Contract =
42-
(provider: BaseProvider) =>
41+
(provider: ContractRunner) =>
4342
(address: string): Erc20Contract => {
4443
const contract = new ethers.Contract(address, [...erc20Abi], provider)
4544

lib/common/utils/execute.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ethers, BigNumber, providers, utils } from 'ethers'
1+
import { ethers, keccak256 } from 'ethers'
22
import { TransactionResponse } from '@ethersproject/abstract-provider'
33
import { keys, mergeAll } from 'ramda'
44

@@ -67,10 +67,9 @@ const pad = (
6767
)
6868

6969
type Value = boolean | string | number
70-
type ValueWithBigNumber = Value | BigNumber
71-
const isBigNumber = (data: unknown): data is BigNumber =>
72-
BigNumber.isBigNumber(data)
73-
const toString = (data: Readonly<BigNumber>): string => data.toString()
70+
type ValueWithBigNumber = Value | bigint
71+
const isBigNumber = (data: unknown): data is bigint => data instanceof BigInt
72+
const toString = (data: Readonly<bigint>): string => data.toString()
7473
const toStringObj = (
7574
data: Readonly<Record<string, ValueWithBigNumber>>
7675
): Record<string, Value> => {
@@ -115,17 +114,11 @@ export const execute: ExecuteFunction = async <
115114
>(
116115
opts: O
117116
) => {
118-
const signer =
119-
typeof (opts.contract?.provider as SignableProvider)?.getSigner ===
120-
'function'
121-
? (opts.contract.provider as SignableProvider).getSigner()
122-
: undefined
123-
const contract =
124-
opts.mutation && signer ? opts.contract.connect(signer) : opts.contract
117+
const contract = opts.contract
125118
const convertedArgs: ArgsWithoutUint8Array | undefined =
126119
opts.args === undefined
127120
? undefined
128-
: opts.args.map((v) => (v instanceof Uint8Array ? utils.keccak256(v) : v))
121+
: opts.args.map((v) => (v instanceof Uint8Array ? keccak256(v) : v))
129122
const args =
130123
convertedArgs === undefined
131124
? undefined
@@ -137,17 +130,16 @@ export const execute: ExecuteFunction = async <
137130
? [...(args || []), opts.overrides.overrides]
138131
: args
139132
const singleMethod = opts.static
140-
? contract.callStatic[opts.method]
133+
? contract[opts.method].staticCall
141134
: contract[opts.method]
142-
const overloadedMethod = singleMethod
143-
? undefined
144-
: ((name) => (opts.static ? contract.callStatic[name] : contract[name]))(
145-
String(
146-
keys(contract.functions).find(
147-
(fn: string | number) => fn === `${opts.method}(${opts.interface})`
148-
)
149-
)
150-
)
135+
const overloadedMethod = ((name) =>
136+
opts.static ? contract[name].staticCall : contract[name])(
137+
String(
138+
keys(contract.functions).find(
139+
(fn: string | number) => fn === `${opts.method}(${opts.interface})`
140+
)
141+
)
142+
)
151143
const method = singleMethod ?? overloadedMethod
152144
const res = await (argsOverrided === undefined
153145
? method()

0 commit comments

Comments
 (0)