Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the new Indexer schema #1

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions integration/testConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { NativeEtherlinkToken, NativeTezosToken, ERC20EtherlinkToken, FA12T
export interface TestTokens {
readonly tezos: {
tez: NativeTezosToken;
ctez: FA12TezosToken;
tzbtc: FA12TezosToken;
usdt: FA2TezosToken;
};
readonly etherlink: {
tez: NativeEtherlinkToken
ctez: ERC20EtherlinkToken;
tzbtc: ERC20EtherlinkToken;
usdt: ERC20EtherlinkToken;
};
}
Expand Down Expand Up @@ -62,27 +62,27 @@ const createTestTokens = (): TestTokens => {
tez: {
type: 'native'
},
ctez: {
tzbtc: {
type: 'fa1.2',
address: 'KT1LpdETWYvPWCQTR2FEW6jE6dVqJqxYjdeW'
address: 'KT1Vq1toL9mQquJhCvVRbbcC8PbZJWM4bPui'
},
usdt: {
type: 'fa2',
address: 'KT195Eb8T524v5VJ99ZzH2wpnPfQ2wJfMi6h',
tokenId: '42'
address: 'KT1K6uyg7cjNRoPkYw6SfyCm1f2tPLHfVUez',
tokenId: '0'
}
},
etherlink: {
tez: {
type: 'native'
},
ctez: {
tzbtc: {
type: 'erc20',
address: '0x87dcBf128677ba36E79D47dAf4eb4e51610e0150'
},
usdt: {
type: 'erc20',
address: '0xcB5d40c6B1bdf5Cd51b3801351b0A68D101a561b'
address: '0x8554cD57C0C3E5Ab9d1782c9063279fA9bFA4680'
}
}
};
Expand Down
16 changes: 8 additions & 8 deletions integration/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ export const createTestTokenBridge = ({ testConfig, tezosToolkit, etherlinkToolk
{
tezos: {
...testConfig.tokens.tezos.tez,
ticketHelperContractAddress: 'KT1DWVsu4Jtu2ficZ1qtNheGPunm5YVniegT'
ticketHelperContractAddress: 'KT1MJxf4KVN3sosR99VRG7WBbWTJtAyWUJt9'
},
etherlink: {
...testConfig.tokens.etherlink.tez,
}
},
{
tezos: {
...testConfig.tokens.tezos.ctez,
ticketerContractAddress: 'KT1RvSp4yDKUABqWmv3pKGE9fA6iCGy7bqGh',
ticketHelperContractAddress: 'KT1DHLWJorW9WB6ztkx1XcoaJKWXeTu9yoR1'
...testConfig.tokens.tezos.tzbtc,
ticketerContractAddress: 'KT1AAi4DCQiTUv5MYoXtdiFwUrPH3t3Yhkjo',
ticketHelperContractAddress: 'KT1FcXb4oFBWtUVbEa96Do4DfQZXn6878yu1'
},
etherlink: {
...testConfig.tokens.etherlink.ctez
...testConfig.tokens.etherlink.tzbtc
}
},
{
tezos: {
...testConfig.tokens.tezos.usdt,
ticketerContractAddress: 'KT1VybveLaWhpQHKph28WcGwSy1ud22KSEan',
ticketHelperContractAddress: 'KT1DNtHLr9T9zksZjZvQwgtx5XJwrW9wzETB'
ticketerContractAddress: 'KT1JT3T9jodxKchWEcwMtHzKTcM5pKD4phFp',
ticketHelperContractAddress: 'KT1G4athp6hNRmy65MdM1stv3bXXh82NEvCH'
},
etherlink: {
...testConfig.tokens.etherlink.usdt
Expand Down Expand Up @@ -194,7 +194,7 @@ export const expectFinishedDeposit = (
etherlinkOperation: {
blockId: expect.any(Number),
hash: expect.stringMatching(etherlinkOperationRegex),
logIndex: expect.any(Number),
logIndex: params.etherlinkToken.type === 'native' ? null : expect.any(Number),
amount: params.outAmount,
token: params.etherlinkToken,
timestamp: expect.any(String),
Expand Down
32 changes: 16 additions & 16 deletions integration/tests/balances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ describe('Balances', () => {

test.each([
() => [testTezosAccountAddress, tokens.tezos.tez] as const,
() => [testTezosAccountAddress, tokens.tezos.ctez] as const,
() => [testTezosAccountAddress, tokens.tezos.tzbtc] as const,
() => [testTezosAccountAddress, tokens.tezos.usdt] as const,
() => [testEtherlinkAccountAddress, tokens.etherlink.tez] as const,
() => [testEtherlinkAccountAddress, tokens.etherlink.ctez] as const,
() => [testEtherlinkAccountAddress, tokens.etherlink.tzbtc] as const,
() => [testEtherlinkAccountAddress, tokens.etherlink.usdt] as const,
])('Get the balance for a specific address and token: %#', async getTestData => {
const [address, token] = getTestData();
Expand All @@ -59,30 +59,30 @@ describe('Balances', () => {

test.each([
() => [testTezosAccountAddress, [tokens.tezos.tez], [tokens.tezos.tez]] as const,
() => [testTezosAccountAddress, [tokens.tezos.ctez], [tokens.tezos.ctez]] as const,
() => [testTezosAccountAddress, [tokens.tezos.ctez, tokens.tezos.usdt], [tokens.tezos.ctez, tokens.tezos.usdt]] as const,
() => [testTezosAccountAddress, [tokens.tezos.tzbtc], [tokens.tezos.tzbtc]] as const,
() => [testTezosAccountAddress, [tokens.tezos.tzbtc, tokens.tezos.usdt], [tokens.tezos.tzbtc, tokens.tezos.usdt]] as const,
() => [
testTezosAccountAddress,
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt],
[tokens.tezos.tez, tokens.tezos.ctez, tokens.tezos.usdt]
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt],
[tokens.tezos.tez, tokens.tezos.tzbtc, tokens.tezos.usdt]
] as const,
() => [
testTezosAccountAddress,
[tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.tezos.usdt],
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt]
[tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.tezos.usdt],
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt]
] as const,
() => [
testTezosAccountAddress,
[tokens.tezos.ctez, tokens.etherlink.ctez, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt],
[tokens.tezos.ctez, tokens.tezos.tez, tokens.tezos.usdt]
[tokens.tezos.tzbtc, tokens.etherlink.tzbtc, tokens.tezos.tez, tokens.etherlink.tez, tokens.tezos.usdt],
[tokens.tezos.tzbtc, tokens.tezos.tez, tokens.tezos.usdt]
] as const,
() => [testEtherlinkAccountAddress, [tokens.etherlink.tez], [tokens.etherlink.tez]] as const,
() => [testEtherlinkAccountAddress, [tokens.etherlink.ctez], [tokens.etherlink.ctez],] as const,
() => [testEtherlinkAccountAddress, [tokens.etherlink.ctez, tokens.etherlink.usdt], [tokens.etherlink.ctez, tokens.etherlink.usdt]] as const,
() => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc], [tokens.etherlink.tzbtc]] as const,
() => [testEtherlinkAccountAddress, [tokens.etherlink.tzbtc, tokens.etherlink.usdt], [tokens.etherlink.tzbtc, tokens.etherlink.usdt]] as const,
() => [
testEtherlinkAccountAddress,
[tokens.etherlink.ctez, tokens.tezos.ctez, tokens.tezos.tez, tokens.etherlink.usdt],
[tokens.etherlink.ctez, tokens.etherlink.tez, tokens.etherlink.usdt]
[tokens.etherlink.tzbtc, tokens.tezos.tzbtc, tokens.tezos.tez, tokens.etherlink.usdt],
[tokens.etherlink.tzbtc, tokens.etherlink.tez, tokens.etherlink.usdt]
] as const,
])('Get the balance for a specific address and tokens: %#', async getTestData => {
const [address, tokens, expectedTokens] = getTestData();
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('Balances', () => {
balance: expect.any(BigInt)
},
{
token: tokens.tezos.ctez,
token: tokens.tezos.tzbtc,
balance: expect.any(BigInt)
},
{
Expand All @@ -137,7 +137,7 @@ describe('Balances', () => {
balance: expect.any(BigInt)
},
{
token: tokens.etherlink.ctez,
token: tokens.etherlink.tzbtc,
balance: expect.any(BigInt)
},
{
Expand Down
14 changes: 7 additions & 7 deletions integration/tests/deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe('Deposit', () => {
});

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

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

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

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

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

tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => {
Expand Down Expand Up @@ -174,8 +174,8 @@ describe('Deposit', () => {
});

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

Expand Down
12 changes: 6 additions & 6 deletions integration/tests/withdrawal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('Withdrawal', () => {
});

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

const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken);
expectPendingWithdrawal(startWithdrawResult.tokenTransfer, {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Withdrawal', () => {
}, withdrawalTimeout);

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

const startWithdrawResult = await tokenBridge.startWithdraw(amount, etherlinkToken);
Expand Down Expand Up @@ -144,9 +144,9 @@ describe('Withdrawal', () => {
});
}, withdrawalTimeout);

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

tokenBridge.addEventListener('tokenTransferCreated', tokenTransfer => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const defaultAddresses = {
etherlinkKernelAddress: '0x0000000000000000000000000000000000000000',
withdrawNativeTokenPrecompileAddress: '0x0000000000000000000000000000000000000020',
withdrawNonNativeTokenPrecompileAddress: '0x0000000000000000000000000000000000000040'
withdrawNativeTokenPrecompileAddress: '0xff00000000000000000000000000000000000001',
withdrawNonNativeTokenPrecompileAddress: '0xff00000000000000000000000000000000000002'
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc
{ receipt: TransactionReceipt },
NonPayableMethodObject,
NonPayableMethodObject
> {
> {
protected readonly web3: Web3;
protected readonly withdrawNativeTokenPrecompiledAddress: string;
protected readonly withdrawNonNativeTokenPrecompiledAddress: string;
Expand Down Expand Up @@ -67,11 +67,16 @@ export class Web3EtherlinkBridgeBlockchainService implements EtherlinkBridgeBloc
this.getSignerAddress()
]);
const data = nonNativeTokenOperation.encodeABI();
// TODO: need to calculate the value or hardcode it in config

const estimatedGas = await this.web3.eth.estimateGas({
from: signerAddress,
to: this.withdrawNonNativeTokenPrecompiledAddress,
data,
});
const receipt = await this.web3.eth.sendTransaction({
from: signerAddress,
to: this.withdrawNonNativeTokenPrecompiledAddress,
gas: 30000n,
gas: estimatedGas + (estimatedGas * 5n / 100n),
gasPrice,
data,
});
Expand Down
1 change: 1 addition & 0 deletions src/bridgeCore/bridgeOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface InitialRollupData {
readonly outboxMessageLevel: number;
readonly outboxMessageIndex: number;
readonly estimatedOutboxMessageExecutionTimestamp?: string;
readonly estimatedOutboxMessageExecutionLevel?: number;
}

export interface CementedRollupData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ l1_transaction {
l1_account
l2_account
timestamp
inbox_message {
type
level
index
}
}
l2_transaction {
level
Expand All @@ -30,4 +25,9 @@ l2_transaction {
id
}
timestamp
}
inbox_message {
type
level
index
}`;
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ l2_transaction {
l1_account
l2_account
timestamp
outbox_message {
level
index
commitment {
hash
}
proof
cemented_at
}
outbox_message {
level
index
commitment {
hash
}
proof
cemented_at
cemented_level
}`;
20 changes: 12 additions & 8 deletions src/bridgeDataProviders/dipDupBridgeDataProvider/dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ interface InboxMessageDto {
index: number;
}

interface OutboxMessageDto {
level: number;
index: number;
commitment: { hash: string; } | null;
proof: string | null;
cemented_at: string;
cemented_level: number;
}

interface TezosTicketDto {
token: TezosTokenDto;
}
Expand All @@ -40,7 +49,6 @@ interface DepositL1TransactionDto {
l1_account: string;
l2_account: string;
timestamp: string;
inbox_message: InboxMessageDto;
}

interface DepositL2TransactionDto {
Expand All @@ -57,6 +65,7 @@ interface DepositL2TransactionDto {
export interface BridgeDepositDto {
l1_transaction: DepositL1TransactionDto;
l2_transaction: DepositL2TransactionDto | null;
inbox_message: InboxMessageDto | null;
}

interface WithdrawalL1TransactionDto {
Expand All @@ -65,6 +74,7 @@ interface WithdrawalL1TransactionDto {
counter: number;
nonce: number | null;
timestamp: string;
outbox_message: OutboxMessageDto;
}

interface WithdrawalL2TransactionDto {
Expand All @@ -79,18 +89,12 @@ interface WithdrawalL2TransactionDto {
l1_account: string;
l2_account: string;
timestamp: string;
outbox_message: {
level: number;
index: number;
commitment: { hash: string; } | null;
proof: string | null;
cemented_at: string | null;
}
}

export interface BridgeWithdrawalDto {
l1_transaction: WithdrawalL1TransactionDto | null;
l2_transaction: WithdrawalL2TransactionDto;
outbox_message: OutboxMessageDto | null;
}

export interface BridgeOperationDto {
Expand Down
Loading