Skip to content

Commit 211e245

Browse files
authored
chore: create EvmHypBaseCollateralAdapter and update inheritance (#7320)
1 parent ba380c5 commit 211e245

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

.changeset/giant-coats-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperlane-xyz/sdk": minor
3+
---
4+
5+
Create EvmHypBaseCollateralAdapter, now EvmHypCollateralAdapter and EvmHypRebaseCollateralAdapter extends from it

typescript/sdk/src/token/adapters/EvmTokenAdapter.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ERC4626__factory,
1111
GasRouter__factory,
1212
HypERC20,
13+
HypERC20Collateral,
1314
HypERC20Collateral__factory,
1415
HypERC20__factory,
1516
HypERC4626,
@@ -375,8 +376,7 @@ export class EvmHypSyntheticAdapter
375376
}
376377
}
377378

378-
// Interacts with HypCollateral contracts
379-
export class EvmHypCollateralAdapter
379+
class BaseEvmHypCollateralAdapter
380380
extends EvmHypSyntheticAdapter
381381
implements IHypTokenAdapter<PopulatedTransaction>
382382
{
@@ -396,22 +396,9 @@ export class EvmHypCollateralAdapter
396396
}
397397

398398
async getWrappedTokenAddress(): Promise<Address> {
399-
if (this.wrappedTokenAddress) return this.wrappedTokenAddress;
400-
401-
const contractVersion = await this.getContractPackageVersion();
402-
const hasTokenFeeInterface = isValidContractVersion(
403-
contractVersion,
404-
TOKEN_FEE_CONTRACT_VERSION,
405-
);
406-
407-
if (!hasTokenFeeInterface) {
408-
const erc20CollateralContract = HypERC20Collateral__factory.connect(
409-
this.addresses.token,
410-
this.getProvider(),
411-
);
412-
this.wrappedTokenAddress = await erc20CollateralContract.wrappedToken();
413-
} else this.wrappedTokenAddress = await this.collateralContract.token();
414-
399+
if (!this.wrappedTokenAddress) {
400+
this.wrappedTokenAddress = await this.collateralContract.token();
401+
}
415402
return this.wrappedTokenAddress!;
416403
}
417404

@@ -470,6 +457,33 @@ export class EvmHypCollateralAdapter
470457
}
471458
}
472459

460+
// Interacts with HypCollateral contracts
461+
export class EvmHypCollateralAdapter
462+
extends BaseEvmHypCollateralAdapter
463+
implements IHypTokenAdapter<PopulatedTransaction>
464+
{
465+
public readonly collateralContract: HypERC20Collateral;
466+
467+
constructor(
468+
public readonly chainName: ChainName,
469+
public readonly multiProvider: MultiProtocolProvider,
470+
public readonly addresses: { token: Address },
471+
) {
472+
super(chainName, multiProvider, addresses);
473+
this.collateralContract = HypERC20Collateral__factory.connect(
474+
addresses.token,
475+
this.getProvider(),
476+
);
477+
}
478+
479+
override async getWrappedTokenAddress(): Promise<Address> {
480+
if (!this.wrappedTokenAddress) {
481+
this.wrappedTokenAddress = await this.collateralContract.wrappedToken();
482+
}
483+
return this.wrappedTokenAddress!;
484+
}
485+
}
486+
473487
export class EvmMovableCollateralAdapter
474488
extends EvmHypCollateralAdapter
475489
implements IMovableCollateralRouterAdapter<PopulatedTransaction>
@@ -620,7 +634,7 @@ export class EvmHypCollateralFiatAdapter
620634
}
621635

622636
export class EvmHypRebaseCollateralAdapter
623-
extends EvmHypCollateralAdapter
637+
extends BaseEvmHypCollateralAdapter
624638
implements IHypTokenAdapter<PopulatedTransaction>
625639
{
626640
public override collateralContract: HypERC4626Collateral;
@@ -637,6 +651,13 @@ export class EvmHypRebaseCollateralAdapter
637651
);
638652
}
639653

654+
override async getWrappedTokenAddress(): Promise<Address> {
655+
if (!this.wrappedTokenAddress) {
656+
this.wrappedTokenAddress = await this.collateralContract.wrappedToken();
657+
}
658+
return this.wrappedTokenAddress!;
659+
}
660+
640661
override async getBridgedSupply(): Promise<bigint> {
641662
const vault = ERC4626__factory.connect(
642663
await this.collateralContract.vault(),

0 commit comments

Comments
 (0)