Skip to content

Commit

Permalink
Merge branch 'main' into more_vault_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adaki2004 authored May 7, 2024
2 parents 6276ffd + bbcfb2d commit 2fa2fe1
Show file tree
Hide file tree
Showing 38 changed files with 360 additions and 439 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,23 @@ jobs:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-2cb875799419c907cc3709e586ece2559e6b340e
uses: foundry-rs/[email protected]

- name: Install pnpm dependencies
uses: ./.github/actions/install-pnpm-dependencies

- name: Check formatting
working-directory: ./packages/protocol
run: forge fmt --check

- name: Unit tests
working-directory: ./packages/protocol
run: pnpm clean && pnpm test

- name: Generate contract layout table
- name: Format solidity && update contract layout table
working-directory: ./packages/protocol
run: pnpm layout
run: pnpm layout && forge fmt

- name: Commit contract layout table
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Add contract layout table"
commit_message: "forge fmt & update contract layout table"

- name: Generate genesis
working-directory: ./packages/protocol
Expand Down
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG PACKAGE=eventindexer

FROM golang:1.21.0 as builder

ARG PACKAGE=eventindexer
ARG PACKAGE

RUN apt install git curl

Expand All @@ -12,16 +14,17 @@ COPY . .

RUN go mod download

WORKDIR /taiko-mono/packages/$PACKAGE
WORKDIR /taiko-mono/packages/${PACKAGE}

RUN CGO_ENABLED=0 GOOS=linux go build -o /taiko-mono/packages/$PACKAGE/bin/${PACKAGE} /taiko-mono/packages/$PACKAGE/cmd/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o /taiko-mono/packages/${PACKAGE}/bin/${PACKAGE} /taiko-mono/packages/${PACKAGE}/cmd/main.go

FROM alpine:latest

ARG PACKAGE
ENV PACKAGE=${PACKAGE}

RUN apk add --no-cache ca-certificates

COPY --from=builder /taiko-mono/packages/$PACKAGE/bin/$PACKAGE /usr/local/bin/
COPY --from=builder /taiko-mono/packages/${PACKAGE}/bin/${PACKAGE} /usr/local/bin/

ENTRYPOINT ["$PACKAGE"]
ENTRYPOINT /usr/local/bin/${PACKAGE}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.3
github.com/testcontainers/testcontainers-go v0.30.0
github.com/urfave/cli/v2 v2.27.1
github.com/urfave/cli/v2 v2.27.2
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
golang.org/x/sync v0.7.0
gopkg.in/go-playground/assert.v1 v1.2.1
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand Down Expand Up @@ -186,7 +186,7 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/yosssi/ace v0.0.5 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ=
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs=
github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA=
Expand Down Expand Up @@ -643,8 +643,8 @@ github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898 h1:
github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898/go.mod h1:9bKuHS7eZh/0mJndbUOrCx8Ej3PlsRDszj4L7oVYMPQ=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.22.0/go.mod h1:0mw2RjXGOzxf4NL2jni3gUQ7LfjjUSiG5sskOUUSEpU=
Expand All @@ -671,8 +671,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ckwNHVo4bv2tqNkgx3W3HANh3ta1j6TR5qw08J1A7Tw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
</div>

<!-- Token Dropdown -->
<TokenDropdown combined class="min-w-[151px] z-20 " {tokens} bind:value={$selectedToken} bind:disabled />
<TokenDropdown combined class="min-w-[151px] z-20" {tokens} bind:value={$selectedToken} bind:disabled />
</div>

