Skip to content

Commit

Permalink
fix: small fixes (use address in price handler) CurveV1Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Verisana committed Nov 8, 2022
1 parent 4ac469e commit 874ae7e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
17 changes: 12 additions & 5 deletions src/dex/curve-v1-factory/curve-v1-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class CurveV1Factory
baseImplementationName = customBasePool.name;
}
}
acc[curr.name] = new PriceHandler(
acc[curr.address] = new PriceHandler(
this.logger,
curr.name,
baseImplementationName,
Expand Down Expand Up @@ -184,7 +184,7 @@ export class CurveV1Factory
_.range(0, nCoins).map(i => ({
target: customPool.address,
callData: this.abiCoder.encodeFunctionCall(
this._getCoinsABI('arg0', customPool.coinsInputType),
this._getCoinsABI(customPool.coinsInputType),
[i.toString()],
),
decodeFunction: addressDecode,
Expand Down Expand Up @@ -489,6 +489,7 @@ export class CurveV1Factory
this.logger,
this.dexKey,
factoryImplementationFromConfig.name,
implementationAddress.toLowerCase(),
poolAddresses[i],
factoryAddress,
poolIdentifier,
Expand Down Expand Up @@ -623,10 +624,17 @@ export class CurveV1Factory
return null;
}

if (state.balances.every(b => b === 0n)) {
this.logger.trace(
`${this.dexKey} on ${this.dexHelper.config.data.network}: State balances equal to 0 in pool ${pool.address}`,
);
return null;
}

const poolData = pool.getPoolData(srcTokenAddress, destTokenAddress);

let outputs: bigint[] = this.poolManager
.getPriceHandler(pool.implementationName)
.getPriceHandler(pool.implementationAddress)
.getOutputs(
state,
amountsWithUnitAndFee,
Expand Down Expand Up @@ -841,9 +849,8 @@ export class CurveV1Factory
);
}

private _getCoinsABI(name: string, type: string): AbiItem {
private _getCoinsABI(type: string): AbiItem {
const newCoinsType = _.cloneDeep(this.coinsTypeTemplate);
newCoinsType.inputs![0].name = name;
newCoinsType.inputs![0].type = type;
return newCoinsType;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dex/curve-v1-factory/curve-v1-pool-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export class CurveV1FactoryPoolManager {
);
}

getPriceHandler(implementationName: string): PriceHandler {
return this.allPriceHandlers[implementationName];
getPriceHandler(implementationAddress: string): PriceHandler {
return this.allPriceHandlers[implementationAddress];
}

releaseResources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const customAvalanche3CoinLending: _calc_withdraw_one_coin = (
_token_amount: bigint,
i: number,
) => {
const { N_COINS, BI_N_COINS, FEE_DENOMINATOR, PRECISION } = self.constants;
const { N_COINS, BI_N_COINS, FEE_DENOMINATOR } = self.constants;
const PRECISION_MUL = requireConstant(self, 'PRECISION_MUL', funcName());
const offpeg_fee_multiplier = requireValue(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/dex/curve-v1-factory/price-handlers/functions/_xp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const implementations: Record<ImplementationNames, _xp> = {
[ImplementationNames.CUSTOM_AVALANCHE_3COIN_LENDING]: notExist,

[ImplementationNames.CUSTOM_FANTOM_2COIN_BTC]: customPlain2CoinFrax,
[ImplementationNames.CUSTOM_FANTOM_2COIN_USD]: notExist,
[ImplementationNames.CUSTOM_FANTOM_2COIN_USD]: customPlain2CoinFrax,
[ImplementationNames.CUSTOM_FANTOM_3COIN_LENDING]: notExist,

[ImplementationNames.CUSTOM_OPTIMISM_3COIN_USD]: notExist,
Expand Down
4 changes: 2 additions & 2 deletions src/dex/curve-v1-factory/price-handlers/functions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const requireConstant = <T extends keyof PoolContextConstants>(
funcName: string,
): NonNullable<PoolContextConstants[T]> => {
const value = self.constants[constantName];
if (!value) {
if (value === undefined) {
throw new Error(
`Required constant ${constantName} was not specified for function ` +
`${funcName} in ${self.IMPLEMENTATION_NAME} implementation`,
Expand All @@ -44,7 +44,7 @@ export const requireValue = <T extends keyof PoolState>(
funcName: string,
): NonNullable<PoolState[T]> => {
const value = state[stateVarName];
if (!value) {
if (value === undefined) {
throw new Error(
`Required state value ${stateVarName} was not specified for function ` +
`${funcName} in ${self.IMPLEMENTATION_NAME} implementation`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
logger,
dexKey,
implementationName,
address,
poolIdentifier,
poolConstants,
address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export class FactoryStateHandler extends PoolPollingBase {
readonly logger: Logger,
readonly dexKey: string,
readonly implementationName: FactoryImplementationNames,
implementationAddress: Address,
readonly address: Address,
readonly factoryAddress: Address,
readonly poolIdentifier: string,
readonly poolConstants: PoolConstants,
readonly poolContextConstants: PoolContextConstants,
readonly isSrcFeeOnTransferSupported: boolean,
private basePoolStateFetcher?: PoolPollingBase,
baseStatePoolPolling?: PoolPollingBase,
private factoryIface: Interface = new Interface(
FactoryCurveV1ABI as JsonFragment[],
),
Expand All @@ -35,16 +36,17 @@ export class FactoryStateHandler extends PoolPollingBase {
logger,
dexKey,
implementationName,
implementationAddress,
poolIdentifier,
poolConstants,
address,
'/factory',
false,
basePoolStateFetcher,
baseStatePoolPolling,
isSrcFeeOnTransferSupported,
);

if (this.isMetaPool && this.basePoolStateFetcher === undefined) {
if (this.isMetaPool && this.baseStatePoolPolling === undefined) {
throw new Error(
`${this.fullName}: is instantiated with error. basePoolStateFetcher is not provided`,
);
Expand Down Expand Up @@ -105,7 +107,7 @@ export class FactoryStateHandler extends PoolPollingBase {
let basePoolState: PoolState | undefined;
if (this.isMetaPool) {
// Check for undefined done in constructor
const retrievedBasePoolState = this.basePoolStateFetcher!.getState();
const retrievedBasePoolState = this.baseStatePoolPolling!.getState();

if (retrievedBasePoolState === null) {
this.logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export abstract class PoolPollingBase {
readonly logger: Logger,
readonly dexKey: string,
readonly implementationName: string,
readonly implementationAddress: Address,
readonly poolIdentifier: string,
readonly poolConstants: PoolConstants,
readonly address: Address,
Expand Down

0 comments on commit 874ae7e

Please sign in to comment.