From e4164d5ad1a77bf91fa161422eeac835e89e0978 Mon Sep 17 00:00:00 2001 From: Vladimir Borovik Date: Wed, 13 Nov 2024 18:31:54 +0300 Subject: [PATCH] fix: `EscrowFactoryFacade.getDstEscrowAddress` --- src/escrow-factory/escrow-factory-facade.ts | 2 +- src/escrow-factory/escrow-factory.spec.ts | 53 ++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/escrow-factory/escrow-factory-facade.ts b/src/escrow-factory/escrow-factory-facade.ts index a86ac40..213f66c 100644 --- a/src/escrow-factory/escrow-factory-facade.ts +++ b/src/escrow-factory/escrow-factory-facade.ts @@ -81,7 +81,7 @@ export class EscrowFactoryFacade implements EscrowFactory { */ implementationAddress: Address ): Address { - return this.getDstEscrowAddress( + return this.factory.getDstEscrowAddress( srcImmutables, complement, blockTime, diff --git a/src/escrow-factory/escrow-factory.spec.ts b/src/escrow-factory/escrow-factory.spec.ts index 87f847f..da6c2fe 100644 --- a/src/escrow-factory/escrow-factory.spec.ts +++ b/src/escrow-factory/escrow-factory.spec.ts @@ -2,7 +2,7 @@ import {Address, NetworkEnum} from '@1inch/fusion-sdk' import {keccak256} from 'ethers' import {EscrowFactoryFacade} from './escrow-factory-facade' import {EscrowFactoryZksync} from './escrow-factory-zksync' -import {Immutables} from '../immutables' +import {DstImmutablesComplement, Immutables} from '../immutables' import {HashLock, TimeLocks} from '../cross-chain-order' describe('EscrowAddressFacade', () => { @@ -33,6 +33,57 @@ describe('EscrowAddressFacade', () => { ) }) + it('Should correct calc src/dst address for Ethereum 2', () => { + const facade = new EscrowFactoryFacade( + NetworkEnum.ETHEREUM, + Address.fromBigInt(1n) + ) + + const immutables = Immutables.new({ + maker: new Address('0x04d3b2c70208f3fb196affef78080b3cc05ee1cb'), + taker: new Address('0x9c4dffb4f7e8217a8ac0555d67e125f8769284ba'), + token: new Address('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'), + amount: 99345341n, + hashLock: HashLock.fromString( + '0x939dbeb956ac9369de8b1acaaa78a173620c2275fba501f8340b91cbceabdbf1' + ), + orderHash: + '0x8ed7de0668228e00103038a7fc6a19c933d56fca27b154a3e532ebeb4a5c07bd', + timeLocks: + TimeLocks.fromBigInt( + 46545443980783778519496226194286874737220106048808714334632784681655911579684n + ), + safetyDeposit: 2474844692460000n + }) + const srcImplAddress = Address.fromBigInt(1n) + const dstImplAddress = Address.fromBigInt(2n) + + const srcAddress = facade.getSrcEscrowAddress( + immutables, + srcImplAddress + ) + const dstAddress = facade.getDstEscrowAddress( + immutables, + DstImmutablesComplement.new({ + amount: immutables.amount, + maker: immutables.maker, + safetyDeposit: immutables.safetyDeposit, + token: immutables.token + }), + 0n, + immutables.taker, + dstImplAddress + ) + + expect(srcAddress).toEqual( + new Address('0xf97a2ae8f0481c1cc11bf8cb962b088bc5f6a945') + ) + + expect(dstAddress).toEqual( + new Address('0x5177d276a4b46b0cbb5ae98d296663fcee0138c4') + ) + }) + describe('zkSync', () => { it('Should calc correct src address from immutables', () => { const immutables = Immutables.new({