@logswap/sdk 0.5.57 → 0.5.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/fees.d.ts +17 -2
- package/dist/fees.js +42 -10
- package/dist/fpool.js +1 -1
- package/dist/generated.d.ts +188 -93
- package/dist/generated.js +175 -101
- package/package.json +1 -1
- package/src/client.ts +2 -2
- package/src/fees.ts +40 -8
- package/src/fpool.ts +2 -2
- package/src/generated.ts +175 -101
package/dist/generated.js
CHANGED
|
@@ -666,6 +666,12 @@ export const cPoolManagerAbi = [
|
|
|
666
666
|
type: 'event',
|
|
667
667
|
anonymous: false,
|
|
668
668
|
inputs: [
|
|
669
|
+
{
|
|
670
|
+
name: 'poolId',
|
|
671
|
+
internalType: 'bytes32',
|
|
672
|
+
type: 'bytes32',
|
|
673
|
+
indexed: true,
|
|
674
|
+
},
|
|
669
675
|
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
|
|
670
676
|
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
|
|
671
677
|
{
|
|
@@ -686,6 +692,12 @@ export const cPoolManagerAbi = [
|
|
|
686
692
|
type: 'uint256',
|
|
687
693
|
indexed: false,
|
|
688
694
|
},
|
|
695
|
+
{
|
|
696
|
+
name: 'fees',
|
|
697
|
+
internalType: 'uint256',
|
|
698
|
+
type: 'uint256',
|
|
699
|
+
indexed: false,
|
|
700
|
+
},
|
|
689
701
|
],
|
|
690
702
|
name: 'Burn',
|
|
691
703
|
},
|
|
@@ -693,6 +705,12 @@ export const cPoolManagerAbi = [
|
|
|
693
705
|
type: 'event',
|
|
694
706
|
anonymous: false,
|
|
695
707
|
inputs: [
|
|
708
|
+
{
|
|
709
|
+
name: 'poolId',
|
|
710
|
+
internalType: 'bytes32',
|
|
711
|
+
type: 'bytes32',
|
|
712
|
+
indexed: true,
|
|
713
|
+
},
|
|
696
714
|
{
|
|
697
715
|
name: 'holder',
|
|
698
716
|
internalType: 'address',
|
|
@@ -809,6 +827,12 @@ export const cPoolManagerAbi = [
|
|
|
809
827
|
type: 'event',
|
|
810
828
|
anonymous: false,
|
|
811
829
|
inputs: [
|
|
830
|
+
{
|
|
831
|
+
name: 'poolId',
|
|
832
|
+
internalType: 'bytes32',
|
|
833
|
+
type: 'bytes32',
|
|
834
|
+
indexed: true,
|
|
835
|
+
},
|
|
812
836
|
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
|
|
813
837
|
{ name: 'id', internalType: 'uint256', type: 'uint256', indexed: true },
|
|
814
838
|
{
|
|
@@ -901,6 +925,7 @@ export const cPoolManagerAbi = [
|
|
|
901
925
|
type: 'uint256',
|
|
902
926
|
indexed: false,
|
|
903
927
|
},
|
|
928
|
+
{ name: 'fee', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
904
929
|
{ name: 'newX', internalType: 'int256', type: 'int256', indexed: false },
|
|
905
930
|
{ name: 'phi', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
906
931
|
{ name: 'F', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
@@ -910,6 +935,12 @@ export const cPoolManagerAbi = [
|
|
|
910
935
|
type: 'uint256',
|
|
911
936
|
indexed: false,
|
|
912
937
|
},
|
|
938
|
+
{
|
|
939
|
+
name: 'lActive',
|
|
940
|
+
internalType: 'uint256',
|
|
941
|
+
type: 'uint256',
|
|
942
|
+
indexed: false,
|
|
943
|
+
},
|
|
913
944
|
],
|
|
914
945
|
name: 'Swap',
|
|
915
946
|
},
|
|
@@ -955,6 +986,12 @@ export const cPoolManagerAbi = [
|
|
|
955
986
|
type: 'event',
|
|
956
987
|
anonymous: false,
|
|
957
988
|
inputs: [
|
|
989
|
+
{
|
|
990
|
+
name: 'poolId',
|
|
991
|
+
internalType: 'bytes32',
|
|
992
|
+
type: 'bytes32',
|
|
993
|
+
indexed: true,
|
|
994
|
+
},
|
|
958
995
|
{
|
|
959
996
|
name: 'holder',
|
|
960
997
|
internalType: 'address',
|
|
@@ -967,7 +1004,12 @@ export const cPoolManagerAbi = [
|
|
|
967
1004
|
type: 'uint256',
|
|
968
1005
|
indexed: true,
|
|
969
1006
|
},
|
|
970
|
-
{
|
|
1007
|
+
{
|
|
1008
|
+
name: 'toId',
|
|
1009
|
+
internalType: 'uint256',
|
|
1010
|
+
type: 'uint256',
|
|
1011
|
+
indexed: false,
|
|
1012
|
+
},
|
|
971
1013
|
{
|
|
972
1014
|
name: 'oldL',
|
|
973
1015
|
internalType: 'uint256',
|
|
@@ -987,6 +1029,12 @@ export const cPoolManagerAbi = [
|
|
|
987
1029
|
type: 'int256',
|
|
988
1030
|
indexed: false,
|
|
989
1031
|
},
|
|
1032
|
+
{
|
|
1033
|
+
name: 'fees',
|
|
1034
|
+
internalType: 'uint256',
|
|
1035
|
+
type: 'uint256',
|
|
1036
|
+
indexed: false,
|
|
1037
|
+
},
|
|
990
1038
|
],
|
|
991
1039
|
name: 'Update',
|
|
992
1040
|
},
|
|
@@ -1730,33 +1778,6 @@ export const fPoolManagerAbi = [
|
|
|
1730
1778
|
],
|
|
1731
1779
|
name: 'AsksSet',
|
|
1732
1780
|
},
|
|
1733
|
-
{
|
|
1734
|
-
type: 'event',
|
|
1735
|
-
anonymous: false,
|
|
1736
|
-
inputs: [
|
|
1737
|
-
{
|
|
1738
|
-
name: 'poolId',
|
|
1739
|
-
internalType: 'bytes32',
|
|
1740
|
-
type: 'bytes32',
|
|
1741
|
-
indexed: true,
|
|
1742
|
-
},
|
|
1743
|
-
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
|
|
1744
|
-
{ name: 'dL', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1745
|
-
{
|
|
1746
|
-
name: 'shares',
|
|
1747
|
-
internalType: 'uint256',
|
|
1748
|
-
type: 'uint256',
|
|
1749
|
-
indexed: false,
|
|
1750
|
-
},
|
|
1751
|
-
{
|
|
1752
|
-
name: 'dQuote',
|
|
1753
|
-
internalType: 'uint256',
|
|
1754
|
-
type: 'uint256',
|
|
1755
|
-
indexed: false,
|
|
1756
|
-
},
|
|
1757
|
-
],
|
|
1758
|
-
name: 'Burn',
|
|
1759
|
-
},
|
|
1760
1781
|
{
|
|
1761
1782
|
type: 'event',
|
|
1762
1783
|
anonymous: false,
|
|
@@ -1831,22 +1852,30 @@ export const fPoolManagerAbi = [
|
|
|
1831
1852
|
type: 'bytes32',
|
|
1832
1853
|
indexed: true,
|
|
1833
1854
|
},
|
|
1834
|
-
{ name: '
|
|
1855
|
+
{ name: 'from', internalType: 'address', type: 'address', indexed: true },
|
|
1856
|
+
{ name: 'gen', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1857
|
+
{ name: 'dL', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1835
1858
|
{
|
|
1836
|
-
name: '
|
|
1859
|
+
name: 'shares',
|
|
1837
1860
|
internalType: 'uint256',
|
|
1838
1861
|
type: 'uint256',
|
|
1839
1862
|
indexed: false,
|
|
1840
1863
|
},
|
|
1841
|
-
{ name: 'cut', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1842
1864
|
{
|
|
1843
|
-
name: '
|
|
1865
|
+
name: 'dQuote',
|
|
1866
|
+
internalType: 'uint256',
|
|
1867
|
+
type: 'uint256',
|
|
1868
|
+
indexed: false,
|
|
1869
|
+
},
|
|
1870
|
+
{ name: 'L', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1871
|
+
{
|
|
1872
|
+
name: 'supply',
|
|
1844
1873
|
internalType: 'uint256',
|
|
1845
1874
|
type: 'uint256',
|
|
1846
1875
|
indexed: false,
|
|
1847
1876
|
},
|
|
1848
1877
|
],
|
|
1849
|
-
name: '
|
|
1878
|
+
name: 'FBurn',
|
|
1850
1879
|
},
|
|
1851
1880
|
{
|
|
1852
1881
|
type: 'event',
|
|
@@ -1890,7 +1919,7 @@ export const fPoolManagerAbi = [
|
|
|
1890
1919
|
indexed: false,
|
|
1891
1920
|
},
|
|
1892
1921
|
],
|
|
1893
|
-
name: '
|
|
1922
|
+
name: 'FInitialize',
|
|
1894
1923
|
},
|
|
1895
1924
|
{
|
|
1896
1925
|
type: 'event',
|
|
@@ -1902,21 +1931,92 @@ export const fPoolManagerAbi = [
|
|
|
1902
1931
|
type: 'bytes32',
|
|
1903
1932
|
indexed: true,
|
|
1904
1933
|
},
|
|
1905
|
-
{ name: '
|
|
1934
|
+
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
|
|
1935
|
+
{ name: 'gen', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1936
|
+
{ name: 'dL', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1906
1937
|
{
|
|
1907
|
-
name: '
|
|
1908
|
-
internalType: '
|
|
1909
|
-
type: '
|
|
1938
|
+
name: 'shares',
|
|
1939
|
+
internalType: 'uint256',
|
|
1940
|
+
type: 'uint256',
|
|
1910
1941
|
indexed: false,
|
|
1911
1942
|
},
|
|
1912
1943
|
{
|
|
1913
|
-
name: '
|
|
1914
|
-
internalType: 'uint256
|
|
1915
|
-
type: 'uint256
|
|
1944
|
+
name: 'dQuote',
|
|
1945
|
+
internalType: 'uint256',
|
|
1946
|
+
type: 'uint256',
|
|
1947
|
+
indexed: false,
|
|
1948
|
+
},
|
|
1949
|
+
{ name: 'L', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1950
|
+
{
|
|
1951
|
+
name: 'supply',
|
|
1952
|
+
internalType: 'uint256',
|
|
1953
|
+
type: 'uint256',
|
|
1916
1954
|
indexed: false,
|
|
1917
1955
|
},
|
|
1918
1956
|
],
|
|
1919
|
-
name: '
|
|
1957
|
+
name: 'FMint',
|
|
1958
|
+
},
|
|
1959
|
+
{
|
|
1960
|
+
type: 'event',
|
|
1961
|
+
anonymous: false,
|
|
1962
|
+
inputs: [
|
|
1963
|
+
{
|
|
1964
|
+
name: 'poolId',
|
|
1965
|
+
internalType: 'bytes32',
|
|
1966
|
+
type: 'bytes32',
|
|
1967
|
+
indexed: true,
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
name: 'sender',
|
|
1971
|
+
internalType: 'address',
|
|
1972
|
+
type: 'address',
|
|
1973
|
+
indexed: true,
|
|
1974
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
name: 'taker',
|
|
1977
|
+
internalType: 'address',
|
|
1978
|
+
type: 'address',
|
|
1979
|
+
indexed: true,
|
|
1980
|
+
},
|
|
1981
|
+
{
|
|
1982
|
+
name: 'tokenIn',
|
|
1983
|
+
internalType: 'address',
|
|
1984
|
+
type: 'address',
|
|
1985
|
+
indexed: false,
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
name: 'tokenOut',
|
|
1989
|
+
internalType: 'address',
|
|
1990
|
+
type: 'address',
|
|
1991
|
+
indexed: false,
|
|
1992
|
+
},
|
|
1993
|
+
{
|
|
1994
|
+
name: 'amountIn',
|
|
1995
|
+
internalType: 'uint256',
|
|
1996
|
+
type: 'uint256',
|
|
1997
|
+
indexed: false,
|
|
1998
|
+
},
|
|
1999
|
+
{
|
|
2000
|
+
name: 'amountOut',
|
|
2001
|
+
internalType: 'uint256',
|
|
2002
|
+
type: 'uint256',
|
|
2003
|
+
indexed: false,
|
|
2004
|
+
},
|
|
2005
|
+
{ name: 'fee', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
2006
|
+
{
|
|
2007
|
+
name: 'reserveIn',
|
|
2008
|
+
internalType: 'uint256',
|
|
2009
|
+
type: 'uint256',
|
|
2010
|
+
indexed: false,
|
|
2011
|
+
},
|
|
2012
|
+
{
|
|
2013
|
+
name: 'reserveOut',
|
|
2014
|
+
internalType: 'uint256',
|
|
2015
|
+
type: 'uint256',
|
|
2016
|
+
indexed: false,
|
|
2017
|
+
},
|
|
2018
|
+
],
|
|
2019
|
+
name: 'FSwap',
|
|
1920
2020
|
},
|
|
1921
2021
|
{
|
|
1922
2022
|
type: 'event',
|
|
@@ -1929,21 +2029,49 @@ export const fPoolManagerAbi = [
|
|
|
1929
2029
|
indexed: true,
|
|
1930
2030
|
},
|
|
1931
2031
|
{ name: 'to', internalType: 'address', type: 'address', indexed: true },
|
|
1932
|
-
{ name: '
|
|
2032
|
+
{ name: 'gen', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1933
2033
|
{
|
|
1934
|
-
name: '
|
|
2034
|
+
name: 'amount',
|
|
1935
2035
|
internalType: 'uint256',
|
|
1936
2036
|
type: 'uint256',
|
|
1937
2037
|
indexed: false,
|
|
1938
2038
|
},
|
|
2039
|
+
{ name: 'cut', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1939
2040
|
{
|
|
1940
|
-
name: '
|
|
2041
|
+
name: 'toOperator',
|
|
1941
2042
|
internalType: 'uint256',
|
|
1942
2043
|
type: 'uint256',
|
|
1943
2044
|
indexed: false,
|
|
1944
2045
|
},
|
|
2046
|
+
{ name: 'Q', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
1945
2047
|
],
|
|
1946
|
-
name: '
|
|
2048
|
+
name: 'Harvest',
|
|
2049
|
+
},
|
|
2050
|
+
{
|
|
2051
|
+
type: 'event',
|
|
2052
|
+
anonymous: false,
|
|
2053
|
+
inputs: [
|
|
2054
|
+
{
|
|
2055
|
+
name: 'poolId',
|
|
2056
|
+
internalType: 'bytes32',
|
|
2057
|
+
type: 'bytes32',
|
|
2058
|
+
indexed: true,
|
|
2059
|
+
},
|
|
2060
|
+
{ name: 'gen', internalType: 'uint256', type: 'uint256', indexed: true },
|
|
2061
|
+
{
|
|
2062
|
+
name: 'bases',
|
|
2063
|
+
internalType: 'address[]',
|
|
2064
|
+
type: 'address[]',
|
|
2065
|
+
indexed: false,
|
|
2066
|
+
},
|
|
2067
|
+
{
|
|
2068
|
+
name: 'weights',
|
|
2069
|
+
internalType: 'uint256[]',
|
|
2070
|
+
type: 'uint256[]',
|
|
2071
|
+
indexed: false,
|
|
2072
|
+
},
|
|
2073
|
+
],
|
|
2074
|
+
name: 'LegsSet',
|
|
1947
2075
|
},
|
|
1948
2076
|
{
|
|
1949
2077
|
type: 'event',
|
|
@@ -2075,6 +2203,7 @@ export const fPoolManagerAbi = [
|
|
|
2075
2203
|
type: 'uint256',
|
|
2076
2204
|
indexed: false,
|
|
2077
2205
|
},
|
|
2206
|
+
{ name: 'dL', internalType: 'uint256', type: 'uint256', indexed: false },
|
|
2078
2207
|
],
|
|
2079
2208
|
name: 'Regenerated',
|
|
2080
2209
|
},
|
|
@@ -2139,61 +2268,6 @@ export const fPoolManagerAbi = [
|
|
|
2139
2268
|
],
|
|
2140
2269
|
name: 'Stamped',
|
|
2141
2270
|
},
|
|
2142
|
-
{
|
|
2143
|
-
type: 'event',
|
|
2144
|
-
anonymous: false,
|
|
2145
|
-
inputs: [
|
|
2146
|
-
{
|
|
2147
|
-
name: 'poolId',
|
|
2148
|
-
internalType: 'bytes32',
|
|
2149
|
-
type: 'bytes32',
|
|
2150
|
-
indexed: true,
|
|
2151
|
-
},
|
|
2152
|
-
{
|
|
2153
|
-
name: 'sender',
|
|
2154
|
-
internalType: 'address',
|
|
2155
|
-
type: 'address',
|
|
2156
|
-
indexed: true,
|
|
2157
|
-
},
|
|
2158
|
-
{
|
|
2159
|
-
name: 'tokenIn',
|
|
2160
|
-
internalType: 'address',
|
|
2161
|
-
type: 'address',
|
|
2162
|
-
indexed: false,
|
|
2163
|
-
},
|
|
2164
|
-
{
|
|
2165
|
-
name: 'tokenOut',
|
|
2166
|
-
internalType: 'address',
|
|
2167
|
-
type: 'address',
|
|
2168
|
-
indexed: false,
|
|
2169
|
-
},
|
|
2170
|
-
{
|
|
2171
|
-
name: 'amountIn',
|
|
2172
|
-
internalType: 'uint256',
|
|
2173
|
-
type: 'uint256',
|
|
2174
|
-
indexed: false,
|
|
2175
|
-
},
|
|
2176
|
-
{
|
|
2177
|
-
name: 'amountOut',
|
|
2178
|
-
internalType: 'uint256',
|
|
2179
|
-
type: 'uint256',
|
|
2180
|
-
indexed: false,
|
|
2181
|
-
},
|
|
2182
|
-
{
|
|
2183
|
-
name: 'reserveIn',
|
|
2184
|
-
internalType: 'uint256',
|
|
2185
|
-
type: 'uint256',
|
|
2186
|
-
indexed: false,
|
|
2187
|
-
},
|
|
2188
|
-
{
|
|
2189
|
-
name: 'reserveOut',
|
|
2190
|
-
internalType: 'uint256',
|
|
2191
|
-
type: 'uint256',
|
|
2192
|
-
indexed: false,
|
|
2193
|
-
},
|
|
2194
|
-
],
|
|
2195
|
-
name: 'Swap',
|
|
2196
|
-
},
|
|
2197
2271
|
{
|
|
2198
2272
|
type: 'event',
|
|
2199
2273
|
anonymous: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logswap/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.59",
|
|
4
4
|
"description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the CPoolManager / FPoolManager / Router / Lens surface.",
|
|
5
5
|
"license": "GPL-2.0-or-later",
|
|
6
6
|
"type": "module",
|
package/src/client.ts
CHANGED
|
@@ -109,7 +109,7 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
|
|
|
109
109
|
* `phiOf`; `getPool` lost `sigma2Ema`; `Initialize` lost two fields; the cut is
|
|
110
110
|
* `MINT_FEE_PROTOCOL_CUT` / `setFeeParams`.
|
|
111
111
|
*/
|
|
112
|
-
export const EXPECTED_VERSION =
|
|
112
|
+
export const EXPECTED_VERSION = 5n;
|
|
113
113
|
/**
|
|
114
114
|
* The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
|
|
115
115
|
* 4 was the income-only harvest cut).
|
|
@@ -165,7 +165,7 @@ export const EXPECTED_VERSION = 4n;
|
|
|
165
165
|
// is the policy at birth, `migrate` moves a pool for the registry's owner; `stamp` / `setAsks` are
|
|
166
166
|
// the policy's; the desk's `setAllowed` / `isAllowed` are `setMinters` / `setTakers` / `isMinter` /
|
|
167
167
|
// `isTaker`; a pad and a POL hold one base (`OneBase`).
|
|
168
|
-
export const EXPECTED_F_VERSION =
|
|
168
|
+
export const EXPECTED_F_VERSION = 19n;
|
|
169
169
|
|
|
170
170
|
export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
|
|
171
171
|
const { cPoolManagerAbi } = await import("./generated.js");
|
package/src/fees.ts
CHANGED
|
@@ -18,7 +18,12 @@ import type { DiscoveredMarket } from "./pools.js";
|
|
|
18
18
|
const WAD = 10n ** 18n;
|
|
19
19
|
const YEAR_SECONDS = 31_536_000;
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The fee one swap paid, in quote, from its `Swap` event's fields.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated The C `Swap` event carries its `fee` since C version 5 (decisions 050); read that.
|
|
25
|
+
* This reconstruction from φ rounds where the contract does not, and is kept for older logs.
|
|
26
|
+
*/
|
|
22
27
|
export function swapFeeOf(e: { baseIn: boolean; amountIn: bigint; amountOut: bigint }, phi: bigint): bigint {
|
|
23
28
|
return e.baseIn ? (e.amountOut * phi) / (WAD - phi) : (e.amountIn * phi) / (WAD + phi);
|
|
24
29
|
}
|
|
@@ -36,14 +41,40 @@ export interface SwapFeeWindow {
|
|
|
36
41
|
swaps: number;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
/**
|
|
44
|
+
/** Probes per round of {@link blockAtOrAfter}: 15 splits the bracket 16 ways. */
|
|
45
|
+
const PROBES = 15n;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The first block with timestamp ≥ `t` in `[lo, hi]`; `hi` when none is earlier.
|
|
49
|
+
*
|
|
50
|
+
* A PARALLEL search: each round reads {@link PROBES} evenly spaced blocks at once and keeps the
|
|
51
|
+
* sixteenth of the bracket that holds the answer, so 64k blocks take 4 round trips. Bisection read
|
|
52
|
+
* one block per round trip — ~16 sequential `getBlock`s, seconds apiece against a distant node,
|
|
53
|
+
* before a fee figure could render. Interpolating on timestamps was tried and did no better: a
|
|
54
|
+
* devnet mines on demand plus a heartbeat, so its blocks are far from evenly spaced in time.
|
|
55
|
+
* Exact for monotonic timestamps; a chain restored from a snapshot can carry a genesis stamped
|
|
56
|
+
* after its later blocks, so callers bound `lo` by the block they care about (a pool's own).
|
|
57
|
+
*/
|
|
40
58
|
export async function blockAtOrAfter(c: LogswapClient, t: bigint, lo: bigint, hi: bigint): Promise<bigint> {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
if (lo >= hi) return hi;
|
|
60
|
+
const stamp = async (n: bigint) => (await c.public.getBlock({ blockNumber: n })).timestamp;
|
|
61
|
+
if ((await stamp(lo)) >= t) return lo;
|
|
62
|
+
// invariant from here: ts(lo) < t, and the answer is in (lo, hi]
|
|
63
|
+
while (hi - lo > 1n) {
|
|
64
|
+
const width = hi - lo;
|
|
65
|
+
const probes = [...new Set(Array.from({ length: Number(PROBES) }, (_, i) => lo + (width * BigInt(i + 1)) / (PROBES + 1n)))].filter(
|
|
66
|
+
(n) => n > lo && n < hi,
|
|
67
|
+
);
|
|
68
|
+
if (probes.length === 0) probes.push(lo + width / 2n);
|
|
69
|
+
const stamps = await Promise.all(probes.map(stamp));
|
|
70
|
+
const first = stamps.findIndex((ts) => ts >= t);
|
|
71
|
+
if (first === -1) lo = probes[probes.length - 1]!;
|
|
72
|
+
else {
|
|
73
|
+
hi = probes[first]!;
|
|
74
|
+
if (first > 0) lo = probes[first - 1]!;
|
|
75
|
+
}
|
|
45
76
|
}
|
|
46
|
-
return
|
|
77
|
+
return hi;
|
|
47
78
|
}
|
|
48
79
|
|
|
49
80
|
/**
|
|
@@ -83,8 +114,9 @@ export async function swapFees(
|
|
|
83
114
|
? []
|
|
84
115
|
: await c.public.getLogs({ address: c.addresses.cPoolManager, event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
|
|
85
116
|
|
|
117
|
+
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ
|
|
86
118
|
let fees = 0n;
|
|
87
|
-
for (const l of logs) fees +=
|
|
119
|
+
for (const l of logs) fees += l.args.fee!;
|
|
88
120
|
|
|
89
121
|
const to = last.timestamp;
|
|
90
122
|
return { fromBlock, toBlock, from, to, seconds: to > from ? to - from : 0n, swapFees: fees, swaps: logs.length };
|
package/src/fpool.ts
CHANGED
|
@@ -1480,8 +1480,8 @@ export async function discoverFPools(
|
|
|
1480
1480
|
c: LogswapClient,
|
|
1481
1481
|
opts: { fromBlock?: bigint; toBlock?: bigint } = {},
|
|
1482
1482
|
): Promise<DiscoveredFPool[]> {
|
|
1483
|
-
type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "
|
|
1484
|
-
const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "
|
|
1483
|
+
type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "FInitialize" }>;
|
|
1484
|
+
const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "FInitialize");
|
|
1485
1485
|
if (!ev) throw new Error("logswap: F Initialize event missing from the generated ABI");
|
|
1486
1486
|
type SeedEv = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "Seeded" }>;
|
|
1487
1487
|
const seedEv = fPoolManagerAbi.find((x): x is SeedEv => x.type === "event" && x.name === "Seeded");
|