Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

feat(investor-foxy): rename amountDesired -> amountDesiredCryptoBaseUnit #1131

Draft
wants to merge 2 commits into
base: feat_investor_foxy_ethers_js_batch_provider
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions packages/investor-foxy/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ export class FoxyApi {
}

async estimateAddLiquidityGas(input: EstimateGasTxInput): Promise<string> {
const { amountDesired, userAddress, contractAddress } = input
const { amountDesiredCryptoBaseUnit, userAddress, contractAddress } = input
this.verifyAddresses([userAddress, contractAddress])
if (!amountDesired.gt(0)) throw new Error('Must send valid amount')
if (!amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress)

try {
const estimatedGas = await liquidityReserveContract.estimateGas.addLiquidity(
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
{ from: userAddress },
)
return estimatedGas.toString()
Expand All @@ -299,15 +299,15 @@ export class FoxyApi {
}

async estimateRemoveLiquidityGas(input: EstimateGasTxInput): Promise<string> {
const { amountDesired, userAddress, contractAddress } = input
const { amountDesiredCryptoBaseUnit, userAddress, contractAddress } = input
this.verifyAddresses([userAddress, contractAddress])
if (!amountDesired.gt(0)) throw new Error('Must send valid amount')
if (!amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress)

try {
const estimatedGas = await liquidityReserveContract.estimateGas.removeLiquidity(
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
{ from: userAddress },
)
return estimatedGas.toString()
Expand All @@ -317,18 +317,18 @@ export class FoxyApi {
}

async estimateWithdrawGas(input: WithdrawEstimateGasInput): Promise<string> {
const { amountDesired, userAddress, contractAddress, type } = input
const { amountDesiredCryptoBaseUnit, userAddress, contractAddress, type } = input
this.verifyAddresses([userAddress, contractAddress])

const stakingContract = this.getStakingContract(contractAddress)

const isDelayed = type === WithdrawType.DELAYED && amountDesired
if (isDelayed && !amountDesired.gt(0)) throw new Error('Must send valid amount')
const isDelayed = type === WithdrawType.DELAYED && amountDesiredCryptoBaseUnit
if (isDelayed && !amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

try {
const estimatedGas = isDelayed
? await stakingContract.estimateGas['unstake(uint256,bool)'](
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
true,
{ from: userAddress },
)
Expand Down Expand Up @@ -358,15 +358,15 @@ export class FoxyApi {
}

async estimateDepositGas(input: EstimateGasTxInput): Promise<string> {
const { amountDesired, userAddress, contractAddress } = input
const { amountDesiredCryptoBaseUnit, userAddress, contractAddress } = input
this.verifyAddresses([userAddress, contractAddress])
if (!amountDesired.gt(0)) throw new Error('Must send valid amount')
if (!amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

const stakingContract = this.getStakingContract(contractAddress)

try {
const estimatedGas = await stakingContract.estimateGas['stake(uint256)'](
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
{ from: userAddress },
)
return estimatedGas.toString()
Expand Down Expand Up @@ -436,15 +436,15 @@ export class FoxyApi {

async deposit(input: TxInput): Promise<string> {
const {
amountDesired,
amountDesiredCryptoBaseUnit,
bip44Params,
dryRun = false,
contractAddress,
userAddress,
wallet,
} = input
this.verifyAddresses([userAddress, contractAddress])
if (!amountDesired.gt(0)) throw new Error('Must send valid amount')
if (!amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')
if (!wallet) throw new Error('Missing inputs')

let estimatedGas: string
Expand All @@ -457,7 +457,7 @@ export class FoxyApi {
const stakingContract = this.getStakingContract(contractAddress)

const data = stakingContract.interface.encodeFunctionData('stake(uint256,address)', [
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
userAddress,
])

Expand All @@ -478,7 +478,7 @@ export class FoxyApi {

async withdraw(input: WithdrawInput): Promise<string> {
const {
amountDesired,
amountDesiredCryptoBaseUnit,
bip44Params,
dryRun = false,
contractAddress,
Expand All @@ -498,13 +498,13 @@ export class FoxyApi {

const stakingContract = this.getStakingContract(contractAddress)

const isDelayed = type === WithdrawType.DELAYED && amountDesired
if (isDelayed && !amountDesired.gt(0)) throw new Error('Must send valid amount')
const isDelayed = type === WithdrawType.DELAYED && amountDesiredCryptoBaseUnit
if (isDelayed && !amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

const stakingContractCallInput: Parameters<
typeof stakingContract.interface.encodeFunctionData
> = isDelayed
? ['unstake(uint256,bool)', [this.normalizeAmount(amountDesired), true]]
? ['unstake(uint256,bool)', [this.normalizeAmount(amountDesiredCryptoBaseUnit), true]]
: ['instantUnstake', ['true']]
const data: string = stakingContract.interface.encodeFunctionData(...stakingContractCallInput)

Expand Down Expand Up @@ -754,15 +754,15 @@ export class FoxyApi {
// utility function for the dao to add liquidity to the lrContract for instantUnstaking
async addLiquidity(input: TxInput): Promise<string> {
const {
amountDesired,
amountDesiredCryptoBaseUnit,
bip44Params,
dryRun = false,
contractAddress,
userAddress,
wallet,
} = input
this.verifyAddresses([userAddress, contractAddress])
if (!amountDesired.gt(0)) throw new Error('Must send valid amount')
if (!amountDesiredCryptoBaseUnit.gt(0)) throw new Error('Must send valid amount')

if (!wallet) throw new Error('Missing inputs')

Expand All @@ -776,7 +776,7 @@ export class FoxyApi {
const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress)

const data: string = liquidityReserveContract.interface.encodeFunctionData('addLiquidity', [
this.normalizeAmount(amountDesired),
this.normalizeAmount(amountDesiredCryptoBaseUnit),
])

const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress)
Expand All @@ -798,7 +798,7 @@ export class FoxyApi {
// utility function for the dao to remove liquidity to the lrContract for instantUnstaking
async removeLiquidity(input: TxInput): Promise<string> {
const {
amountDesired,
amountDesiredCryptoBaseUnit: amountDesired,
bip44Params,
dryRun = false,
contractAddress,
Expand Down
13 changes: 8 additions & 5 deletions packages/investor-foxy/src/api/foxy-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ export type TxInput = {
userAddress: string
contractAddress: string
wallet: HDWallet
amountDesired: BigNumber
amountDesiredCryptoBaseUnit: BigNumber
}

export type TxInputWithoutAmount = Pick<TxInput, Exclude<keyof TxInput, 'amountDesired'>>
export type TxInputWithoutAmount = Pick<
TxInput,
Exclude<keyof TxInput, 'amountDesiredCryptoBaseUnit'>
>

export type TxInputWithoutAmountAndWallet = Pick<
TxInputWithoutAmount,
Exclude<keyof TxInputWithoutAmount, 'wallet'>
>

export type WithdrawInput = Omit<TxInput, 'amountDesired'> & {
export type WithdrawInput = Omit<TxInput, 'amountDesiredCryptoBaseUnit'> & {
type: WithdrawType
amountDesired?: BigNumber
amountDesiredCryptoBaseUnit?: BigNumber
}

export type WithdrawEstimateGasInput = Omit<WithdrawInput, 'wallet'>
Expand All @@ -71,7 +74,7 @@ export type FoxyOpportunityInputData = {

export type EstimateGasTxInput = Pick<
TxInput,
'tokenContractAddress' | 'contractAddress' | 'userAddress' | 'amountDesired'
'tokenContractAddress' | 'contractAddress' | 'userAddress' | 'amountDesiredCryptoBaseUnit'
>

export type BalanceInput = {
Expand Down
8 changes: 4 additions & 4 deletions packages/investor-foxy/src/foxycli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const main = async (): Promise<void> => {
console.info('staking...')
const response = await api.deposit({
contractAddress: foxyStakingContractAddress,
amountDesired: bnOrZero(amount),
amountDesiredCryptoBaseUnit: bnOrZero(amount),
userAddress,
wallet,
bip44Params: {
Expand All @@ -144,7 +144,7 @@ const main = async (): Promise<void> => {
console.info('unstaking...')
const response = await api.withdraw({
contractAddress: foxyStakingContractAddress,
amountDesired: bnOrZero(amount),
amountDesiredCryptoBaseUnit: bnOrZero(amount),
type: WithdrawType.DELAYED,
userAddress,
wallet,
Expand Down Expand Up @@ -206,7 +206,7 @@ const main = async (): Promise<void> => {
const response = await api.addLiquidity({
contractAddress: liquidityReserveContractAddress,
userAddress,
amountDesired: bnOrZero(amount),
amountDesiredCryptoBaseUnit: bnOrZero(amount),
wallet,
bip44Params: {
accountNumber: 0,
Expand All @@ -226,7 +226,7 @@ const main = async (): Promise<void> => {
const response = await api.removeLiquidity({
contractAddress: liquidityReserveContractAddress,
userAddress,
amountDesired: bnOrZero(amount),
amountDesiredCryptoBaseUnit: bnOrZero(amount),
wallet,
bip44Params: {
accountNumber: 0,
Expand Down