Skip to content

Commit

Permalink
Merge pull request #3385 from synapsecns/master
Browse files Browse the repository at this point in the history
FE Release 2024-11-11
  • Loading branch information
abtestingalpha authored Nov 12, 2024
2 parents 34e5886 + 4019633 commit 8e6b05a
Show file tree
Hide file tree
Showing 43 changed files with 318 additions and 43 deletions.
56 changes: 45 additions & 11 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package botmd

import (
"context"
"errors"
"fmt"
"log"
"math/big"
Expand All @@ -20,8 +19,8 @@ import (
"github.com/hako/durafmt"
"github.com/slack-go/slack"
"github.com/slack-io/slacker"
"github.com/synapsecns/sanguine/contrib/opbot/internal"
"github.com/synapsecns/sanguine/contrib/opbot/signoz"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/retry"
"github.com/synapsecns/sanguine/ethergo/chaindata"
"github.com/synapsecns/sanguine/ethergo/submitter"
Expand Down Expand Up @@ -250,7 +249,8 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return
}

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
//nolint: gosec
fastBridgeContractOrigin, err := b.makeFastBridge(ctx.Context(), uint32(rawRequest.Bridge.OriginChainID))
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
Expand All @@ -275,11 +275,44 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return
}

//nolint:gosec
fastBridgeContractDest, err := b.makeFastBridge(ctx.Context(), uint32(rawRequest.Bridge.DestChainID))
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
}
txBz, err := core.BytesToArray(common.Hex2Bytes(rawRequest.Bridge.TransactionID[2:]))
if err != nil {
_, err := ctx.Response().Reply("error converting tx id")
if err != nil {
log.Println(err)
}
return
}
isRelayed, err := fastBridgeContractDest.BridgeRelays(nil, txBz)
if err != nil {
_, err := ctx.Response().Reply("error fetching bridge relays")
if err != nil {
log.Println(err)
}
return
}
if isRelayed {
_, err := ctx.Response().Reply("transaction has already been relayed")
if err != nil {
log.Println(err)
}
return
}

nonce, err := b.submitter.SubmitTransaction(
ctx.Context(),
big.NewInt(int64(rawRequest.Bridge.OriginChainID)),
func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request[2:]))
tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request[2:]))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
Expand Down Expand Up @@ -322,7 +355,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
}
}

