Skip to content

Commit d45c8fc

Browse files
authored
Merge pull request #1 from baking-bad/fix/indexer-schema
Support the new Indexer schema
2 parents e3511e6 + 52c1a47 commit d45c8fc

21 files changed

+167
-148
lines changed

integration/testConfig.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { NativeEtherlinkToken, NativeTezosToken, ERC20EtherlinkToken, FA12T
33
export interface TestTokens {
44
readonly tezos: {
55
tez: NativeTezosToken;
6-
ctez: FA12TezosToken;
6+
tzbtc: FA12TezosToken;
77
usdt: FA2TezosToken;
88
};
99
readonly etherlink: {
1010
tez: NativeEtherlinkToken
11-
ctez: ERC20EtherlinkToken;
11+
tzbtc: ERC20EtherlinkToken;
1212
usdt: ERC20EtherlinkToken;
1313
};
1414
}
@@ -62,27 +62,27 @@ const createTestTokens = (): TestTokens => {
6262
tez: {
6363
type: 'native'
6464
},
65-
ctez: {
65+
tzbtc: {
6666
type: 'fa1.2',
67-
address: 'KT1LpdETWYvPWCQTR2FEW6jE6dVqJqxYjdeW'
67+
address: 'KT1Vq1toL9mQquJhCvVRbbcC8PbZJWM4bPui'
6868
},
6969
usdt: {
7070
type: 'fa2',
71-
address: 'KT195Eb8T524v5VJ99ZzH2wpnPfQ2wJfMi6h',
72-
tokenId: '42'
71+
address: 'KT1K6uyg7cjNRoPkYw6SfyCm1f2tPLHfVUez',
72+
tokenId: '0'
7373
}
7474
},
7575
etherlink: {
7676
tez: {
7777
type: 'native'
7878
},
79-
ctez: {
79+
tzbtc: {
8080
type: 'erc20',
8181
address: '0x87dcBf128677ba36E79D47dAf4eb4e51610e0150'
8282
},
8383
usdt: {
8484
type: 'erc20',
85-
address: '0xcB5d40c6B1bdf5Cd51b3801351b0A68D101a561b'
85+
address: '0x8554cD57C0C3E5Ab9d1782c9063279fA9bFA4680'
8686
}
8787
}
8888
};

integration/testHelpers.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
4747
{
4848
tezos: {
4949
...testConfig.tokens.tezos.tez,
50-
ticketHelperContractAddress: 'KT1DWVsu4Jtu2ficZ1qtNheGPunm5YVniegT'
50+
ticketHelperContractAddress: 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9'
5151
},
5252
etherlink: {
5353
...testConfig.tokens.etherlink.tez,
5454
}
5555
},
5656
{
5757
tezos: {
58-
...testConfig.tokens.tezos.ctez,
59-
ticketerContractAddress: 'KT1RvSp4yDKUABqWmv3pKGE9fA6iCGy7bqGh',
60-
ticketHelperContractAddress: 'KT1DHLWJorW9WB6ztkx1XcoaJKWXeTu9yoR1'
58+
...testConfig.tokens.tezos.tzbtc,
59+
ticketerContractAddress: 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo',
60+
ticketHelperContractAddress: 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1'
6161
},
6262
etherlink: {
63-
...testConfig.tokens.etherlink.ctez
63+
...testConfig.tokens.etherlink.tzbtc
6464
}
6565
},
6666
{
6767
tezos: {
6868
...testConfig.tokens.tezos.usdt,
69-
ticketerContractAddress: 'KT1VybveLaWhpQHKph28WcGwSy1ud22KSEan',
70-
ticketHelperContractAddress: 'KT1DNtHLr9T9zksZjZvQwgtx5XJwrW9wzETB'
69+
ticketerContractAddress: 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp',
70+
ticketHelperContractAddress: 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH'
7171
},
7272
etherlink: {
7373
...testConfig.tokens.etherlink.usdt
@@ -194,7 +194,7 @@ export const expectFinishedDeposit = (
194194
etherlinkOperation: {
195195
blockId: expect.any(Number),
196196
hash: expect.stringMatching(etherlinkOperationRegex),
197-
logIndex: expect.any(Number),
197+
logIndex: params.etherlinkToken.type === 'native' ? null : expect.any(Number),
198198
amount: params.outAmount,
199199
token: params.etherlinkToken,
200200
timestamp: expect.any(String),

integration/tests/balances.test.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ describe('Balances', () => {
4040

4141
test.each([
4242
() => [testTezosAccountAddress, tokens.tezos.tez] as const,
43-
() => [testTezosAccountAddress, tokens.tezos.ctez] as const,
43+
() => [testTezosAccountAddress, tokens.tezos.tzbtc] as const,
4444
() => [testTezosAccountAddress, tokens.tezos.usdt] as const,
4545
() => [testEtherlinkAccountAddress, tokens.etherlink.tez] as const,
46-
() => [testEtherlinkAccountAddress, tokens.etherlink.ctez] as const,
46+
() => [testEtherlinkAccountAddress, tokens.etherlink.tzbtc] as const,
4747
() => [testEtherlinkAccountAddress, tokens.etherlink.usdt] as const,
4848
])('Get the balance for a specific address and token: %#', async getTestData => {
4949
const [address, token] = getTestData();
@@ -59,30 +59,30 @@ describe('Balances', () => {
5959

6060
test.each([
6161
() => [testTezosAccountAddress, [tokens.tezos.tez], [tokens.tezos.tez]] as const,
62-
() => [testTezosAccountAddress, [tokens.tezos.ctez], [tokens.tezos.ctez]] as const,
63-
() => [testTezosAccountAddress, [tokens.tezos.ctez, tokens.tezos.usdt], [tokens.tezos.ctez, tokens.tezos.usdt]] as const,
62+
() => [testTezosAccountAddress, [tokens.tezos.tzbtc], [tokens.tezos.tzbtc]] as const,
63+
() => [testTezosAccountAddress, [tokens.tezos.tzbtc, tokens.tezos.usdt], [tokens.tezos.tzbtc, tokens.tezos.usdt]] as const,
6464
() => [
6565
testTezosAccountAddress,
66-
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt],
67-
[tokens.tezos.tez, tokens.tezos.ctez, tokens.tezos.usdt]
66+
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt],
67+
[tokens.tezos.tez, tokens.tezos.tzbtc, tokens.tezos.usdt]
6868
] as const,
6969
() => [
7070
testTezosAccountAddress,
71-
[tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.tezos.usdt],
72-
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt]
71+
[tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.tezos.usdt],
72+
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt]
7373
] as const,
7474
() => [
7575
testTezosAccountAddress,
76-
[tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt],
77-
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt]
76+
[tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt],
77+
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt]
7878
] as const,
7979
() => [testEtherlinkAccountAddress, [tokens.etherlink.tez], [tokens.etherlink.tez]] as const,
80-
() => [testEtherlinkAccountAddress, [tokens.etherlink.ctez], [tokens.etherlink.ctez],] as const,
81-
() => [testEtherlinkAccountAddress, [tokens.etherlink.ctez, tokens.etherlink.usdt], [tokens.etherlink.ctez, tokens.etherlink.usdt]] as const,
80+
() => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc], [tokens.etherlink.tzbtc]] as const,
81+
() => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc, tokens.etherlink.usdt], [tokens.etherlink.tzbtc, tokens.etherlink.usdt]] as const,
8282
() => [
8383
testEtherlinkAccountAddress,
84-
[tokens.etherlink.ctez, tokens.tezos.ctez, tokens.tezos.tez, tokens.etherlink.usdt],
85-
[tokens.etherlink.ctez, tokens.etherlink.tez, tokens.etherlink.usdt]
84+
[tokens.etherlink.tzbtc, tokens.tezos.tzbtc, tokens.tezos.tez, tokens.etherlink.usdt],
85+
[tokens.etherlink.tzbtc, tokens.etherlink.tez, tokens.etherlink.usdt]
8686
] as const,
8787
])('Get the balance for a specific address and tokens: %#', async getTestData => {
8888
const [address, tokens, expectedTokens] = getTestData();
@@ -113,7 +113,7 @@ describe('Balances', () => {
113113
balance: expect.any(BigInt)
114114
},
115115
{
116-
token: tokens.tezos.ctez,
116+
token: tokens.tezos.tzbtc,
117117
balance: expect.any(BigInt)
118118
},
119119
{
@@ -137,7 +137,7 @@ describe('Balances', () => {
137137
balance: expect.any(BigInt)
138138
},
139139
{
140-
token: tokens.etherlink.ctez,
140+
token: tokens.etherlink.tzbtc,
141141
balance: expect.any(BigInt)
142142
},
143143
{

integration/tests/deposit.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ describe('Deposit', () => {
7575
});
7676

7777
test('Deposit FA1.2 token', async () => {
78-
const amount = 7n;
79-
const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez];
78+
const amount = 7_000_000n;
79+
const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc];
8080

8181
const depositResult = await tokenBridge.deposit(amount, tezosToken);
8282
expectPendingDeposit(depositResult.tokenTransfer, {
@@ -102,7 +102,7 @@ describe('Deposit', () => {
102102
});
103103

104104
test('Deposit FA2 token', async () => {
105-
const amount = 20n;
105+
const amount = 20_000_000n;
106106
const [tezosToken, etherlinkToken] = [tokens.tezos.usdt, tokens.etherlink.usdt];
107107

108108
const depositResult = await tokenBridge.deposit(amount, tezosToken);
@@ -129,8 +129,8 @@ describe('Deposit', () => {
129129
});
130130

131131
test('Deposit FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => {
132-
const amount = 5n;
133-
const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez];
132+
const amount = 5_000_000n;
133+
const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc];
134134
let readyForDone = false;
135135

136136
tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => {
@@ -174,8 +174,8 @@ describe('Deposit', () => {
174174
});
175175

176176
test('Deposit FA1.2 token, check the transfer status using events (subscribeToAccountTransfers)', done => {
177-
const amount = 5n;
178-
const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez];
177+
const amount = 5_000_000n;
178+
const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc];
179179
let readyForDone = false;
180180
let tokenTransferOperationHash: string | undefined;
181181

integration/tests/withdrawal.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ describe('Withdrawal', () => {
4747
});
4848

4949
test('Withdraw FA1.2 token', async () => {
50-
const amount = 17n;
51-
const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez];
50+
const amount = 1_700_000n;
51+
const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc];
5252

5353
const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken);
5454
expectPendingWithdrawal(startWithdrawResult.tokenTransfer, {
@@ -96,7 +96,7 @@ describe('Withdrawal', () => {
9696
}, withdrawalTimeout);
9797

9898
test('Withdraw FA2 token', async () => {
99-
const amount = 20n;
99+
const amount = 20_000_000n;
100100
const [tezosToken, etherlinkToken] = [tokens.tezos.usdt, tokens.etherlink.usdt];
101101

102102
const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken);
@@ -144,9 +144,9 @@ describe('Withdrawal', () => {
144144
});
145145
}, withdrawalTimeout);
146146

147-
test('Withdraw FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => {
148-
const amount = 3n;
149-
const [tezosToken, etherlinkToken] = [tokens.tezos.ctez, tokens.etherlink.ctez];
147+
test.skip('Withdraw FA1.2 token, check the transfer status using events (subscribeToTokenTransfer)', done => {
148+
const amount = 3_000_000n;
149+
const [tezosToken, etherlinkToken] = [tokens.tezos.tzbtc, tokens.etherlink.tzbtc];
150150
let readyForDone = false;
151151

152152
tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const defaultAddresses = {
22
etherlinkKernelAddress: '0x0000000000000000000000000000000000000000',
3-
withdrawNativeTokenPrecompileAddress: '0x0000000000000000000000000000000000000020',
4-
withdrawNonNativeTokenPrecompileAddress: '0x0000000000000000000000000000000000000040'
3+
withdrawNativeTokenPrecompileAddress: '0xff00000000000000000000000000000000000001',
4+
withdrawNonNativeTokenPrecompileAddress: '0xff00000000000000000000000000000000000002'
55
} as const;

src/bridgeBlockchainService/web3EtherlinkBridgeBlockchainService/web3EtherlinkBridgeBlockchainService.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc
2828
{ receipt: TransactionReceipt },
2929
NonPayableMethodObject,
3030
NonPayableMethodObject
31-
> {
31+
> {
3232
protected readonly web3: Web3;
3333
protected readonly withdrawNativeTokenPrecompiledAddress: string;
3434
protected readonly withdrawNonNativeTokenPrecompiledAddress: string;
@@ -67,11 +67,16 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc
6767
this.getSignerAddress()
6868
]);
6969
const data = nonNativeTokenOperation.encodeABI();
70-
// TODO: need to calculate the value or hardcode it in config
70+
71+
const estimatedGas = await this.web3.eth.estimateGas({
72+
from: signerAddress,
73+
to: this.withdrawNonNativeTokenPrecompiledAddress,
74+
data,
75+
});
7176
const receipt = await this.web3.eth.sendTransaction({
7277
from: signerAddress,
7378
to: this.withdrawNonNativeTokenPrecompiledAddress,
74-
gas: 30000n,
79+
gas: estimatedGas + (estimatedGas * 5n / 100n),
7580
gasPrice,
7681
data,
7782
});

src/bridgeCore/bridgeOperations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface InitialRollupData {
2323
readonly outboxMessageLevel: number;
2424
readonly outboxMessageIndex: number;
2525
readonly estimatedOutboxMessageExecutionTimestamp?: string;
26+
readonly estimatedOutboxMessageExecutionLevel?: number;
2627
}
2728

2829
export interface CementedRollupData {

src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupGraphQLQueryBuilder/queryParts/bridgeDepositFields.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ l1_transaction {
1515
l1_account
1616
l2_account
1717
timestamp
18-
inbox_message {
19-
type
20-
level
21-
index
22-
}
2318
}
2419
l2_transaction {
2520
level
@@ -30,4 +25,9 @@ l2_transaction {
3025
id
3126
}
3227
timestamp
28+
}
29+
inbox_message {
30+
type
31+
level
32+
index
3333
}`;

src/bridgeDataProviders/dipDupBridgeDataProvider/dipDupGraphQLQueryBuilder/queryParts/bridgeWithdrawalFields.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ l2_transaction {
2424
l1_account
2525
l2_account
2626
timestamp
27-
outbox_message {
28-
level
29-
index
30-
commitment {
31-
hash
32-
}
33-
proof
34-
cemented_at
27+
}
28+
outbox_message {
29+
level
30+
index
31+
commitment {
32+
hash
3533
}
34+
proof
35+
cemented_at
36+
cemented_level
3637
}`;

src/bridgeDataProviders/dipDupBridgeDataProvider/dtos.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ interface InboxMessageDto {
2626
index: number;
2727
}
2828

29+
interface OutboxMessageDto {
30+
level: number;
31+
index: number;
32+
commitment: { hash: string; } | null;
33+
proof: string | null;
34+
cemented_at: string;
35+
cemented_level: number;
36+
}
37+
2938
interface TezosTicketDto {
3039
token: TezosTokenDto;
3140
}
@@ -40,7 +49,6 @@ interface DepositL1TransactionDto {
4049
l1_account: string;
4150
l2_account: string;
4251
timestamp: string;
43-
inbox_message: InboxMessageDto;
4452
}
4553

4654
interface DepositL2TransactionDto {
@@ -57,6 +65,7 @@ interface DepositL2TransactionDto {
5765
export interface BridgeDepositDto {
5866
l1_transaction: DepositL1TransactionDto;
5967
l2_transaction: DepositL2TransactionDto | null;
68+
inbox_message: InboxMessageDto | null;
6069
}
6170

6271
interface WithdrawalL1TransactionDto {
@@ -65,6 +74,7 @@ interface WithdrawalL1TransactionDto {
6574
counter: number;
6675
nonce: number | null;
6776
timestamp: string;
77+
outbox_message: OutboxMessageDto;
6878
}
6979

7080
interface WithdrawalL2TransactionDto {
@@ -79,18 +89,12 @@ interface WithdrawalL2TransactionDto {
7989
l1_account: string;
8090
l2_account: string;
8191
timestamp: string;
82-
outbox_message: {
83-
level: number;
84-
index: number;
85-
commitment: { hash: string; } | null;
86-
proof: string | null;
87-
cemented_at: string | null;
88-
}
8992
}
9093

9194
export interface BridgeWithdrawalDto {
9295
l1_transaction: WithdrawalL1TransactionDto | null;
9396
l2_transaction: WithdrawalL2TransactionDto;
97+
outbox_message: OutboxMessageDto | null;
9498
}
9599

96100
export interface BridgeOperationDto {

0 commit comments

Comments
 (0)