-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: zksync address generation for escrow factory
- Loading branch information
1 parent
b3d755a
commit 4faaec0
Showing
3 changed files
with
238 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import {Address, NetworkEnum} from '@1inch/fusion-sdk' | ||
import {EscrowFactory} from './escrow-factory' | ||
import {DstImmutablesComplement, Immutables} from '../immutables' | ||
|
||
export class EscrowFactoryFacade { | ||
private factory: EscrowFactory | ||
|
||
constructor(factoryAddress: Address) { | ||
this.factory = new EscrowFactory(factoryAddress) | ||
} | ||
|
||
public getEscrowAddressByChain( | ||
/** | ||
* chain id | ||
*/ | ||
chainId: number, | ||
/** | ||
* @see Immutables.hash | ||
*/ | ||
immutablesHash: string, | ||
/** | ||
* Address of escrow implementation at the same chain as `this.address` | ||
*/ | ||
implementationAddress: Address | ||
): Address { | ||
switch (chainId) { | ||
case NetworkEnum.ZKSYNC: | ||
return this.factory.getZkEscrowAddress( | ||
immutablesHash, | ||
implementationAddress | ||
) | ||
default: | ||
return this.factory.getEscrowAddress( | ||
immutablesHash, | ||
implementationAddress | ||
) | ||
} | ||
} | ||
|
||
public getSrcEscrowAddressByChain( | ||
/** | ||
* chain id | ||
*/ | ||
chainId: number, | ||
/** | ||
* From `SrcEscrowCreated` event (with correct timeLock.deployedAt) | ||
*/ | ||
srcImmutables: Immutables, | ||
/** | ||
* Address of escrow implementation at the same chain as `this.address` | ||
*/ | ||
implementationAddress: Address | ||
): Address { | ||
switch (chainId) { | ||
case NetworkEnum.ZKSYNC: | ||
return this.factory.getZkSrcEscrowAddress( | ||
srcImmutables, | ||
implementationAddress | ||
) | ||
default: | ||
return this.factory.getSrcEscrowAddress( | ||
srcImmutables, | ||
implementationAddress | ||
) | ||
} | ||
} | ||
|
||
public getDstEscrowAddressByChain( | ||
/** | ||
* chain id | ||
*/ | ||
chainId: number, | ||
/** | ||
* From `SrcEscrowCreated` event | ||
*/ | ||
srcImmutables: Immutables, | ||
/** | ||
* From `SrcEscrowCreated` event | ||
*/ | ||
complement: DstImmutablesComplement, | ||
/** | ||
* Block time when event `DstEscrowCreated` produced | ||
*/ | ||
blockTime: bigint, | ||
/** | ||
* Taker from `DstEscrowCreated` event | ||
*/ | ||
taker: Address, | ||
/** | ||
* Address of escrow implementation at the same chain as `this.address` | ||
*/ | ||
implementationAddress: Address | ||
): Address { | ||
switch (chainId) { | ||
case NetworkEnum.ZKSYNC: | ||
return this.factory.getZkDstEscrowAddress( | ||
srcImmutables, | ||
complement, | ||
blockTime, | ||
taker, | ||
implementationAddress | ||
) | ||
default: | ||
return this.factory.getDstEscrowAddress( | ||
srcImmutables, | ||
complement, | ||
blockTime, | ||
taker, | ||
implementationAddress | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters