Skip to content

Commit

Permalink
feat: add multi fill hashlock (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk authored Aug 1, 2024
1 parent 4e8cf25 commit 2fddd2f
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 40 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@1inch/byte-utils": "2.6.0",
"@1inch/fusion-sdk": "2.1.5-rc.0",
"@openzeppelin/merkle-tree": "1.0.7",
"axios": "1.7.2",
"ecies-25519": "1.3.1",
"ethers": "6.13.1"
Expand Down
211 changes: 211 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 64 additions & 4 deletions src/cross-chain-order/cross-chain-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
import {CrossChainOrder} from './cross-chain-order'
import {CrossChainOrderInfo, EscrowParams} from './types'
import {HashLock} from './hash-lock'
import {TimeLocks} from './time-locks/time-locks'
import {TimeLocks} from './time-locks'
import {getRandomBytes32} from '../utils/get-random-bytes-32'

describe('CrossChainOrder', () => {
it('Should encode/decode order', () => {
Expand All @@ -26,7 +27,66 @@ describe('CrossChainOrder', () => {
}

const escrowParams: EscrowParams = {
hashLock: HashLock.fromSecret('123'),
hashLock: HashLock.forSingleFill(getRandomBytes32()),
srcChainId: NetworkEnum.ETHEREUM,
dstChainId: NetworkEnum.ARBITRUM,
srcSafetyDeposit: 1000n,
dstSafetyDeposit: 1000n,
timeLocks: TimeLocks.new({
srcWithdrawal: 1n,
srcPublicWithdrawal: 2n,
srcCancellation: 3n,
srcPublicCancellation: 4n,
dstWithdrawal: 1n,
dstPublicWithdrawal: 2n,
dstCancellation: 3n
})
}
const order = CrossChainOrder.new(
factoryAddress,
orderData,
escrowParams,
{
auction: new AuctionDetails({
startTime: now(),
duration: 180n,
points: [],
initialRateBump: 100_000
}),
whitelist: [{address: Address.fromBigInt(100n), allowFrom: 0n}]
},
{
nonce: 1n
}
)

expect(
CrossChainOrder.fromDataAndExtension(
order.build(),
Extension.decode(order.extension.encode())
)
).toEqual(order)
})

it('Should encode/decode order with multiple fills', () => {
const factoryAddress = Address.fromBigInt(1n)
const orderData: CrossChainOrderInfo = {
maker: Address.fromBigInt(2n),
makerAsset: new Address(
'0xdac17f958d2ee523a2206206994597c13d831ec7'
),
takerAsset: new Address(
'0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'
),
makingAmount: 100_000000n,
takingAmount: 90_000000n
}

const secrets = [getRandomBytes32(), getRandomBytes32()]
const leaves = HashLock.getMerkleLeaves(secrets)

const escrowParams: EscrowParams = {
hashLock: HashLock.forMultipleFills(leaves),
srcChainId: NetworkEnum.ETHEREUM,
dstChainId: NetworkEnum.ARBITRUM,
srcSafetyDeposit: 1000n,
Expand Down Expand Up @@ -86,7 +146,7 @@ describe('CrossChainOrder', () => {
dstChainId: number
): CrossChainOrder => {
const escrowParams: EscrowParams = {
hashLock: HashLock.fromSecret('123'),
hashLock: HashLock.forSingleFill(getRandomBytes32()),
srcChainId,
dstChainId,
srcSafetyDeposit: 1000n,
Expand Down Expand Up @@ -146,7 +206,7 @@ describe('CrossChainOrder', () => {
}

const escrowParams: EscrowParams = {
hashLock: HashLock.fromSecret('123'),
hashLock: HashLock.forSingleFill(getRandomBytes32()),
srcChainId: NetworkEnum.ETHEREUM,
dstChainId: NetworkEnum.ETHEREUM,
srcSafetyDeposit: 1000n,
Expand Down
5 changes: 3 additions & 2 deletions src/cross-chain-order/escrow-extension.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Address, FusionExtension, NetworkEnum} from '@1inch/fusion-sdk'
import {EscrowExtension} from './escrow-extension'
import {TimeLocks} from './time-locks/time-locks'
import {TimeLocks} from './time-locks'
import {HashLock} from './hash-lock'
import {getRandomBytes32} from '../utils/get-random-bytes-32'

describe('EscrowExtension', () => {
it('Should build/decode', () => {
Expand All @@ -14,7 +15,7 @@ describe('EscrowExtension', () => {
fusionExt.auctionDetails,
fusionExt.postInteractionData,
fusionExt.makerPermit,
HashLock.fromSecret('0xff'),
HashLock.forSingleFill(getRandomBytes32()),
NetworkEnum.ARBITRUM,
Address.fromBigInt(1n),
100n,
Expand Down
Loading

0 comments on commit 2fddd2f

Please sign in to comment.