Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 fix - config map key to lowercase #191

Merged
merged 5 commits into from
Apr 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ export class AaveV3CollateralConfigMap
collateral: IToken
collateralConfig: IAaveV3CollateralConfig
}): void {
this.record[params.collateral.address.value] = AaveV3CollateralConfig.createFrom(
params.collateralConfig,
)
this.record[this._formatRecordKey(params.collateral.address.value)] =
AaveV3CollateralConfig.createFrom(params.collateralConfig)
}

public override get(params: { token: IToken }): Maybe<AaveV3CollateralConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export class AaveV3DebtConfigMap extends DebtConfigMap implements IAaveV3DebtCon
}

public override add(params: { debt: IToken; debtConfig: IAaveV3DebtConfig }): void {
this.record[params.debt.address.value] = AaveV3DebtConfig.createFrom(params.debtConfig)
this.record[this._formatRecordKey(params.debt.address.value)] = AaveV3DebtConfig.createFrom(
params.debtConfig,
)
}

public override get(params: { token: IToken }): Maybe<AaveV3DebtConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ export class MakerCollateralConfigMap
collateral: IToken
collateralConfig: IMakerCollateralConfig
}): void {
this.record[params.collateral.address.value] = MakerCollateralConfig.createFrom(
params.collateralConfig,
)
this.record[this._formatRecordKey(params.collateral.address.value)] =
MakerCollateralConfig.createFrom(params.collateralConfig)
}

public override get(params: { token: IToken }): Maybe<MakerCollateralConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export class MakerDebtConfigMap extends DebtConfigMap implements IMakerDebtConfi
}

public override add(params: { debt: IToken; debtConfig: IMakerDebtConfig }): void {
this.record[params.debt.address.value] = MakerDebtConfig.createFrom(params.debtConfig)
this.record[this._formatRecordKey(params.debt.address.value)] = MakerDebtConfig.createFrom(
params.debtConfig,
)
}

public override get(params: { token: IToken }): Maybe<MakerDebtConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ export class SparkCollateralConfigMap
collateral: IToken
collateralConfig: ISparkCollateralConfig
}): void {
this.record[params.collateral.address.value] = SparkCollateralConfig.createFrom(
params.collateralConfig,
)
this.record[this._formatRecordKey(params.collateral.address.value)] =
SparkCollateralConfig.createFrom(params.collateralConfig)
}

public override get(params: { token: IToken }): Maybe<SparkCollateralConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export class SparkDebtConfigMap extends DebtConfigMap implements ISparkDebtConfi
}

public override add(params: { debt: IToken; debtConfig: ISparkDebtConfig }): void {
this.record[params.debt.address.value] = SparkDebtConfig.createFrom(params.debtConfig)
this.record[this._formatRecordKey(params.debt.address.value)] = SparkDebtConfig.createFrom(
params.debtConfig,
)
}

public override get(params: { token: IToken }): Maybe<SparkDebtConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}
}

Expand Down
19 changes: 17 additions & 2 deletions sdk/protocol-plugins/tests/integration/SparkProtocolPlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {
TokenAmount,
Percentage,
} from '@summerfi/sdk-common/common'
import { SparkProtocolPlugin } from '../../src/plugins/spark'
import { SparkLendingPool, SparkProtocolPlugin } from '../../src/plugins/spark'
import { sparkPoolIdMock as validSparkPoolId } from '../mocks/SparkPoolIdMock'
import { createProtocolPluginContext } from '../utils/CreateProtocolPluginContext'

describe('Spark Protocol Plugin (Integration)', () => {
let ctx: IProtocolPluginContext
let sparkProtocolPlugin: SparkProtocolPlugin
let pool: SparkLendingPool
beforeAll(async () => {
ctx = await createProtocolPluginContext()
sparkProtocolPlugin = new SparkProtocolPlugin({
Expand Down Expand Up @@ -84,7 +85,7 @@ describe('Spark Protocol Plugin (Integration)', () => {
})

it('correctly populates debt configuration from blockchain data', async () => {
const pool = await sparkProtocolPlugin.getPool(validSparkPoolId)
pool = await sparkProtocolPlugin.getPool(validSparkPoolId)

const mockDebtToken = Token.createFrom({
chainInfo: ChainInfo.createFrom({ chainId: 1, name: 'Ethereum' }),
Expand Down Expand Up @@ -146,4 +147,18 @@ describe('Spark Protocol Plugin (Integration)', () => {
const originationFee = config!.originationFee
expect(originationFee).toBeInstanceOf(Percentage)
})

it('resolves config maps for tokens sent with addresses in alternative formats', async () => {
const mockCollateralToken = Token.createFrom({
chainInfo: ChainInfo.createFrom({ chainId: 1, name: 'Ethereum' }),
// NOTE: Address is different format to that expected by the protocol
address: Address.createFromEthereum({ value: '0xae78736cd615f374d3085123a210448e74fc6393' }),
symbol: 'RETH',
name: 'Rocket Ether',
decimals: 18,
})

const config = pool.collaterals.get({ token: mockCollateralToken })
expect(config).toBeDefined()
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HexData } from '../../common/aliases/HexData'
import { AddressValue } from '../../common/aliases/AddressValue'
import { Maybe } from '../../common/aliases/Maybe'
import { IToken } from '../../common/interfaces/IToken'
Expand All @@ -20,20 +21,23 @@ export class CollateralConfigMap implements ICollateralConfigMap {
}

public add(params: { collateral: IToken; collateralConfig: ICollateralConfig }): void {
this.record[params.collateral.address.value] = CollateralConfig.createFrom(
params.collateralConfig,
)
this.record[this._formatRecordKey(params.collateral.address.value)] =
CollateralConfig.createFrom(params.collateralConfig)
}

public get(params: { token: IToken }): Maybe<CollateralConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}

protected _importCollateralConfigMap(params: ICollateralConfigMap): void {
return Object.entries(params.record).forEach(([, collateralConfig]) => {
this.add({ collateral: collateralConfig.token, collateralConfig })
})
}

protected _formatRecordKey(address: HexData) {
return address.toLowerCase() as HexData
}
}

SerializationService.registerClass(CollateralConfigMap)
11 changes: 9 additions & 2 deletions sdk/sdk-common/src/protocols/implementation/DebtConfigMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HexData } from '../../common/aliases/HexData'
import { AddressValue } from '../../common/aliases/AddressValue'
import { Maybe } from '../../common/aliases/Maybe'
import { IToken } from '../../common/interfaces/IToken'
Expand All @@ -21,18 +22,24 @@ export class DebtConfigMap implements IDebtConfigMap {
}

public add(params: { debt: IToken; debtConfig: IDebtConfig }): void {
this.record[params.debt.address.value] = DebtConfig.createFrom(params.debtConfig)
this.record[this._formatRecordKey(params.debt.address.value)] = DebtConfig.createFrom(
params.debtConfig,
)
}

public get(params: { token: IToken }): Maybe<DebtConfig> {
return this.record[params.token.address.value]
return this.record[this._formatRecordKey(params.token.address.value)]
}

protected _importDebtConfigMap(params: IDebtConfigMap): void {
return Object.entries(params.record).forEach(([, debtConfig]) => {
this.add({ debt: debtConfig.token, debtConfig })
})
}

protected _formatRecordKey(address: HexData) {
return address.toLowerCase() as HexData
}
}

SerializationService.registerClass(DebtConfigMap)
Loading