func (b *Bot) makeFastBridge(ctx context.Context, req *internal.GetRFQByTxIDResponse) (*fastbridge.FastBridge, error) {
func (b *Bot) makeFastBridge(ctx context.Context, chainID uint32) (*fastbridge.FastBridge, error) {
client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
if err != nil {
return nil, fmt.Errorf("error creating rfq client: %w", err)
Expand All @@ -333,22 +366,23 @@ func (b *Bot) makeFastBridge(ctx context.Context, req *internal.GetRFQByTxIDResp
return nil, fmt.Errorf("error fetching rfq contracts: %w", err)
}

chainClient, err := b.rpcClient.GetChainClient(ctx, req.Bridge.OriginChainID)
chainClient, err := b.rpcClient.GetChainClient(ctx, int(chainID))
if err != nil {
return nil, fmt.Errorf("error getting chain client: %w", err)
return nil, fmt.Errorf("error getting chain client for chain ID %d: %w", chainID, err)
}

//nolint: gosec
contractAddress, ok := contracts.Contracts[uint32(req.Bridge.OriginChainID)]
contractAddress, ok := contracts.Contracts[chainID]
if !ok {
return nil, errors.New("contract address not found")
return nil, fmt.Errorf("no contract address for chain ID")
}

fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
if err != nil {
return nil, fmt.Errorf("error creating fast bridge: %w", err)
return nil, fmt.Errorf("error creating fast bridge for chain ID %d: %w", chainID, err)
}

return fastBridgeHandle, nil

}

func toExplorerSlackLink(ogHash string) string {
Expand Down
10 changes: 10 additions & 0 deletions core/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ func BytesToJSONString(bz []byte) (string, error) {

return string(formattedJSON), nil
}

// BytesToArray converts a slice to a 32 length byte array.
func BytesToArray(bz []byte) ([32]byte, error) {
var bytes [32]byte
if len(bz) != 32 {
return bytes, fmt.Errorf("invalid length of bytes: %d", len(bz))
}
copy(bytes[:], bz)
return bytes, nil
}
8 changes: 8 additions & 0 deletions packages/contracts-rfq/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.12.1](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-11)

**Note:** Version bump only for package @synapsecns/contracts-rfq





# [0.12.0](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-04)


Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/interfaces/IAdmin.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

interface IAdmin {
// ============ Events ============
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

interface IFastBridge {
struct BridgeTransaction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

import {IFastBridge} from "./IFastBridge.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

interface IFastBridgeV2Errors {
error AmountIncorrect();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

/// @notice Interface for a contract that can be called multiple times by the same caller. Inspired by MulticallV3:
/// https://github.com/mds1/multicall/blob/master/src/Multicall3.sol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

interface IZapRecipient {
function zap(address token, uint256 amount, bytes memory zapData) external payable returns (bytes4);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

import {IFastBridgeV2} from "../interfaces/IFastBridgeV2.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/libs/Errors.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

error DeadlineExceeded();
error DeadlineNotExceeded();
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/utils/MulticallTarget.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity ^0.8.4;

import {IMulticallTarget} from "../interfaces/IMulticallTarget.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@synapsecns/contracts-rfq",
"license": "MIT",
"version": "0.12.0",
"version": "0.12.1",
"description": "FastBridge contracts.",
"private": true,
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/test/MulticallTarget.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {IMulticallTarget} from "../contracts/interfaces/IMulticallTarget.sol";
import {MulticallTargetHarness, MulticallTarget} from "./harnesses/MulticallTargetHarness.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {MulticallTarget} from "../../contracts/utils/MulticallTarget.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {IZapRecipient} from "../../contracts/interfaces/IZapRecipient.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {IZapRecipient} from "../../contracts/interfaces/IZapRecipient.sol";

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/test/mocks/NoOpContract.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

// solhint-disable-next-line no-empty-blocks
contract NoOpContract {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

// solhint-disable no-empty-blocks
/// @notice Incorrectly implemented recipient mock for testing purposes. DO NOT USE IN PRODUCTION.
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/test/mocks/NonPayableRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

// solhint-disable no-empty-blocks
/// @notice Incorrectly implemented recipient mock for testing purposes. DO NOT USE IN PRODUCTION.
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/test/mocks/RecipientMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.4;

import {IZapRecipient} from "../../contracts/interfaces/IZapRecipient.sol";

Expand Down
24 changes: 24 additions & 0 deletions packages/rest-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.8.7](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-11)

**Note:** Version bump only for package @synapsecns/rest-api





## [1.8.6](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-07)

**Note:** Version bump only for package @synapsecns/rest-api





## [1.8.5](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-07)

**Note:** Version bump only for package @synapsecns/rest-api





## [1.8.4](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-01)

**Note:** Version bump only for package @synapsecns/rest-api
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synapsecns/rest-api",
"version": "1.8.4",
"version": "1.8.7",
"private": "true",
"engines": {
"node": ">=18.17.0"
Expand All @@ -22,7 +22,7 @@
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/units": "5.7.0",
"@synapsecns/sdk-router": "^0.11.5",
"@synapsecns/sdk-router": "^0.11.6",
"bignumber": "^1.1.0",
"dotenv": "^16.4.5",
"ethers": "5.7.2",
Expand Down
13 changes: 13 additions & 0 deletions packages/rest-api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ import {
const app = express()
const port = process.env.PORT || 3000

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS')
res.setHeader('Access-Control-Allow-Headers', '*')

if (req.method === 'OPTIONS') {
res.sendStatus(200)
return
}

next()
})

app.use(express.json())

app.use((req, res, next) => {
Expand Down
18 changes: 16 additions & 2 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { isTokenSupportedOnChain } from '../utils/isTokenSupportedOnChain'
import { checksumAddresses } from '../middleware/checksumAddresses'
import { normalizeNativeTokenAddress } from '../middleware/normalizeNativeTokenAddress'
import { validateRouteExists } from '../validations/validateRouteExists'

import { validateDecimals } from '../validations/validateDecimals'
import { tokenAddressToToken } from '../utils/tokenAddressToToken'
const router: express.Router = express.Router()

/**
Expand Down Expand Up @@ -227,7 +228,20 @@ router.get(
isTokenSupportedOnChain(value, req.query.toChain as string)
)
.withMessage('Token not supported on specified chain'),
check('amount').isNumeric().exists().withMessage('amount is required'),
check('amount')
.exists()
.withMessage('amount is required')
.isNumeric()
.custom((value, { req }) => {
const fromTokenInfo = tokenAddressToToken(
req.query.fromChain,
req.query.fromToken
)
return validateDecimals(value, fromTokenInfo.decimals)
})
.withMessage(
'Amount has too many decimals, beyond the maximum allowed for this token'
),
check()
.custom((_value, { req }) => {
const { fromChain, toChain, fromToken, toToken } = req.query
Expand Down
Loading

0 comments on commit 8e6b05a

Please sign in to comment.