Skip to content

Commit

Permalink
Integrate Fluid Dex (#524)
Browse files Browse the repository at this point in the history
* feat(fluid): implement dexT1 pools list updater

* feat(fluid): implement dexT1 pool tracker

* feat(fluid): add dex math

* feat(fluid): dex integration pool simulator, fixes etc.

* feat(fluid): finish implementing dex logic

* tests(fluid): fix vault-t1 tests

* refactor(fluid): improve token comparison logic

* fix(ci): run go generate

* fix(fluid): fix reserves sum calculation

* Update pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go

Co-authored-by: SunSpirit <[email protected]>
Signed-off-by: bergben <[email protected]>

* Update pkg/liquidity-source/fluid/dex-t1/pool_tracker.go

Co-authored-by: SunSpirit <[email protected]>
Signed-off-by: bergben <[email protected]>

* feat(fluid): remove duplicate log

* feat(fluid): add nil check on reserves

* refactor(fluid): replace big.newInt(0) with bignumber.ZeroBI

* refactor(fluid): make fee percent precision a constant

* refactor(fluid): remove unused struct Pool

* fix(fluid): compare reserves against zero correctly

* refactor(fluid): make panic in math.go an error instead

* refactor(fluid): make dexAmountsDecimals a constant

* refactor(fluid): make 1e18 a constant

* fix(valueobject): fix merge compilation issue

* refactor(fluid): move logic from math.go into pool_simulator.go

* feat(fluid): finalize dex protocol integration

* feat(fluid-dex): change swap gas cost to 150k

* feat(fluid): finalize gas cost

* docs(fluid): fix comment  WETH

* Update pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go

Signed-off-by: SunSpirit <[email protected]>

* Update pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go

Signed-off-by: SunSpirit <[email protected]>

* Update pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go

Signed-off-by: SunSpirit <[email protected]>

* Update pkg/liquidity-source/fluid/dex-t1/constant.go

Signed-off-by: SunSpirit <[email protected]>

* Update pkg/valueobject/exchange.go

Signed-off-by: SunSpirit <[email protected]>

* Update pkg/pooltypes/pooltypes.go

Signed-off-by: SunSpirit <[email protected]>

* fix(fluidVaultT1): fix failing test because of hasNative in static extra

* feat(fluid): finalize fetching reserves from updated resolver

* refactor(poolTypes): fix formatting

* feat(fluid-dex): add checks for insufficient liquidity

* feat(fluid-dex): remove reserves check in pool_list_updater

* feat(fluid-dex): remove reserves check in pool_tracker

* feat(fluid-dex): fix native token use in pool

* feat(fluid-dex): optimize only fetch new pools

* feat(fluid-dex): optimize swapRouting methods

* Update pkg/liquidity-source/fluid/dex-t1/pool_list_updater.go

Co-authored-by: Phu Ngo <[email protected]>
Signed-off-by: bergben <[email protected]>

* Update pkg/liquidity-source/fluid/dex-t1/pool_simulator.go

Signed-off-by: SunSpirit <[email protected]>

---------

Signed-off-by: bergben <[email protected]>
Signed-off-by: SunSpirit <[email protected]>
Co-authored-by: SunSpirit <[email protected]>
Co-authored-by: Phu Ngo <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent bef08f5 commit 6261f89
Show file tree
Hide file tree
Showing 18 changed files with 2,859 additions and 19 deletions.
30 changes: 30 additions & 0 deletions pkg/liquidity-source/fluid/dex-t1/abis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dexT1

import (
"bytes"

"github.com/ethereum/go-ethereum/accounts/abi"
)

var (
dexReservesResolverABI abi.ABI
erc20 abi.ABI
)

func init() {
builder := []struct {
ABI *abi.ABI
data []byte
}{
{&dexReservesResolverABI, dexReservesResolverJSON},
{&erc20, erc20JSON},
}

for _, b := range builder {
var err error
*b.ABI, err = abi.JSON(bytes.NewReader(b.data))
if err != nil {
panic(err)
}
}
}
222 changes: 222 additions & 0 deletions pkg/liquidity-source/fluid/dex-t1/abis/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
Loading

0 comments on commit 6261f89

Please sign in to comment.