@xyo-network/chain-bridge 1.16.15 → 1.16.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -8
- package/dist/node/driver/indexer/spec/ChainBlocksObservable.spec.d.ts +0 -2
- package/dist/node/driver/indexer/spec/ChainBlocksObservable.spec.d.ts.map +0 -1
- package/dist/node/driver/indexer/spec/ChainHydratedBlocksObservable.spec.d.ts +0 -2
- package/dist/node/driver/indexer/spec/ChainHydratedBlocksObservable.spec.d.ts.map +0 -1
- package/dist/node/interface/service/Observer/ERC20TransferObserver/spec/ERC20TransferObserver.spec.d.ts +0 -2
- package/dist/node/interface/service/Observer/ERC20TransferObserver/spec/ERC20TransferObserver.spec.d.ts.map +0 -1
- package/dist/node/interface/service/Observer/LiquidityPoolBridgeObserver/spec/LiquidityPoolBridgeObserver.spec.d.ts +0 -2
- package/dist/node/interface/service/Observer/LiquidityPoolBridgeObserver/spec/LiquidityPoolBridgeObserver.spec.d.ts.map +0 -1
- package/dist/node/interface/service/Relay/ChainBridgeRelay/spec/ChainBridgeRelayService.spec.d.ts +0 -2
- package/dist/node/interface/service/Relay/ChainBridgeRelay/spec/ChainBridgeRelayService.spec.d.ts.map +0 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/spec/LiquidityPoolBridgeRelay.spec.d.ts +0 -2
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/spec/LiquidityPoolBridgeRelay.spec.d.ts.map +0 -1
- package/dist/node/manifest/public/spec/Node.spec.d.ts +0 -2
- package/dist/node/manifest/public/spec/Node.spec.d.ts.map +0 -1
- package/src/driver/indexer/spec/ChainBlocksObservable.spec.ts +0 -62
- package/src/driver/indexer/spec/ChainHydratedBlocksObservable.spec.ts +0 -64
- package/src/interface/service/Observer/ERC20TransferObserver/spec/ERC20TransferObserver.spec.ts +0 -272
- package/src/interface/service/Observer/LiquidityPoolBridgeObserver/spec/LiquidityPoolBridgeObserver.spec.ts +0 -314
- package/src/interface/service/Relay/ChainBridgeRelay/spec/ChainBridgeRelayService.spec.ts +0 -266
- package/src/interface/service/Relay/LiquidityPoolBridgeRelay/spec/LiquidityPoolBridgeRelay.spec.ts +0 -238
- package/src/manifest/public/spec/Node.spec.ts +0 -32
package/src/interface/service/Relay/LiquidityPoolBridgeRelay/spec/LiquidityPoolBridgeRelay.spec.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
assertEx, toAddress, toHex,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import { Account } from '@xyo-network/account'
|
|
6
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
7
|
-
import {
|
|
8
|
-
type BridgeableToken, BridgeableToken__factory, type LiquidityPoolBridge, LiquidityPoolBridge__factory,
|
|
9
|
-
} from '@xyo-network/typechain'
|
|
10
|
-
import type {
|
|
11
|
-
BridgeIntent, BridgeSourceObservation, ChainId,
|
|
12
|
-
} from '@xyo-network/xl1-protocol'
|
|
13
|
-
import {
|
|
14
|
-
AttoXL1ConvertFactor, BridgeIntentSchema, BridgeSourceObservationSchema,
|
|
15
|
-
} from '@xyo-network/xl1-protocol'
|
|
16
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
17
|
-
import { getDefaultConfig } from '@xyo-network/xl1-protocol-sdk'
|
|
18
|
-
import {
|
|
19
|
-
parseEther, Wallet, WebSocketProvider,
|
|
20
|
-
} from 'ethers'
|
|
21
|
-
import {
|
|
22
|
-
beforeAll, beforeEach, describe, expect, it, vi,
|
|
23
|
-
} from 'vitest'
|
|
24
|
-
|
|
25
|
-
import type {
|
|
26
|
-
BridgeDestinationObservationIndexerInterface, BridgeIntentIndexerInterface, BridgeSourceObservationIndexerInterface, ChainBridgeRelayInterface,
|
|
27
|
-
LockingBridgeIntentProcessorInterface, UnlockingBridgeIntentProcessorInterface,
|
|
28
|
-
} from '../../../../interface/index.ts'
|
|
29
|
-
import type { LiquidityPoolBridgeRelayParams } from '../LiquidityPoolBridgeRelay.ts'
|
|
30
|
-
import { LiquidityPoolBridgeRelay } from '../LiquidityPoolBridgeRelay.ts'
|
|
31
|
-
|
|
32
|
-
describe.skip('LiquidityPoolBridgeRelay', () => {
|
|
33
|
-
// Test ERC-20 deployed to Hardhat local chain
|
|
34
|
-
const TOKEN_ADDRESS = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
|
|
35
|
-
const bridgeAddress = '0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f'
|
|
36
|
-
const WS_URL = 'ws://127.0.0.1:8545'
|
|
37
|
-
const provider = new WebSocketProvider(WS_URL)
|
|
38
|
-
let ethBridgeSender: Wallet
|
|
39
|
-
let ethBridgeReceiver: Wallet
|
|
40
|
-
let token: BridgeableToken
|
|
41
|
-
let bridge: LiquidityPoolBridge
|
|
42
|
-
let xl1Address: Address
|
|
43
|
-
let account: AccountInstance
|
|
44
|
-
let config: Config
|
|
45
|
-
let destinationObservations: BridgeDestinationObservationIndexerInterface
|
|
46
|
-
let destinationRelay: ChainBridgeRelayInterface
|
|
47
|
-
let intentProcessed: LockingBridgeIntentProcessorInterface
|
|
48
|
-
let intentProcessing: UnlockingBridgeIntentProcessorInterface
|
|
49
|
-
let intents: BridgeIntentIndexerInterface
|
|
50
|
-
let sourceObservations: BridgeSourceObservationIndexerInterface
|
|
51
|
-
let relay: LiquidityPoolBridgeRelay
|
|
52
|
-
let intent: BridgeIntent
|
|
53
|
-
let srcObservation: BridgeSourceObservation
|
|
54
|
-
|
|
55
|
-
const xl1ChainId: ChainId = toAddress('0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9')
|
|
56
|
-
const xl1TxHash = toHex('0x4444444444444444444444444444444444444444444444444444444444444444') // Some XL1 tx hash
|
|
57
|
-
const srcAmountBigint = 100n * AttoXL1ConvertFactor.xl1
|
|
58
|
-
const srcAmount = toHex(srcAmountBigint)
|
|
59
|
-
const destAmount = srcAmount // 1:1 for test
|
|
60
|
-
const ethChainId = toHex('0x7A69')
|
|
61
|
-
const bridgeableTokenContract = toHex(TOKEN_ADDRESS)
|
|
62
|
-
|
|
63
|
-
const createRandomWallet = async (): Promise<Wallet> => {
|
|
64
|
-
// Create random account
|
|
65
|
-
const account = await Account.random()
|
|
66
|
-
expect(account.private?.hex).toBeDefined()
|
|
67
|
-
const key = assertEx(account.private?.hex)
|
|
68
|
-
|
|
69
|
-
// Create a wallet from the private key
|
|
70
|
-
const wallet = new Wallet(key, provider)
|
|
71
|
-
const deployer = await provider.getSigner(0)
|
|
72
|
-
|
|
73
|
-
// Fund the wallet with some ETH for gas
|
|
74
|
-
const fundTx = await deployer.sendTransaction({ to: wallet.address, value: parseEther('1') })
|
|
75
|
-
await fundTx.wait()
|
|
76
|
-
|
|
77
|
-
// Ensure wallet has ETH
|
|
78
|
-
const balance = await provider.getBalance(wallet.address)
|
|
79
|
-
expect(balance).toBeGreaterThan(0n)
|
|
80
|
-
|
|
81
|
-
// Return the created wallet
|
|
82
|
-
return wallet
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
beforeAll(async () => {
|
|
86
|
-
account = await Account.fromPrivateKey('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80')
|
|
87
|
-
config = getDefaultConfig()
|
|
88
|
-
const deployer = await provider.getSigner(0)
|
|
89
|
-
ethBridgeSender = await createRandomWallet()
|
|
90
|
-
|
|
91
|
-
token = BridgeableToken__factory.connect(TOKEN_ADDRESS, deployer)
|
|
92
|
-
bridge = LiquidityPoolBridge__factory.connect(bridgeAddress, deployer)
|
|
93
|
-
const owner = await bridge.owner()
|
|
94
|
-
expect(owner).toBeDefined()
|
|
95
|
-
expect(owner).to.eq(deployer.address)
|
|
96
|
-
const amount = srcAmountBigint * 2n
|
|
97
|
-
await token.mint(await bridge.getAddress(), parseEther(amount.toString()))
|
|
98
|
-
expect(await token.balanceOf(await bridge.getAddress())).toBeGreaterThanOrEqual(amount)
|
|
99
|
-
await token.mint(ethBridgeSender.address, parseEther(amount.toString()))
|
|
100
|
-
expect(await token.balanceOf(ethBridgeSender.address)).toBeGreaterThanOrEqual(amount)
|
|
101
|
-
|
|
102
|
-
intents = {
|
|
103
|
-
addIntent: vi.fn().mockResolvedValue(true),
|
|
104
|
-
getIntentByNonce: vi.fn(),
|
|
105
|
-
getIntentsForDestination: vi.fn().mockResolvedValue([]),
|
|
106
|
-
getIntentsForSource: vi.fn().mockResolvedValue([]),
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
sourceObservations = {
|
|
110
|
-
addObservation: vi.fn().mockResolvedValue(true),
|
|
111
|
-
getIntentForObservation: vi.fn().mockResolvedValue(null),
|
|
112
|
-
getObservationForIntent: vi.fn().mockResolvedValue(null),
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
destinationObservations = {
|
|
116
|
-
addObservation: vi.fn().mockResolvedValue(true),
|
|
117
|
-
getIntentForObservation: vi.fn().mockResolvedValue(null),
|
|
118
|
-
getObservationForIntent: vi.fn().mockResolvedValue(null),
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
intentProcessed = {
|
|
122
|
-
isLocked: vi.fn().mockResolvedValue(null),
|
|
123
|
-
lock: vi.fn().mockResolvedValue(true),
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
intentProcessing = {
|
|
127
|
-
isLocked: vi.fn().mockResolvedValue(null),
|
|
128
|
-
lock: vi.fn().mockResolvedValue(true),
|
|
129
|
-
unlock: vi.fn().mockResolvedValue(true),
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
destinationRelay = {
|
|
133
|
-
beginRelay: vi.fn().mockResolvedValue(true),
|
|
134
|
-
relaySync: vi.fn().mockResolvedValue(null),
|
|
135
|
-
onDestinationObservation: vi.fn().mockResolvedValue(false),
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
describe('relaySync', () => {
|
|
139
|
-
beforeEach(async () => {
|
|
140
|
-
xl1Address = (await Account.random()).address
|
|
141
|
-
ethBridgeReceiver = await createRandomWallet()
|
|
142
|
-
sourceObservations = {
|
|
143
|
-
addObservation: vi.fn().mockResolvedValue(true),
|
|
144
|
-
getObservationForIntent: vi.fn().mockResolvedValue(null),
|
|
145
|
-
getIntentForObservation: vi.fn().mockResolvedValue(null),
|
|
146
|
-
}
|
|
147
|
-
destinationObservations = {
|
|
148
|
-
addObservation: vi.fn().mockResolvedValue(true),
|
|
149
|
-
getObservationForIntent: vi.fn().mockResolvedValue(null),
|
|
150
|
-
getIntentForObservation: vi.fn().mockResolvedValue(null),
|
|
151
|
-
}
|
|
152
|
-
const nonce = Date.now().toString()
|
|
153
|
-
intent = {
|
|
154
|
-
// Source
|
|
155
|
-
src: xl1ChainId, // From XL1
|
|
156
|
-
srcAddress: xl1Address, // From XL1 sender
|
|
157
|
-
srcAmount,
|
|
158
|
-
srcToken: xl1ChainId, // In XL1
|
|
159
|
-
|
|
160
|
-
// Destination
|
|
161
|
-
dest: ethChainId, // To Ethereum
|
|
162
|
-
destAddress: toAddress(ethBridgeReceiver.address),
|
|
163
|
-
destAmount,
|
|
164
|
-
destToken: bridgeableTokenContract,
|
|
165
|
-
|
|
166
|
-
// Details
|
|
167
|
-
nonce,
|
|
168
|
-
|
|
169
|
-
schema: BridgeIntentSchema,
|
|
170
|
-
}
|
|
171
|
-
srcObservation = {
|
|
172
|
-
// Source
|
|
173
|
-
src: xl1ChainId, // From XL1
|
|
174
|
-
srcAddress: xl1Address, // From XL1 sender
|
|
175
|
-
srcAmount,
|
|
176
|
-
srcToken: xl1ChainId, // In XL1
|
|
177
|
-
|
|
178
|
-
// Destination
|
|
179
|
-
dest: ethChainId, // To Ethereum
|
|
180
|
-
destAddress: toAddress(ethBridgeReceiver.address),
|
|
181
|
-
destAmount,
|
|
182
|
-
destToken: bridgeableTokenContract,
|
|
183
|
-
|
|
184
|
-
// Observation
|
|
185
|
-
srcConfirmation: xl1TxHash,
|
|
186
|
-
|
|
187
|
-
schema: BridgeSourceObservationSchema,
|
|
188
|
-
}
|
|
189
|
-
intents = {
|
|
190
|
-
addIntent: vi.fn().mockResolvedValue(true),
|
|
191
|
-
getIntentByNonce: vi.fn().mockResolvedValue(intent),
|
|
192
|
-
getIntentsForDestination: vi.fn().mockResolvedValue([intent]),
|
|
193
|
-
getIntentsForSource: vi.fn().mockResolvedValue([]),
|
|
194
|
-
}
|
|
195
|
-
const params: LiquidityPoolBridgeRelayParams = {
|
|
196
|
-
account,
|
|
197
|
-
config,
|
|
198
|
-
bridgeAddress,
|
|
199
|
-
provider,
|
|
200
|
-
destinationObservations,
|
|
201
|
-
destinationRelay,
|
|
202
|
-
intentProcessed,
|
|
203
|
-
intentProcessing,
|
|
204
|
-
intents,
|
|
205
|
-
sourceObservations,
|
|
206
|
-
}
|
|
207
|
-
relay = await LiquidityPoolBridgeRelay.create(params)
|
|
208
|
-
})
|
|
209
|
-
it('should do nothing if source observation is null', async () => {
|
|
210
|
-
// Arrange
|
|
211
|
-
sourceObservations.getObservationForIntent = vi.fn().mockResolvedValue(null)
|
|
212
|
-
intentProcessing.lock = vi.fn().mockResolvedValue(true)
|
|
213
|
-
intentProcessing.unlock = vi.fn()
|
|
214
|
-
|
|
215
|
-
// Act
|
|
216
|
-
const result = await relay.relaySync(intent)
|
|
217
|
-
|
|
218
|
-
// Assert
|
|
219
|
-
expect(intentProcessing.lock).not.toHaveBeenCalled()
|
|
220
|
-
expect(result).toBe(null)
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
it('should lock and call destinationRelay.beginRelay if observation exists', async () => {
|
|
224
|
-
// Arrange
|
|
225
|
-
sourceObservations.getObservationForIntent = vi.fn().mockResolvedValue(srcObservation)
|
|
226
|
-
intentProcessing.lock = vi.fn().mockResolvedValue(true)
|
|
227
|
-
intentProcessing.unlock = vi.fn()
|
|
228
|
-
|
|
229
|
-
// Act
|
|
230
|
-
const result = await relay.relaySync(intent)
|
|
231
|
-
|
|
232
|
-
// Assert
|
|
233
|
-
expect(sourceObservations.getObservationForIntent).toHaveBeenCalledWith(intent)
|
|
234
|
-
expect(intentProcessing.lock).toHaveBeenCalledWith(account.address, intent)
|
|
235
|
-
expect(result).not.toBe(null)
|
|
236
|
-
})
|
|
237
|
-
})
|
|
238
|
-
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { MemoryNode } from '@xyo-network/node-memory'
|
|
2
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
3
|
-
import { getDefaultConfig } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import {
|
|
5
|
-
beforeAll, describe, expect,
|
|
6
|
-
it,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { getNode, GetNodeContext } from '../../getNode.ts'
|
|
10
|
-
import { SilentLogger } from '@xylabs/sdk-js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @group manifest
|
|
14
|
-
*/
|
|
15
|
-
describe('Node', () => {
|
|
16
|
-
let node: MemoryNode
|
|
17
|
-
let context: GetNodeContext
|
|
18
|
-
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
const config = getDefaultConfig()
|
|
21
|
-
const logger = new SilentLogger()
|
|
22
|
-
const wallet = await HDWallet.random()
|
|
23
|
-
context = {
|
|
24
|
-
config, logger, wallet,
|
|
25
|
-
}
|
|
26
|
-
// Create a node with the default configuration
|
|
27
|
-
node = await getNode(context)
|
|
28
|
-
})
|
|
29
|
-
it('should return node', () => {
|
|
30
|
-
expect(node).toBeDefined()
|
|
31
|
-
})
|
|
32
|
-
})
|