Skip to content

Commit

Permalink
Merge pull request #67 from balancer/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
johngrantuk authored Oct 17, 2024
2 parents 49b343d + fd8165e commit 02e30cf
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 27 deletions.
6 changes: 3 additions & 3 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Currently supported hooks:
from src.vault import Vault

pool = {
"poolType": "Weighted",
"poolType": "WEIGHTED",
"chainId": "11155111",
"blockNumber": "5955145",
"poolAddress": "0xb2456a6f51530053bc41b0ee700fe6a2c37282e8",
Expand Down Expand Up @@ -60,7 +60,7 @@ calculated_result = vault.swap(
from src.vault import Vault

pool = {
"poolType": "Weighted",
"poolType": "WEIGHTED",
"chainId": "11155111",
"blockNumber": "5955145",
"poolAddress": "0xb2456a6f51530053bc41b0ee700fe6a2c37282e8",
Expand Down Expand Up @@ -101,7 +101,7 @@ This example shows how to calculate the result of a remove liqudity operation wh
from src.vault import Vault

pool = {
"poolType": "Weighted",
"poolType": "WEIGHTED",
"hookType": "ExitFee",
"chainId": "11155111",
"blockNumber": "5955145",
Expand Down
2 changes: 1 addition & 1 deletion python/src/pools/buffer/erc4626_buffer_wrap_or_unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from src.pools.buffer.buffer_math import calculate_buffer_amounts
from src.pools.buffer.enums import WrappingDirection

_MINIMUM_WRAP_AMOUNT = 1000000
_MINIMUM_WRAP_AMOUNT = 1000


def erc4626_buffer_wrap_or_unwrap(swap_input, pool_state):
Expand Down
7 changes: 5 additions & 2 deletions python/src/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
class Vault:
def __init__(self, *, custom_pool_classes=None, custom_hook_classes=None):
self.pool_classes = {
"Weighted": Weighted,
"Stable": Stable,
"WEIGHTED": Weighted,
"STABLE": Stable,
}
self.hook_classes = {"ExitFee": ExitFeeHook}
if custom_pool_classes is not None:
Expand All @@ -22,6 +22,9 @@ def __init__(self, *, custom_pool_classes=None, custom_hook_classes=None):
self.hook_classes.update(custom_hook_classes)

def swap(self, swap_input, pool_state, *, hook_state=None):
if swap_input["amount_raw"] == 0:
return 0

# buffer is handled separately than a "normal" pool
if pool_state.get("totalSupply") is None:
return erc4626_buffer_wrap_or_unwrap(swap_input, pool_state)
Expand Down
2 changes: 1 addition & 1 deletion python/test/hooks/exit_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

pool = {
"poolType": "Weighted",
"poolType": "WEIGHTED",
"hookType": "ExitFee",
"chainId": "11155111",
"blockNumber": "5955145",
Expand Down
4 changes: 2 additions & 2 deletions python/test/hooks/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_hook_no_state():
with pytest.raises(SystemError, match=r"\('No state for Hook:', 'CustomHook'\)"):
vault.swap(
{
"amountRaw": 1,
"amount_raw": 1,
"tokenIn": "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9",
"tokenOut": "0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75",
"swapKind": 0,
Expand All @@ -61,7 +61,7 @@ def test_unsupported_hook_type():
):
vault.swap(
{
"amountRaw": 1,
"amount_raw": 1,
"tokenIn": "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9",
"tokenOut": "0xb19382073c7A0aDdbb56Ac6AF1808Fa49e377B75",
"swapKind": 0,
Expand Down
6 changes: 3 additions & 3 deletions testData/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"chainId": "11155111",
"blockNumber": "5955145",
"poolAddress": "0x03bf996c7bd45b3386cb41875761d45e27eab284",
"poolType": "Weighted",
"poolType": "WEIGHTED",
"swaps": [
{
"swapKind": 0,
Expand Down Expand Up @@ -70,7 +70,7 @@
"chainId": "11155111",
"blockNumber": "5955146",
"poolAddress": "0x03bf996c7bd45b3386cb41875761d45e27eab284",
"poolType": "Weighted",
"poolType": "WEIGHTED",
"swaps": [
{
"swapKind": 0,
Expand All @@ -91,7 +91,7 @@
"chainId": "11155111",
"blockNumber": "6113328",
"poolAddress": "0x302b75a27e5e157f93c679dd7a25fdfcdbc1473c",
"poolType": "Stable",
"poolType": "STABLE",
"swaps": [
{
"swapKind": 0,
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-5955145-Weighted.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"pool": {
"chainId": "11155111",
"blockNumber": "5955145",
"poolType": "Weighted",
"poolType": "WEIGHTED",
"poolAddress": "0x03bf996c7bd45b3386cb41875761d45e27eab284",
"tokens": [
"0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9",
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-5955146-Weighted.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"pool": {
"chainId": "11155111",
"blockNumber": "5955146",
"poolType": "Weighted",
"poolType": "WEIGHTED",
"poolAddress": "0x03bf996c7bd45b3386cb41875761d45e27eab284",
"tokens": [
"0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9",
Expand Down
2 changes: 1 addition & 1 deletion testData/testData/11155111-6113328-Stable.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"pool": {
"chainId": "11155111",
"blockNumber": "6113328",
"poolType": "Stable",
"poolType": "STABLE",
"poolAddress": "0x302b75a27e5e157f93c679dd7a25fdfcdbc1473c",
"tokens": [
"0x8A88124522dbBF1E56352ba3DE1d9F78C143751e",
Expand Down
6 changes: 3 additions & 3 deletions typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const vault = new Vault();
const pool = {
chainId: '11155111',
blockNumber: '5955146',
poolType: 'Weighted',
poolType: 'WEIGHTED',
poolAddress: '0x204d4194e4e42364e3d1841d0a9b1ef857879c31',
tokens: [
'0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
Expand Down Expand Up @@ -56,7 +56,7 @@ const vault = new Vault();
const pool = {
chainId: '11155111',
blockNumber: '5955145',
poolType: 'Weighted',
poolType: 'WEIGHTED',
poolAddress: '0x204d4194e4e42364e3d1841d0a9b1ef857879c31',
tokens: [
'0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
Expand Down Expand Up @@ -89,7 +89,7 @@ This example shows how to calculate the result of a remove liqudity operation wh
const vault = new Vault();

const poolState = {
poolType: 'Weighted',
poolType: 'WEIGHTED',
hookType: 'ExitFee',
chainId: '11155111',
blockNumber: '5955145',
Expand Down
2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"publishConfig": {
"access": "public"
},
"version": "0.0.12",
"version": "0.0.13",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/buffer/erc4626BufferWrapOrUnwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SwapInput } from '../vault/types';
import { calculateBufferAmounts } from './bufferMath';
import { WrappingDirection } from './types';

const _MINIMUM_WRAP_AMOUNT = 1000000n;
const _MINIMUM_WRAP_AMOUNT = 1000n;

export function erc4626BufferWrapOrUnwrap(
input: SwapInput,
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/stable/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PoolState } from '@/vault/types';

type PoolType = 'Stable';
type PoolType = 'STABLE';

export type StableMutable = {
amp: bigint;
Expand Down
6 changes: 4 additions & 2 deletions typescript/src/vault/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class Vault {
const { customPoolClasses, customHookClasses: hookClasses } =
config || {};
this.poolClasses = {
Weighted: Weighted,
Stable: Stable,
WEIGHTED: Weighted,
STABLE: Stable,
// custom add liquidity types take precedence over base types
...customPoolClasses,
};
Expand Down Expand Up @@ -126,6 +126,8 @@ export class Vault {
poolState: PoolState | BufferState,
hookState?: HookState | unknown,
): bigint {
if (swapInput.amountRaw === 0n) return 0n;

// buffer is handled separately than a "normal" pool
if (!('totalSupply' in poolState)) {
return erc4626BufferWrapOrUnwrap(swapInput, poolState);
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/weighted/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PoolState } from '@/vault/types';

type PoolType = 'Weighted';
type PoolType = 'WEIGHTED';
export type WeightedImmutable = {
weights: bigint[];
};
Expand Down
2 changes: 1 addition & 1 deletion typescript/test/hooks/exitFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest';
import { RemoveKind, Vault } from '../../src';

const poolState = {
poolType: 'Weighted',
poolType: 'WEIGHTED',
hookType: 'ExitFee',
chainId: '11155111',
blockNumber: '5955145',
Expand Down
4 changes: 2 additions & 2 deletions typescript/test/utils/readTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type TransformBigintToString<T> = {
function mapPool(
pool: TransformBigintToString<SupportedPools>,
): SupportedPools {
if (pool.poolType === 'Weighted') {
if (pool.poolType === 'WEIGHTED') {
return {
...pool,
scalingFactors: pool.scalingFactors.map((sf) => BigInt(sf)),
Expand All @@ -154,7 +154,7 @@ function mapPool(
aggregateSwapFee: BigInt(pool.aggregateSwapFee ?? '0'),
};
}
if (pool.poolType === 'Stable') {
if (pool.poolType === 'STABLE') {
return {
...pool,
scalingFactors: pool.scalingFactors.map((sf) => BigInt(sf)),
Expand Down

0 comments on commit 02e30cf

Please sign in to comment.