<div class="flex mt-[8px] min-h-[24px]">
Expand All @@ -242,9 +242,9 @@
>{$t('recipient.label')} <ProcessingFee textOnly class="text-tertiary-content" bind:hasEnoughEth /></span>
</div>
{:else if showInsufficientBalanceAlert}
<FlatAlert type="error" message={$t('bridge.errors.insufficient_balance.title')} class="relative " />
<FlatAlert type="error" message={$t('bridge.errors.insufficient_balance.title')} class="relative" />
{:else if showInvalidTokenAlert}
<FlatAlert type="error" message={$t('bridge.errors.custom_token.not_found.message')} class="relative " />
<FlatAlert type="error" message={$t('bridge.errors.custom_token.not_found.message')} class="relative" />
{:else}
<LoadingText mask="" class="w-1/2" />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
<li
role="menuitem"
tabindex="0"
class=" h-[64px] rounded-[10px]
{disabled ? 'opacity-50 ' : 'hover:bg-primary-brand cursor-pointer'}"
class="h-[64px] rounded-[10px] text-primary-content
{disabled ? 'opacity-50' : 'hover:bg-primary-brand hover:text-white'}"
aria-disabled={disabled}>
<label class="f-row items-center w-full h-full p-[16px] text-primary-content hover:text-white">
<label class="f-row items-center w-full h-full p-[16px] {disabled ? 'cursor-not-allowed' : 'cursor-pointer'}">
<input
type="radio"
name="nft-radio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
menuOpen = false;
};
const openMenu = (event: Event) => {
event.stopPropagation();
const openMenu = () => {
menuOpen = true;
};
Expand Down Expand Up @@ -201,7 +200,7 @@
aria-expanded={menuOpen}
class="f-between-center w-full h-full px-[20px] py-[14px] input-box bg-neutral-background border-0 shadow-none outline-none
{combined ? '!rounded-l-[0px] !rounded-r-[10px]' : '!rounded-[10px]'}"
on:click={openMenu}>
on:click|stopPropagation={openMenu}>
<div class="space-x-2">
{#if !value || disabled}
<span class="title-subsection-bold text-base text-secondary-content">{$t('token_dropdown.label')}</span>
Expand Down
7 changes: 3 additions & 4 deletions packages/bridge-ui/src/components/Tooltip/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
}, ms);
}
function openTooltip(event: Event) {
event.stopPropagation();
function openTooltip() {
tooltipOpen = true;
}
Expand All @@ -45,8 +44,8 @@
aria-haspopup="dialog"
aria-controls={tooltipId}
aria-expanded={tooltipOpen}
on:click={openTooltip}
on:focus={openTooltip}
on:click|stopPropagation={openTooltip}
on:focus|stopPropagation={openTooltip}
on:mouseenter={openTooltip}
bind:this={triggerElem}>
<Icon type="question-circle" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
let openStatusDialog = false;
let tooltipOpen = false;
const openToolTip = (event: Event) => {
event.stopPropagation();
const openToolTip = () => {
tooltipOpen = !tooltipOpen;
};
let dialogId = `dialog-${uid()}`;
Expand Down Expand Up @@ -119,7 +118,7 @@
<li class="f-between-center">
<h4 class="text-secondary-content">
<div class="f-items-center space-x-1">
<button on:click={openToolTip}>
<button on:click|stopPropagation={openToolTip}>
<span>{$t('transactions.header.status')}</span>
</button>
<button on:click={handleStatusDialog} class="flex justify-start content-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@
<h4 class={classes.headline}>{$t('transactions.status.failed.name')}</h4>
{$t('transactions.status.failed.description')}
</div>

<!-- We catch key events aboe -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div role="button" tabindex="0" class="overlay-backdrop" on:click={closeModalIfClickedOutside} />
</div>
<!-- We catch key events aboe -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div role="button" tabindex="0" class="overlay-backdrop" on:click={closeModalIfClickedOutside} />
</dialog>
2 changes: 1 addition & 1 deletion packages/eventindexer/indexer/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func filterFunc(

err = i.saveTransitionProvedEvents(ctx, chainID, transitionProvedEvents)
if err != nil {
return errors.Wrap(err, "i.saveBlockProvenEvents")
return errors.Wrap(err, "i.saveTransitionProvedEvents")
}

return nil
Expand Down
37 changes: 18 additions & 19 deletions packages/eventindexer/indexer/index_nft_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,35 +116,34 @@ func (i *Indexer) saveERC721Transfer(ctx context.Context, chainID *big.Int, vLog
)

// increment To address's balance

_, err := i.nftBalanceRepo.IncreaseBalance(ctx, eventindexer.UpdateNFTBalanceOpts{
// decrement From address's balance
increaseOpts := eventindexer.UpdateNFTBalanceOpts{
ChainID: chainID.Int64(),
Address: to,
TokenID: tokenID,
ContractAddress: vLog.Address.Hex(),
ContractType: "ERC721",
Amount: 1, // ERC721 is always 1
})
if err != nil {
return err
}
decreaseOpts := eventindexer.UpdateNFTBalanceOpts{}

// decrement From address's balance
// ignore zero address since that is usually the "mint"
if from != ZeroAddress.Hex() {
_, err = i.nftBalanceRepo.SubtractBalance(ctx, eventindexer.UpdateNFTBalanceOpts{
decreaseOpts = eventindexer.UpdateNFTBalanceOpts{
ChainID: chainID.Int64(),
Address: from,
TokenID: tokenID,
ContractAddress: vLog.Address.Hex(),
ContractType: "ERC721",
Amount: 1, // ERC721 is always 1
})
if err != nil {
return err
}
}

_, _, err := i.nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(ctx, increaseOpts, decreaseOpts)
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -178,7 +177,7 @@ func (i *Indexer) saveERC1155Transfer(ctx context.Context, chainID *big.Int, vLo
}

transfers = append(transfers, t)
} else if vLog.Topics[0].Hex() != transferBatchSignatureHash.Hex() {
} else if vLog.Topics[0].Hex() == transferBatchSignatureHash.Hex() {
var t []transfer

err = erc1155ABI.UnpackIntoInterface(&t, "TransferBatch", []byte(vLog.Data))
Expand All @@ -200,32 +199,32 @@ func (i *Indexer) saveERC1155Transfer(ctx context.Context, chainID *big.Int, vLo
// increment To address's balance

for _, transfer := range transfers {
_, err = i.nftBalanceRepo.IncreaseBalance(ctx, eventindexer.UpdateNFTBalanceOpts{
increaseOpts := eventindexer.UpdateNFTBalanceOpts{
ChainID: chainID.Int64(),
Address: to,
TokenID: transfer.ID.Int64(),
ContractAddress: vLog.Address.Hex(),
ContractType: "ERC1155",
Amount: transfer.Amount.Int64(),
})
if err != nil {
return err
}
decreaseOpts := eventindexer.UpdateNFTBalanceOpts{}

if from != ZeroAddress.Hex() {
// decrement From address's balance
_, err = i.nftBalanceRepo.SubtractBalance(ctx, eventindexer.UpdateNFTBalanceOpts{
decreaseOpts = eventindexer.UpdateNFTBalanceOpts{
ChainID: chainID.Int64(),
Address: from,
TokenID: transfer.ID.Int64(),
ContractAddress: vLog.Address.Hex(),
ContractType: "ERC1155",
Amount: transfer.Amount.Int64(),
})
if err != nil {
return err
}
}

_, _, err = i.nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(ctx, increaseOpts, decreaseOpts)
if err != nil {
return err
}
}

return nil
Expand Down
7 changes: 5 additions & 2 deletions packages/eventindexer/nft_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ type UpdateNFTBalanceOpts struct {

// NFTBalanceRepository is used to interact with nft balances in the store
type NFTBalanceRepository interface {
SubtractBalance(ctx context.Context, opts UpdateNFTBalanceOpts) (*NFTBalance, error)
IncreaseBalance(ctx context.Context, opts UpdateNFTBalanceOpts) (*NFTBalance, error)
IncreaseAndDecreaseBalancesInTx(
ctx context.Context,
increaseOpts UpdateNFTBalanceOpts,
decreaseOpts UpdateNFTBalanceOpts,
) (increasedBalance *NFTBalance, decreasedBalance *NFTBalance, err error)
FindByAddress(ctx context.Context,
req *http.Request,
address string,
Expand Down
16 changes: 5 additions & 11 deletions packages/eventindexer/pkg/mock/nft_balance_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ func NewNFTBalanceRepository() *NFTBalanceRepository {
return &NFTBalanceRepository{}
}

func (r *NFTBalanceRepository) SubtractBalance(
func (r *NFTBalanceRepository) IncreaseAndDecreaseBalancesInTx(
ctx context.Context,
opts eventindexer.UpdateNFTBalanceOpts,
) (*eventindexer.NFTBalance, error) {
return nil, nil
}

func (r *NFTBalanceRepository) IncreaseBalance(
ctx context.Context,
opts eventindexer.UpdateNFTBalanceOpts,
) (*eventindexer.NFTBalance, error) {
return nil, nil
increaseOpts eventindexer.UpdateNFTBalanceOpts,
decreaseOpts eventindexer.UpdateNFTBalanceOpts,
) (increasedBalance *eventindexer.NFTBalance, decreasedBalance *eventindexer.NFTBalance, err error) {
return nil, nil, nil
}

func (r *NFTBalanceRepository) FindByAddress(ctx context.Context,
Expand Down
Loading

0 comments on commit 2fa2fe1

Please sign in to comment.