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

[Swap]: Fix BSC swap #3549

Merged
merged 2 commits into from
Nov 10, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Android CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codegen-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Codegen-v2 Tests

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
paths:
- 'codegen-v2/**'
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
paths:
- 'codegen-v2/**'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Docker CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
paths:
- Dockerfile
- tools/install-dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: iOS CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/kotlin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Kotlin CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/kotlin-sample-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Kotlin Multiplatform CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linux CI Rust

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

env:
SCCACHE_GHA_ENABLED: "true"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-ci-sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linux CI SonarCloud

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linux CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -15,6 +15,12 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Remove GCC 13 from runner image
shell: bash
run: |
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades libc6=2.35-0ubuntu3.4 libc6-dev=2.35-0ubuntu3.4 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/linux-sampleapp-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linux SampleApps CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -15,6 +15,12 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Remove GCC 13 from runner image
shell: bash
run: |
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades libc6=2.35-0ubuntu3.4 libc6-dev=2.35-0ubuntu3.4 libstdc++6=12.3.0-1ubuntu1~22.04 libgcc-s1=12.3.0-1ubuntu1~22.04
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wasm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Wasm CI

on:
push:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]
pull_request:
branches: [ dev, master ]
branches: [ dev, master, master-3 ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
3 changes: 2 additions & 1 deletion src/THORChain/Swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ std::string chainName(Chain chain) {
case Chain::ETH:
return "ETH";
case Chain::BNB:
case Chain::BSC:
return "BNB";
case Chain::BSC:
return "BSC";
case Chain::BTC:
return "BTC";
case Chain::DOGE:
Expand Down
57 changes: 57 additions & 0 deletions tests/chains/Cosmos/THORChain/SwapTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,63 @@ Data SwapTest_ethAddressStringToData(const std::string& asString) {
return asData;
}

TEST(THORChainSwap, SwapUsdtBsc) {
auto myAddress = "0x0d6aA74992eDDaaf430eadca63B87f4C99Aef8dE";
auto vaultAddress = "0x1f3b3c6ac151bf32409fe139a5d55f3d9444729c";
auto routerAddress = "0xD37BbE5744D730a1d98d8DC97c42F0Ca46aD7146";
auto usdtTokenId = "0xdAC17F958D2ee523a2206206994597C13D831ec7";
auto amount = 70000000;
auto expirationTime = 1775669796;

Proto::Asset fromAsset;
fromAsset.set_chain(static_cast<Proto::Chain>(Chain::ETH));
fromAsset.set_symbol("USDT");
fromAsset.set_token_id(usdtTokenId);
Proto::Asset toAsset;
toAsset.set_chain(static_cast<Proto::Chain>(Chain::BSC));
toAsset.set_symbol("BSC");
toAsset.set_token_id("BNB");

auto&& [out, errorCode, error] = SwapBuilder::builder()
.from(fromAsset)
.to(toAsset)
.fromAddress(myAddress)
.toAddress(myAddress)
.vault(vaultAddress)
.router(routerAddress)
.fromAmount(std::to_string(amount))
.expirationPolicy(expirationTime)
.affFeeAddress("tr")
.affFeeRate("0")
.streamInterval("1")
.streamQuantity("0")
.build();
ASSERT_EQ(errorCode, 0);
ASSERT_EQ(error, "");

auto tx = Ethereum::Proto::SigningInput();
ASSERT_TRUE(tx.ParseFromArray(out.data(), (int)out.size()));

// check fields
EXPECT_EQ(tx.to_address(), routerAddress);
ASSERT_TRUE(tx.transaction().has_contract_generic());

Data vaultAddressBin = SwapTest_ethAddressStringToData(vaultAddress);
Data usdtTokenIdBin = SwapTest_ethAddressStringToData(usdtTokenId);
auto func = Ethereum::ABI::Function("depositWithExpiry", std::vector<std::shared_ptr<Ethereum::ABI::ParamBase>>{
std::make_shared<Ethereum::ABI::ParamAddress>(vaultAddressBin),
std::make_shared<Ethereum::ABI::ParamAddress>(usdtTokenIdBin),
std::make_shared<Ethereum::ABI::ParamUInt256>(uint256_t(amount)),
std::make_shared<Ethereum::ABI::ParamString>("=:BSC.BNB:0x0d6aA74992eDDaaf430eadca63B87f4C99Aef8dE:0/1/0:tr:0"),
std::make_shared<Ethereum::ABI::ParamUInt256>(uint256_t(expirationTime))});

Data funcData;
func.encode(funcData);
EXPECT_EQ(hex(funcData), "44bc937b0000000000000000000000001f3b3c6ac151bf32409fe139a5d55f3d9444729c000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000042c1d8000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000069d69224000000000000000000000000000000000000000000000000000000000000003f3d3a4253432e424e423a3078306436614137343939326544446161663433306561646361363342383766344339394165663864453a302f312f303a74723a3000");
EXPECT_EQ(hex(TW::data(tx.transaction().contract_generic().amount())), "00");
EXPECT_EQ(hex(TW::data(tx.transaction().contract_generic().data())), hex(funcData));
}

TEST(THORChainSwap, SwapErc20Rune) {
Proto::Asset fromAsset;
fromAsset.set_token_id("0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E");
Expand Down
Loading